0

在 haskel 中,我遇到了一个错误,不知何故我找不到正确的解决方案。我得到了错误和我的代码:

我的代码:

data MyTree = Leaf Float | Tree String MyTree MyTree deriving (Show, Eq, Ord)

asgCodeRec1 [] _ = []
asgCodeRec1 (a:b:c) (y:ys) = [Tree (y) (Leaf a) (Leaf b)] ++ asgCodeRec1 c ys

asgCode2 (a:b:c) (x:xs) = [Tree x a b] ++ (if c/=[] then (asgCode2 c xs) else [])

asgCode c y = asgCode2 (asgCodeRec1 c y) (drop (length c * 2) y)

和我的控制台日志:

*Main> asgCode [0.5,0.5,0.5,0.5,0.5,0.5] ["and","and","and","or","or"]
*** Exception: part1.hs:6:1-81: Non-exhaustive patterns in function asgCode2

任何帮助都是有用的。谢谢。

4

1 回答 1

5

(drop (length c * 2) y)返回[][]当然不匹配(x:xs)(它至少需要一个单例)。这有帮助吗?

于 2014-03-30T20:32:58.980 回答