I suppose this is an exercise / homework and only give you a nudge:
This Node (Tree a) a (Tree a) is:
- a left Tree
- a payload value of type
a.
- a right Tree
in this order. And here (\x t1 t2 -> Node (f x) t1 t2) you construct a -value- (edit: Node!) out of
- something that looks / is named like a value
f x
- tree1
- tree2
in that order.
Addressing the follow-up updated to mapTree f = foldTree Leaf (Node (f x) (\x t1 t2 -> t1 t2)): The "and here" above was deliberately vague, so lets have a look at
foldTree :: b -> (b -> a -> b -> b) -> Tree a -> b
-- 1 \_______2________/ 3 4
This takes:
- a value of type `b` for `Leafs`
- a combining function that takes:
- the result of the folded left tree `b`
- the value of the currently folded Node `a`
- the result of the folded right tree `b`
- and outputs a `b`
- the tree to be folded.
in this order. Your function `(\x t1 t2 -> Node (f x) t1 t2)` in place of 2 takes
- the value of the currently folded Node `a`
- the result of the folded left tree `b`
- the result of the folded right tree `b`
- and outputs a `b`
in that order.
So all you have to do is correct the order of both sides of the -> in (\x t1 t2 -> Node (f x) t1 t2).
Node (Tree a) a (Tree a);(b -> a -> b -> b);n (foldTree l n lt) x (foldTree l n rt); ====>n = (\ ..... -> Node .....(f x)..... ).