data Tree a = Leaf a | Branch (Tree a) (Tree a)

multiply (Leaf x)     = x
multiply (Branch l r) = multiply l * multiply r

{-- Test it with:

multiply (Branch (Branch (Leaf 3) (Leaf 2)) (Leaf 4))

--}


visit bf lf (Leaf x)     = lf x
visit bf lf (Branch l r) = bf (visit bf lf l)
                              (visit bf lf r)

{-- Test it with:

visit (*) (\x->x) (Branch (Branch (Leaf 3) (Leaf 2)) (Leaf 4))

visit (++) (\x -> [x]) (Branch (Branch (Leaf 3) (Leaf 2)) (Leaf 4))

--}

