Эх сурвалжийг харах

exercise 5.2: sndItem without pattern matching

George C. Privon 1 жил өмнө
parent
commit
22e7b1c5d4

+ 10 - 0
05-Lists/exercises/ex5.2.hs

@@ -0,0 +1,10 @@
+-- Exercise 5.2
+-- George C. Privon
+-- 2024-07-20
+
+sndItem0 :: [a] -> a
+sndItem0 ys = if length ys == 0
+              then error "Empty list has no second element."
+              else if length ys == 1
+                    then error "1-item list has no 2nd item."
+                    else ys !! 1