Code given:
data Tree a b = Leaf a | Branch b [Tree a b] deriving (Eq,Read,Show)
--with these trees defines
t1 = Branch "+" [Leaf 10, Leaf 20, Branch "*" [Leaf 2, Leaf 3, Leaf 4], Leaf 50]
t2 = Branch "*" [t1,t1,t1] //should multiply t1 3 times
How can I find the value of t1? As in, 10 + 20 + (2 * 3 * 4) + 50 = 104
I've started a solve function:
solve (Leaf a) = a
solve (Branch _ ts) = //not sure how to make it solve itself recursively here.
Any help would be appreciated. Thank you.