私の考えでは、型パラメーターa
はリストを含む何でもかまいません。なぜこれが機能しないのですか?
fun :: a -> a
fun [] = []
Haskell はこのコードをコンパイルしたくありません。なぜだろう。
Couldn't match expected type `a' with actual type `[t0]'
`a' is a rigid type variable bound by
the type signature for fun :: a -> a
I can make it work rewriting the signature like this
fun :: [a] -> [a]
But this is not something that I am looking for as I wanted to keep the function polymorphic.
I wonder how id
works on empty lists.
Prelude> :t id
id :: a -> a
Prelude> id []
[]