99-haskell-problems/Problems 1-10/problem_4.hs

9 lines
210 B
Haskell
Raw Normal View History

2024-05-24 17:06:42 -05:00
-- Simple recursive solution
myLength :: (Num n) => [a] -> n
myLength [] = 0
myLength (_ : tl) = 1 + myLength tl
-- Solution using fold
myLength' :: (Num n) => [a] -> n
myLength' = foldl (\acc _ -> acc + 1) 0