2013-05-14 60 views
0

這裏是我的代碼:高階功能,模式解析錯誤:XS

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

您不能像case表達式那樣將多個圖案並排放置。要一次匹配多個模式,請將它們放在元組中:

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

yeap,man,u are right,thank you so so much – libra 2013-05-14 15:07:38