Skip to content

Instantly share code, notes, and snippets.

@pnkfelix
Created May 2, 2013 16:24
Show Gist options
  • Save pnkfelix/5503376 to your computer and use it in GitHub Desktop.
Save pnkfelix/5503376 to your computer and use it in GitHub Desktop.
Attempting to encode a nested (aka "non-regular", "non-uniform") data type in Rust.
enum Seq<A> {
Nil,
Cons{hd: A, tl:~Seq<(A,A)>}
}
impl<A> Seq<A> {
fn len(&self) -> int {
match self {
&Nil => 0,
&Cons{ hd: x, tl: ref s } => 1 + 2 * s.len()
}
}
}
fn main() {
io::println(fmt!("Hello World"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment