高阶函数,模式中的解析错误:xs

时间:2013-05-14 02:47:32

标签: haskell parse-error

这是我的代码:

-- 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.

有人喜欢告诉我代码有什么问题吗?

1 个答案:

答案 0 :(得分:1)

您不能像case表达式那样并排放置多个模式。要一次匹配多个模式,请将它们放在元组中:

case (lista, listb) of
   ([], [])     -> ...
   (x:xs, y:ys) -> ...
   otherwise    -> ...