diff --git a/problem_1.hs b/problem_1.hs new file mode 100644 index 0000000..470d3c8 --- /dev/null +++ b/problem_1.hs @@ -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)