Last active
November 21, 2019 15:58
-
-
Save myuon/efe5cee5d5b76acc651fbdace38dc3cb to your computer and use it in GitHub Desktop.
This file contains 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
func identity<A>(x: A): A { | |
x | |
} | |
enum List<A> { | |
Nil, | |
Cons(A, List<A>), | |
} | |
record User { | |
user_id: string, | |
age: int, | |
} | |
instance List<A> { | |
open List.*; | |
func length(self): int { | |
case self { | |
Nil -> 0, | |
Cons(x, xs) -> 1 + xs.length(), | |
} | |
} | |
func concat(self, other: List<A>): List<A> { | |
case other { | |
Nil -> self, | |
Cons(x, xs) -> self.snoc(x).concat(other) | |
} | |
} | |
} | |
func public_length(xs: List<A>): int { | |
... | |
} | |
func main() { | |
let xs = { | |
open List::*; | |
Cons( | |
1, | |
Cons( | |
2, | |
Nil | |
) | |
) | |
}; | |
println("{:?}", xs.length()); | |
println("{:?}", List.length(xs)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment