I'm trying to get a mapping function like this working for an n-ary tree, but am struggling.

```
data NTree a = Leaf a | Node a [NTree a]
ntreeMap :: (a -> b) -> NTree a -> NTree b
ntreeMap f (Leaf x) = Leaf (f x)
ntreeMap f (Node y t) = Node (ntreeMap f y) (ntreeMap f t)
```

gives me

Type error in application *** Expression : ntreeMap f t *** Term : t *** Type : [NTree b] *** Does not match : NTree a

Could someone give me a pointer as to where I'm going wrong? Thanks

## comments:

`derive`

package (hackage.haskell.org/package/derive) for this to work. Also, as of GHC 6.12 you can simply use`deriving Functor`

in your code (by using the`-XDerivingFunctor`

extension).