【问题标题】:Higher order function, parse error in pattern: xs高阶函数,解析模式错误:xs
【发布时间】:2013-05-08 05:03:39
【问题描述】:

这是我的代码:

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

有人愿意告诉我我的代码有什么问题吗?

【问题讨论】:

    标签: haskell parse-error


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-07-03
      • 2013-05-07
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多