我能够执行下面的代码完美无法匹配预期的类型'一“与实际类型`[A]”
myLast :: [a] -> a
myLast [] = error "Can't call myLast on an empty list!"
myLast (x:_) = x
,但我发现这个错误Couldn't match expected type `a' with actual type `[a]'. `a' is a rigid type variable bound by the type signature for myLast :: [a] -> a
以下代码:
myLast :: [a] -> a
myLast [] = error "Can't call myLast on an empty list!"
myLast (_:x) = x
我是Haskell的初学者,错误信息太过于希腊语和拉丁语。根据我的理解,编译器无法在第二种情况下推断出类型。有人能指出我在这里发生了什么吗?