这是我的代码:
-- combine lists with binary operation
clwbo :: (Num a, Num b, Num c) => (a -> b -> c) -> [a] -> [b] -> [c]
clwbo fps lista listb
|length lista /= length listb = []
|length lista ==length listb = case lista listb of
[] [] -> []
x:xs y:ys -> [fps x y] ++ clwbo fps xs ys
otherwise -> error "get off"
以下是来自终端的错误消息:
test.hs:8:42: Parse error in pattern: xs
Failed, modules loaded: none.
有人喜欢告诉我代码有什么问题吗?
答案 0 :(得分:1)
您不能像case
表达式那样并排放置多个模式。要一次匹配多个模式,请将它们放在元组中:
case (lista, listb) of
([], []) -> ...
(x:xs, y:ys) -> ...
otherwise -> ...