Search code examples
haskelltypesmonoids

No Monoid instance for Integer


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.


Solution

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