Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

- class Semigroup a where
- class Monoid a where
- class Monoid a => Group a where
- class Semigroup a => Abelian a
- class Semigroup a => Idempotent a
- (+) :: Semigroup (Sum a) => a -> a -> a
- (-) :: (Semigroup (Sum a), Group (Sum a)) => a -> a -> a
- (*) :: Semigroup (Product a) => a -> a -> a
- (/) :: (Semigroup (Product a), Group (Product a)) => a -> a -> a

# Documentation

The class of semigroups (types with an associative binary operation).

*Since: 4.9.0.0*

(<>) :: a -> a -> a infixr 6 #

An associative operation.

(a`<>`

b)`<>`

c = a`<>`

(b`<>`

c)

If `a`

is also a `Monoid`

we further require

(`<>`

) =`mappend`

Reduce a non-empty list with `<>`

The default definition should be sufficient, but this can be overridden for efficiency.

stimes :: Integral b => b -> a -> a #

Repeat a value `n`

times.

Given that this works on a `Semigroup`

it is allowed to fail if
you request 0 or fewer repetitions, and the default definition
will do so.

By making this a member of the class, idempotent semigroups and monoids can
upgrade this to execute in *O(1)* by picking
`stimes = stimesIdempotent`

or `stimes = stimesIdempotentMonoid`

respectively.

Semigroup Ordering | |

Semigroup () | |

Semigroup Void | |

Semigroup All | |

Semigroup Any | |

Semigroup [a] | |

Semigroup a => Semigroup (Maybe a) | |

Semigroup a => Semigroup (Identity a) | |

Ord a => Semigroup (Min a) | |

Ord a => Semigroup (Max a) | |

Semigroup (First a) | |

Semigroup (Last a) | |

Monoid m => Semigroup (WrappedMonoid m) | |

Semigroup a => Semigroup (Option a) | |

Semigroup (NonEmpty 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 b => Semigroup (a -> b) | |

Semigroup (Either a b) | |

(Semigroup a, Semigroup b) => Semigroup (a, b) | |

Semigroup (Proxy k s) | |

(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) | |

Semigroup a => Semigroup (Const k a b) | |

Alternative f => Semigroup (Alt * f a) | |

(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) | |

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.

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 `newtype`

s and make those instances
of `Monoid`

, e.g. `Sum`

and `Product`

.

Monoid Ordering | |

Monoid () | |

Monoid All | |

Monoid Any | |

Monoid [a] | |

Monoid a => Monoid (Maybe a) | Lift a semigroup into |

Monoid a => Monoid (IO a) | |

Monoid a => Monoid (Identity a) | |

(Ord a, Bounded a) => Monoid (Min a) | |

(Ord a, Bounded a) => Monoid (Max a) | |

Monoid m => Monoid (WrappedMonoid m) | |

Semigroup a => Monoid (Option 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 b => Monoid (a -> b) | |

(Monoid a, Monoid b) => Monoid (a, b) | |

Monoid (Proxy k s) | |

(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | |

Monoid a => Monoid (Const k a b) | |

Alternative f => Monoid (Alt * f a) | |

(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) | |

class Monoid a => Group a where Source #

Group () Source # | |

Group a => Group (IO a) Source # | |

Group a => Group (Identity a) Source # | |

Group a => Group (Dual a) Source # | |

Group (Sum Integer) Source # | |

Group b => Group (a -> b) Source # | |

(Group a, Group b) => Group (a, b) Source # | |

Group (Proxy k a) Source # | |

(Group a, Group b, Group c) => Group (a, b, c) Source # | |

Group a => Group (Const k a b) Source # | |

(Group a, Group b, Group c, Group d) => Group (a, b, c, d) Source # | |

(Group a, Group b, Group c, Group d, Group e) => Group (a, b, c, d, e) Source # | |

class Semigroup a => Idempotent a Source #