瀏覽代碼

exercise 5.2: sndItem without pattern matching

George C. Privon 1 年之前
父節點
當前提交
22e7b1c5d4
共有 1 個文件被更改,包括 10 次插入0 次删除
  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