I'm trying to write a function that combines a list of rose trees with the their parent node being the highest values of the root nodes of the given rose trees. For example;
RosesToRose [Rose 1 [Rose 1 [], Rose 2 []], Rose 3 [], Rose 4 [Rose 10 []]]
should return Rose 4 [Rose 1 [Rose 1 [], Rose 2 []], Rose 3 [], Rose 4 [Rose 10 []]]
I'm getting an error " Non-exhaustive patterns in function rosesToRose" and I'm not sure whats causing it. Tried matching against an empty list as input and got the same error. Any suggestions would be appreciated.
My code:
data Rose a = Rose a [Rose a]
deriving Show
rosesToRose:: (Ord a, Num a )=> [Rose a] -> Rose a
rosesToRose [(Rose node tree)] = Rose (maxRoseNode [(Rose node tree)]) [(Rose node tree)]
maxRoseNode:: (Ord a,Num a) =>[Rose a] -> a
maxRoseNode trs = case trs of
[] -> 0
(Rose node tree):xs -> maximum ([maxRoseNode xs] ++ [node])