traverse :: (a -> b) -> Tree a -> Tree b
traverse f (ATree e l) = ATree (f e) (map (traverse f) l)
Note your function has the same signature as fmap
so you should implement Functor
for your type:
instance Functor Tree where
fmap f (ATree e l) = ATree (f e) (fmap (traverse f) l)
in fact you can have the compiler generate your functor instance for you:
{-# LANGUAGE DeriveFunctor #-}
data Tree a = ATree a [Tree a] deriving (Show, Functor)