Reputation: 1522
In haskel, I got an error and somehow I couldn't find the right solution. There is the error i get and my code:
My code:
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)
and my console log:
*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
Any help is useful. Thanks.
Upvotes: 0
Views: 127
Reputation: 66
(drop (length c * 2) y)
returns []
. []
of course doesn't match (x:xs)
(it requires at least a singleton). Does this help?
Upvotes: 5