new: Solved problem 1

This commit is contained in:
Sayantan Santra 2024-05-24 15:56:10 -05:00
parent 93af9a98c1
commit e8cfa96c03
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F

9
problem_1.hs Normal file
View 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)