在哈斯克尔,我收到了一个错误,不知怎的,我找不到合适的解决方案。我得到的错误和我的代码:
我的代码:
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
任何帮助都很有用。感谢。
答案 0 :(得分:5)
(drop (length c * 2) y)
返回[]
。 []
当然与(x:xs)
不匹配(至少需要一个单身)。这有帮助吗?