File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,18 @@ import Type.Data.RowList (RLProxy(..))
28
28
-- | `Monoid`s are commonly used as the result of fold operations, where
29
29
-- | `<>` is used to combine individual results, and `mempty` gives the result
30
30
-- | of folding an empty collection of elements.
31
+ -- |
32
+ -- | Some types (e.g. `Int`, `Boolean`) can implement multiple law-abiding
33
+ -- | instances for `Monoid`. For example, `<>` could be `+` and `mempty` could
34
+ -- | be `0`. Likewise, `<>` could be `*` and `mempty` could be `1`.
35
+ -- | To workaround these ambiguous situations, one should use newtypes
36
+ -- | to specify which instance should be used:
37
+ -- | - `Additive`: use `Semiring`'s `plus`/`+` and `zero` for `<>` and `mempty`.
38
+ -- | - `Multiplicative`: use `Semiring`'s `mul`/`*` and `one` for `<>` and `mempty`.
39
+ -- | - `Conj`: use `HeytingAlgebra`'s `conj`/`&&` and `tt` for `<>` and `mempty`.
40
+ -- | - `Disj`: use `HeytingAlgebra`'s `disj`/`||` and `ff` for `<>` and `mempty`.
41
+ -- | - `Endo`: use `Category`'s `compose`/`<<<` and `identity` for `<>` and `mempty`.
42
+ -- | - `Dual`: use `Category`'s `composeFlipped`/`>>>` and `identity` for `<>` and `mempty`.
31
43
class Semigroup m <= Monoid m where
32
44
mempty :: m
33
45
You can’t perform that action at this time.
0 commit comments