Created
December 18, 2013 12:22
-
-
Save polux/8021388 to your computer and use it in GitHub Desktop.
Staged "contains" method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cons { | |
final x; | |
final xs; | |
Cons(this.x, this.xs); | |
freeze() => new Cons(((v) => <v>)(this.x), this.xs.freeze()); | |
contains(e) => < (~this.x).eq(~e) ? true : ~(this.xs.contains(e)) >; | |
} | |
class Nil { | |
Nil(); | |
freeze() => new Nil(); | |
contains(e) => <false>; | |
} | |
class Demo { | |
Demo(); | |
range(n) => n.eq(0) ? new Nil() : new Cons(n, this.range(n.minus(1))); | |
inRange10() => run(<(e) => ~this.range(10).freeze().contains(<e>)>); | |
} | |
main() { | |
print(new Demo().inRange10()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment