From e8cfa96c03f4034b934d6605137c91196b6661c7 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Fri, 24 May 2024 15:56:10 -0500 Subject: [PATCH] new: Solved problem 1 --- problem_1.hs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 problem_1.hs 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)