我想每两个元素挑错误类型形成一个列表,使一个新的列表,然后我得到这样的错误:递归
test.hs:4:20: error:
? Couldn't match expected type ‘[a]’ with actual type ‘a’
‘a’ is a rigid type variable bound by
the type signature for:
test :: forall a. [a] -> [[a]]
at test.hs:1:7
? In the expression: x1
In the expression: [x1]
In a case alternative: [x1] -> [x1]
? Relevant bindings include
x1 :: a (bound at test.hs:4:6)
list :: [a] (bound at test.hs:2:6)
test :: [a] -> [[a]] (bound at test.hs:2:1)
这里是我的代码:
test::[a]->[[a]]
test list = case list of
[] ->[]
[x1] ->[x1]
[x1,x2] ->[x1,x2]
x1:x2:xs ->[[x1,x2],(test xs)]
任何人都可以帮助我吗?
如果'[x1]'的类型是'[a]',那么'[x1]'的类型是什么? – leftaroundabout