No Monoid instance for Integer

198 Views Asked by At

I am in my Haskell journey and came across Chapter 15.6 - Why Integer doesn’t have a Monoid from the purple book Haskell Programming From Frist Principles.

Is this limited to Integer type? It feels to me that it should be generalized to Int, Float, Double, etc.. all number types.

Because the only reason for Integer to not have a Monoidal instance is because its uniqueness is not specified, ie. Sum or Product wrappers have to be applied.

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, you are correct: Int, Float, Double, and other number types are not instances of Monoid unless you wrap them in Sum or Product.