3 ms·
The main reason Haskell does not define Monoid instances for numbers is that there are two equally valid instances: with 1 and * or with 0 and +. So, instead, t
by garethrowlands 4y ago
The main reason Haskell does not define Monoid instances for numbers is that there are two equally valid instances: with 1 and * or with 0 and +. So, instead, there are two newtypes defined:
* `Sum` whose `mempty` (identity) is `Sum 0` and `<>` (combining operator) is multiplication; and
* `Product` whose `mempty` is `Product 1` and `<>` is addition
You have to choose one explicitly. That is, you can't say `2 <> 3` and expect 6 (or is it 5?). Instead you have to say `Product 2 <> Product 3`
- a1369209993 4y ago> * `Sum` whose [`<>`] is multiplication; and * `Product` whose [...] `<>` is addition ... Uhh?
- nequo 4y agoParent probably wanted to create two bullet points with the two asterisks.
- a1369209993 4y agoI was actually questioning the "Sum is multiplication, Product is addition" part, although now that you mention it, the lack of a line break is also a (less significant) problem.