Created
October 25, 2013 00:46
-
-
Save tautologico/7147707 to your computer and use it in GitHub Desktop.
Tail-recursive length function for lists, using an accumulator.
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
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