99-haskell-problems/problem_1.hs
2024-05-24 15:59:23 -05:00

9 lines
208 B
Haskell

-- Simple recursive solution
myLast :: [a] -> a
myLast [] = error "Empty list"
myLast [s] = s
myLast (hd : tl) = myLast tl
-- Alternative Solution using fold
myLast' :: [a] -> a
myLast' = foldl1 (\_ x -> x)