Typeclassopedia comments on Monoids:
since we can’t have two instances for the same type,
Data.Monoid provides two newtype wrappers, Sum and Product,
with appropriate Monoid instances.
> getSum (mconcat . map Sum $ [1..5])
15
> getProduct (mconcat . map Product $ [1..5])
120
Why is a newtype
wrapper, rather than data
, used?
Note - I found this question useful, but I didn't find my answer.