type token = string; function holds(pair:[any, any], rel:Array<[any, any]>): boolean { return rel.includes(pair); } type relation<X, Y> = Array<[X, Y]>; type relationFun<X, Y> = (x:X) => (null | Y | Array<Y>); type LabelSpace = { "type": "LabelSpace", "id"?: string, "data": Array<token>, "label_isChildOf": relation<token, token>, "label_isNextOf": relation<token, token>, }; class LableSpaceAxiom { staff:LabelSpace; constructor(staff: LabelSpace) { this.staff = staff; } /* atmostOneParent:: * ∀x,y,z. (x label_isChildOf y ∧ x label_isChildOf z) ⇒ y = z */ atmostOneParent():boolean { let my = this.staff; let result:boolean = true; for (let x in my.data) { for (let y in my.data) { for (let z in my.data) { if ( holds([x,y], my.label_isChildOf) && holds([x, z], my.label_isChildOf) ) { result = result && (x == y); } else { ; } } } } return result; } /* ... */ };
ちなみに、コンストラクタだけで、プロパティ宣言を書ける。コンストラクタ引数内がプロパティ宣言を兼ねる。
class LableSpaceAxiom { constructor(public staff: LabelSpace) {} }