소스 검색

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