title: Map function for custom n-ary tree
body: <p>I'm trying to get a mapping function like <a href="http://en.wikibooks.org/wiki/Haskell/More_on_datatypes#Map" rel="nofollow noreferrer">this</a> working for an n-ary tree, but am struggling.</p>
  
  <pre><code>data NTree a = Leaf a | Node a [NTree a]
  
  ntreeMap :: (a -&gt; b) -&gt; NTree a -&gt; NTree b
  ntreeMap f (Leaf x) = Leaf (f x)
  ntreeMap f (Node y t) = Node (ntreeMap f y) (ntreeMap f t)
  </code></pre>
  
  <p>gives me </p>
  
  <pre>
   Type error in application
  *** Expression     : ntreeMap f t
  *** Term           : t
  *** Type           : [NTree b]
  *** Does not match : NTree a
  </pre>
  
  <p>Could someone give me a pointer as to where I'm going wrong? Thanks</p>