
9 Mar
2010
9 Mar
'10
3:26 p.m.
I'm working my way through the 99 sample programs for haskell and I'm on #4: find the number of elements in a list. http://haskell.org/haskellwiki/99_questions/1_to_10 I wrote the obvious recursion. Then I rewrote it using foldl myLength :: [a] -> Int myLength [] = 0 myLength xs = foldl addOne 0 xs where addOne lhs rhs = lhs + 1 However, the solution given uses notation that confuses my little mind. Can someone point me to a good resource on this notation? myLength :: [a] -> Int myLength = foldr (\x n -> n + 1) 0 Thanks, Tim