IPiiro
IPiiro

Reputation: 97

Why Float is not instance of the Monoid type class?

My question is why Float is not readily defined to be an instance of the Monoid type class ? I mean what is against it ? Doesn't Floats have the identity element and if no why? Also the operations (*) and (+) are associative in the set of Floats, or ?

Upvotes: 0

Views: 391

Answers (1)

Dietrich Epp
Dietrich Epp

Reputation: 213768

Which monoid is are you talking about? Sum? Product?

These are already available by wrapping the type with the newtype Sum or Product. But you are correct that addition and multiplication are not associative for floating-point numbers. That's somewhat a different issue, however. The issue is that there's not an obvious "correct" monoid to choose by default.

Upvotes: 6

Related Questions