在下面的Haskell代码中,函数typeError没有进行类型检查.
wrap x = [x]
listf :: [[a]] -> [[a]]
listf = id
typeCheck :: [a] -> [[a]]
typeCheck x = listf (wrap x)
typeError :: [a] -> [[a]]
typeError = wrap . listf
Run Code Online (Sandbox Code Playgroud)
如果GHC取消注释,GHC会产生此错误:
Couldn't match type `a' with `[a0]'
`a' is a rigid type variable bound by
the type signature for typeError :: [a] -> [[a]] at tim.hs:10:1
Expected type: [a] -> [a]
Actual type: [[a0]] -> [[a0]]
In the second argument of `(.)', namely `listf'
In the …Run Code Online (Sandbox Code Playgroud)