title: How do I map functions over a RoseTree in Applicative (Haskell)?
body: <p>How do I apply applicative to a RoseTree, i.e. return a tree composed of trees created by the successive application of functions to initial nodes. Here's the code that I have written:</p>
  
  <pre><code>{-# LANGUAGE DeriveFunctor, InstanceSigs #-}
  
  data RoseTree a = Nil | Node a [RoseTree a] deriving(Functor,Show)
  
  instance Applicative RoseTree where
      pure :: a -&gt; RoseTree a
      pure x = Node x []
  
      (&lt;*&gt;) :: RoseTree (a -&gt; b) -&gt; RoseTree a -&gt; RoseTree b
      (&lt;*&gt;) _ Nil = Nil
      (&lt;*&gt;) Nil _ = Nil
      (&lt;*&gt;) (Node f tree) (Node x subtrees) = Node (f x) (zipWith (&lt;*&gt;) tree subtrees)
  </code></pre>
  
  <p>I am unsure what's wrong with my definition of pure and (&lt;*>). Here's the error I got:</p>
  
  <p>Error:
  <code>failure in expression `(Node (+1) []) &lt;*&gt; (Node 7 [Node 1 [], Node 2 [], Node 3 [Node 4 []]])'
  expected: Node 8 [Node 2 [],Node 3 [],Node 4 [Node 5 []]]
   but got: Node 8 []</code></p>
  
  <p>Test cases for reference:</p>
  
  <pre><code>-- &gt;&gt;&gt; (Node (+1) [Node (*2) []]) &lt;*&gt; Nil
  -- Nil
  --
  -- &gt;&gt;&gt; Nil &lt;*&gt; (Node 7 [Node 1 [], Node 2 [], Node 3 [Node 4 []]])
  -- Nil
  --
  -- &gt;&gt;&gt; (Node (+1) []) &lt;*&gt; (Node 7 [Node 1 [], Node 2 [], Node 3 [Node 4 []]])
  -- Node 8 [Node 2 [],Node 3 [],Node 4 [Node 5 []]]
  --
  -- &gt;&gt;&gt; (Node (+1) [Node (*2) []]) &lt;*&gt; (Node 5 [Node 2 [], Node 8 [Node 1 []]])
  -- Node 6 [Node 3 [],Node 9 [Node 2 []],Node 10 [Node 4 [],Node 16 [Node 2 []]]]
  </code></pre>