Skip to content

Instantly share code, notes, and snippets.

@ethnt
Created March 13, 2015 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethnt/b31b94edc1f9e054a270 to your computer and use it in GitHub Desktop.
Save ethnt/b31b94edc1f9e054a270 to your computer and use it in GitHub Desktop.
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