I am learning Haskell programming, and I am trying to understand how lists work, hence I attempted writing two possible length functions:
myLength :: [a] -> Integer
myLength = foldr (\x -> (+) 1) 0
myLength1 :: [a] -> Integer
myLength1 [] = 0
myLength1 (x:xs) = (+1) (myLength1 xs)
Which one is better?
From my point of view, myLength1 is much easier to understand, and looks natural for operating on lists.
On the other hand, myLength is shorter and it does not use recursion; does this imply myLength runs faster than myLength1?