Skip to content

Instantly share code, notes, and snippets.

@tautologico
Created October 25, 2013 00:46
Show Gist options
  • Save tautologico/7147707 to your computer and use it in GitHub Desktop.
Save tautologico/7147707 to your computer and use it in GitHub Desktop.
Tail-recursive length function for lists, using an accumulator.
fn length_acc<A>(l: @List<A>, acc: uint) -> uint {
match *l {
Empty => acc,
Cons(_, rest) => length_acc(rest, acc + 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment