new: Solved problem 1
This commit is contained in:
parent
93af9a98c1
commit
e8cfa96c03
1 changed files with 9 additions and 0 deletions
9
problem_1.hs
Normal file
9
problem_1.hs
Normal file
|
@ -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 a new issue