Created
May 2, 2013 16:24
-
-
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.
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
| 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