Skip to content

Instantly share code, notes, and snippets.

@tautologico
Last active December 26, 2015 11:49
Show Gist options
  • Save tautologico/7146397 to your computer and use it in GitHub Desktop.
Save tautologico/7146397 to your computer and use it in GitHub Desktop.
Polymorphic length function and test.
fn length<A>(l: @List<A>) -> uint {
match *l {
Empty => 0,
Cons(_, rest) => 1 + length(rest)
}
}
fn main() {
let l = @Cons("3", @Cons("little", @Cons("strings", @Empty)));
println!("Length of l is {}", length(l));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment