new: Solved problem 1
This commit is contained in:
parent
93af9a98c1
commit
e8cfa96c03
|
@ -0,0 +1,9 @@
|
|||
-- 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)
|
Loading…
Reference in New Issue