Skip to content

Instantly share code, notes, and snippets.

@honda0510
Created January 14, 2013 03:18
Show Gist options
  • Select an option

  • Save honda0510/4527544 to your computer and use it in GitHub Desktop.

Select an option

Save honda0510/4527544 to your computer and use it in GitHub Desktop.
reverse' はコンパイルエラーにならないのに reverse'' はコンパイルエラーになるのはなぜだろう
reverse' :: [a] -> [a]
reverse' = foldl (flip (:)) []
reverse'' :: [a] -> [a]
reverse'' = foldl (:) []
@honda0510
Copy link
Author

今の僕の解釈

foldlとしては

(a -> b -> a) -> a

こういう型で渡さなければいけないのに、

(a -> [a] -> [a]) -> [a]

こういう型で渡そうとしていたってことですね。
aと[a]の型不一致が2つあるから、エラーメッセージも2つあったんですね。

@haiiro-shimeji
Copy link

あーなるほど、そういうことなのかな

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment