Here's my type:
data Tree a = Empty | Node a (Tree a) (Tree a)
Here's the instance declaration for Monoid:
instance (Monoid a) => Monoid (Tree a) where
mempty = Empty
mappend Empty Empty = Empty
mappend Empty t = t
mappend t Empty = t
mappend (Node val ta tb) (Node val' ta' tb') = (Node (mappend val val') (mappend ta ta') (mappend tb tb'))
This compiles, but it was tedious to write and very repetitive. Is there a better way of doing this?
<>
operator in the last line in the place ofmappend
. \$\endgroup\$