|
Data.Semigroup | Portability | portable | Stability | provisional | Maintainer | Edward Kmett <ekmett@gmail.com> |
|
|
|
|
|
Description |
In mathematics, a semigroup is an algebraic structure consisting of a
set together with an associative binary operation. A semigroup
generalizes a monoid in that there might not exist an identity
element. It also (originally) generalized a group (a monoid with all
inverses) to a type where every element did not have to have an inverse,
thus the name semigroup.
The use of () in this module conflicts with an operator with the same
name that is being exported by Data.Monoid. However, this package
re-exports (most of) the contents of Data.Monoid, so to use semigroups
and monoids in the same package just
import Data.Semigroup
|
|
Synopsis |
|
|
|
Documentation |
|
|
| Methods | | An associative operation.
(a <> b) <> c = a <> (b <> c)
| | | Reduce a non-empty list with <>
The default definition should be sufficient, but this can be overridden for efficiency.
| | | Repeat a value (n + 1) times.
times1p n a = a <> a <> ... <> a -- using <> n times
The default definition uses peasant multiplication, exploiting associativity to only
require O(log n) uses of <>.
|
| | Instances | Semigroup () | Semigroup All | Semigroup Any | Semigroup IntSet | Semigroup [a] | Semigroup a => Semigroup (Dual a) | Semigroup (Endo a) | Num a => Semigroup (Sum a) | Num a => Semigroup (Product a) | Semigroup (First a) | Semigroup (Last a) | Semigroup a => Semigroup (Maybe a) | Semigroup (IntMap v) | Ord a => Semigroup (Set a) | Semigroup (Seq a) | Semigroup (NonEmpty a) | Semigroup a => Semigroup (Option a) | Monoid m => Semigroup (WrappedMonoid m) | Semigroup (Last a) | Semigroup (First a) | Ord a => Semigroup (Max a) | Ord a => Semigroup (Min a) | Semigroup b => Semigroup (a -> b) | Semigroup (Either a b) | (Semigroup a, Semigroup b) => Semigroup (a, b) | Ord k => Semigroup (Map k v) | (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) | (Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) | (Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) |
|
|
|
Semigroups
|
|
|
Constructors | | Instances | |
|
|
|
Constructors | | Instances | |
|
|
|
Use Option (First a) -- to get the behavior of Data.Monoid.First
| Constructors | | Instances | |
|
|
|
Use Option (Last a) -- to get the behavior of Data.Monoid.Last
| Constructors | | Instances | |
|
|
newtype WrappedMonoid m | Source |
|
Provide a Semigroup for an arbitrary Monoid.
| Constructors | | Instances | |
|
|
Re-exported monoids from Data.Monoid
|
|
|
The class of monoids (types with an associative binary operation that
has an identity). Instances should satisfy the following laws:
- mappend mempty x = x
- mappend x mempty = x
- mappend x (mappend y z) = mappend (mappend x y) z
- mconcat = foldr mappend mempty
The method names refer to the monoid of lists under concatenation,
but there are many other instances.
Minimal complete definition: mempty and mappend.
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.
| | Methods | | Identity of mappend
| | | An associative operation
| | | Fold a list using the monoid.
For most types, the default definition for mconcat will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
|
| | Instances | Monoid Ordering | Monoid () | Monoid All | Monoid Any | Monoid IntSet | Monoid [a] | Monoid a => Monoid (Dual a) | Monoid (Endo a) | Num a => Monoid (Sum a) | Num a => Monoid (Product a) | Monoid (First a) | Monoid (Last a) | Monoid a => Monoid (Maybe a) | Monoid (IntMap a) | Ord a => Monoid (Set a) | Monoid (Seq a) | Semigroup a => Monoid (Option a) | Monoid m => Monoid (WrappedMonoid m) | (Ord a, Bounded a) => Monoid (Max a) | (Ord a, Bounded a) => Monoid (Min a) | Monoid b => Monoid (a -> b) | (Monoid a, Monoid b) => Monoid (a, b) | Ord k => Monoid (Map k v) | (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) |
|
|
|
|
The dual of a monoid, obtained by swapping the arguments of mappend.
| Constructors | | Instances | |
|
|
|
The monoid of endomorphisms under composition.
| Constructors | | Instances | |
|
|
|
Boolean monoid under conjunction.
| Constructors | | Instances | |
|
|
|
Boolean monoid under disjunction.
| Constructors | | Instances | |
|
|
|
Monoid under addition.
| Constructors | | Instances | |
|
|
|
Monoid under multiplication.
| Constructors | | Instances | |
|
|
A better monoid for Maybe
|
|
|
Option is effectively Maybe with a better instance of Monoid, built off of an underlying Semigroup
instead of an underlying Monoid. Ideally, this type would not exist at all and we would just fix the Monoid intance of Maybe
| Constructors | | Instances | |
|
|
|
|
Difference lists of a semigroup
|
|
|
This lets you use a difference list of a Semigroup as a Monoid.
|
|
|
A generalization of Data.List.cycle to an arbitrary Semigroup.
May fail to terminate for some values in some semigroups.
|
|
Produced by Haddock version 2.6.1 |