0

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.

Community
  • 1
  • 1
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
  • 1
    "I found this question useful, but I didn't find my answer." -- How so? – Shoe May 04 '15 at 01:01
  • 1
    in particular, I'm curious about why `newtype` gets used over `data`. I'm not arguing for the latter, but that's my question. – Kevin Meredith May 04 '15 at 01:01
  • 1
    What about [this question](http://stackoverflow.com/questions/2649305/why-is-there-data-and-newtype-in-haskell)? – Shoe May 04 '15 at 01:02
  • 1
    Or [this one](http://stackoverflow.com/questions/5889696/difference-between-data-and-newtype-in-haskell)? – Shoe May 04 '15 at 01:02
  • 1
    Or what about [this one](http://stackoverflow.com/questions/991467/haskell-type-vs-newtype-with-respect-to-type-safety)? – Shoe May 04 '15 at 01:03

0 Answers0