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