2014-03-30 23 views
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 

任何幫助是非常有用的。謝謝。

+3

想想如果在空列表上調用asgCode2會發生什麼 – cdk

回答

5

(drop (length c * 2) y)返回[][]當然不匹配(x:xs)(它至少需要一個單身人士)。這有幫助嗎?