我想每兩個元素挑錯誤類型形成一個列表,使一個新的列表,然後我得到這樣的錯誤:遞歸
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