Bläddra i källkod

exercise 5.2: sndItem without pattern matching

George C. Privon 1 år sedan
förälder
incheckning
22e7b1c5d4
1 ändrade filer med 10 tillägg och 0 borttagningar
  1. 10 0
      05-Lists/exercises/ex5.2.hs

+ 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