Monoid package:universum
This module reexports functions to work with monoids plus adds extra
useful functions.
The class of monoids (types with an associative binary operation that
has an identity). Instances should satisfy the following:
You can alternatively define
mconcat instead of
mempty,
in which case the laws are:
The method names refer to the monoid of lists under concatenation, but
there are many other instances.
Some types can be viewed as a monoid in more than one way, e.g. both
addition and multiplication on numbers. In such cases we often define
newtypes and make those instances of
Monoid, e.g.
Sum and
Product.
NOTE:
Semigroup is a superclass of
Monoid since
base-4.11.0.0.
Provide a Semigroup for an arbitrary Monoid.
NOTE: This is not needed anymore since
Semigroup became
a superclass of
Monoid in
base-4.11 and this newtype be
deprecated at some point in the future.
Extracts
Monoid value from
Maybe returning
mempty
if
Nothing.
>>> maybeToMonoid (Just [1,2,3] :: Maybe [Int])
[1,2,3]
>>> maybeToMonoid (Nothing :: Maybe [Int])
[]
This is a valid definition of
stimes for an idempotent
Monoid.
When
x <> x = x, this definition should be preferred,
because it works in <math> rather than <math>
This is a valid definition of
stimes for a
Monoid.
Unlike the default definition of
stimes, it is defined for 0
and so it should be preferred where possible.