Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface Nat {
- name: 'zero' | 'succ';
- pred: Nat;
- }
- class Zero implements Nat {
- name: 'zero';
- pred: Zero;
- constructor() { this.pred = this; }
- }
- class Succ<T extends Nat> implements Nat {
- name: 'succ';
- pred: T;
- constructor(pred: T) { this.pred = pred; }
- }
- class Plus<A extends Nat, B extends Nat> {
- zero: {
- zero: B;
- succ: B;
- };
- succ: {
- zero: A;
- succ: Succ<Plus<A['pred'], B>[A['pred']['name']][B['name']]>;
- };
- }
- type One = Succ<Zero>;
- type Two = Succ<One>;
- type Sum = Plus<One, Two>[One['name']][Two['name']];
Add Comment
Please, Sign In to add comment