Skip to content

Instantly share code, notes, and snippets.

@myuon
Last active November 21, 2019 15:58
Show Gist options
  • Save myuon/efe5cee5d5b76acc651fbdace38dc3cb to your computer and use it in GitHub Desktop.
Save myuon/efe5cee5d5b76acc651fbdace38dc3cb to your computer and use it in GitHub Desktop.
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