# 099: last.hs, init.hs で occurs check fails [↑up](bunny_notes) - issued: 2020-06-04 - 分類: A サンプルコードが fail - status: Closed (2020-10-16) ## 概要 lib/Prelude.hs に関数を追加していく際、the language report にならって last, init を定義するとエラーが発生した(このため、違う書き方で回避した)。 これらの調査用にテストプログラムを作成。 last.hs, init.hs ともに occurs check fails となってエラーする。 ## 調査ログ ## 2020-10-16 この issue 発行以来、かなり別件で修正してきているため、再確認したところ、 いずれも ok となっていた。 lib/Prelude.hs に反映(last.hs, init.hs は廃止) $$
{
diff --git a/compiler/lib/Prelude.hs b/compiler/lib/Prelude.hs
index b611ac7..a02bd86 100644
--- a/compiler/lib/Prelude.hs
+++ b/compiler/lib/Prelude.hs
@@ -717,12 +717,12 @@ tail [] = error "Prelude.tail: empty list"
last :: [a] -> a
last [x] = x
-last xs = last (tail xs) -- todo: occur check fail?
+last (_:xs) = last xs
last [] = error "Prelude.last: empty list"
init :: [a] -> [a]
init [x] = []
-init xs = head xs : init (tail xs) -- todo: occur check fail?
+init (x:xs) = x : init xs
init [] = error "Prelude.init: empty list"
null :: [a] -> Bool
$$}