title: How to implement `zipTree` using `foldTree`?
body: <p>How do you implement <code>zipTree</code>, which behaves like this</p>
  <ol>
  <li>takes a <code>merger</code>, <code>tree1</code>, <code>tree2</code></li>
  <li>for each pair of node
  <ul>
  <li>if both possess value, merge with <code>merger</code></li>
  <li>otherwise turn into a <code>Leaf</code></li>
  </ul>
  </li>
  </ol>
  <pre><code>&gt;&gt;&gt; :t zipTree
  zipTree :: (a -&gt; a -&gt; b) -&gt; Tree a -&gt; Tree a -&gt; Tree b
  &gt;&gt;&gt; zipTree (+) (Branch 1 Leaf (Branch 2 Leaf Leaf)) (Branch 3 Leaf Leaf)
  (Branch 4 Leaf Leaf)
  </code></pre>
  <p>Using <code>foldTree</code> defined below</p>
  <pre><code>data Tree a = Leaf | Branch a (Tree a) (Tree a) deriving (Show, Eq)
  
  foldTree :: b -&gt; (a -&gt; b -&gt; b -&gt; b) -&gt; Tree a -&gt; b
  foldTree e _ Leaf     = e
  foldTree e n (Branch a n1 n2) = n a (foldTree e n n1) (foldTree e n n2)
  
  mapTree :: (a -&gt; b) -&gt; Tree a -&gt; Tree b
  mapTree f = foldTree Leaf (\x t1 t2 -&gt; Branch (f x) t1 t2)
  </code></pre>
  <p>I only managed to implement the self-recusive version w/o using <code>foldTree</code></p>
  <pre><code>zipTree :: (a -&gt; a -&gt; b) -&gt; Tree a -&gt; Tree a -&gt; Tree b
  zipTree f Leaf _ = Leaf
  zipTree f _ Leaf = Leaf
  zipTree f (Branch aroot a1 a2) (Branch broot b1 b2) = Branch (f aroot broot) (zipTree f a1 b1) (zipTree f a2 b2)
  </code></pre>
  <p>I have worked on the direction to return a callback with <code>foldTree</code> on <code>tree1</code> to operate on <code>tree2</code>, but to no avail</p>
  <p>Anyone knows how to use <code>foldTree</code> to implement the <code>zipTree</code>? Thanks in advance!</p>