Created
March 13, 2015 03:51
-
-
Save ethnt/b31b94edc1f9e054a270 to your computer and use it in GitHub Desktop.
This file contains 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
length' xs = lengthHelper xs 0 -- We're passing in the full list and 0 as the starting value for rsf | |
where lengthHelper (x:xs) rsf -- Separate xs into x (head) and xs (tail) | |
| xs == [] = rsf -- If the tail is empty, we're at the end. At this point, return rsf — we're done | |
| otherwise = lengthHelper xs (rsf + 1) -- If the tail isn't empty, pass in the tail (the rest of the list) and rsf + 1, since we're counting the head (x) right now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment