You may need to implement the Data.Traversable class or Data.Foldable class for your tree structure. Each only needs to define one method.
In particular, if you implement the Data.Foldable class, you get the following two functions for free:
mapM_ :: (Foldable t, Monad m) => (a -> mb) -> ta -> m () toList :: Foldable t => ta -> [a]
It will also provide you with a rich set of functions ( foldr , concatMap , any , ...) that you use to use with a list type.
You need to perform one of the following functions to create an instance of Data.Foldable :
foldMap :: Monoid m => (a -> m) -> ta -> m foldr :: (a -> b -> b) -> b -> ta -> b
source share