| Portability | portable (depends on ghc) |
|---|---|
| Stability | provisional |
| Maintainer | bastiaan.heeren@ou.nl |
| Safe Haskell | None |
Ideas.Common.Algebra.Group
Contents
Description
- class Monoid a where
- (<>) :: Monoid m => m -> m -> m
- class Monoid a => Group a where
- (<>-) :: Group a => a -> a -> a
- class Monoid a => MonoidZero a where
- mzero :: a
- data WithZero a
- fromWithZero :: WithZero a -> Maybe a
- class CoMonoid a where
- class CoMonoid a => CoGroup a where
- isInverse :: a -> Maybe a
- isAppendInv :: a -> Maybe (a, a)
- class CoMonoid a => CoMonoidZero a where
- isMonoidZero :: a -> Bool
- associativeList :: CoMonoid a => a -> [a]
Monoids
class Monoid a where
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 =
foldrmappend 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
mempty :: a
Identity of mappend
mappend :: a -> a -> a
An associative operation
mconcat :: [a] -> a
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
Groups
class Monoid a => Group a whereSource
Minimal complete definition: inverse or appendInverse
Instances
| Field a => Group (Multiplicative a) | |
| Ring a => Group (Additive a) | |
| (CoGroup a, Group a) => Group (SmartGroup a) |
Monoids with a zero element
class Monoid a => MonoidZero a whereSource
Instances
| Monoid a => MonoidZero (WithZero a) | |
| SemiRing a => MonoidZero (Multiplicative a) | |
| Boolean a => MonoidZero (Or a) | |
| Boolean a => MonoidZero (And a) | |
| (CoGroup a, MonoidZero a, Group a) => MonoidZero (SmartGroup a) | |
| (CoMonoidZero a, MonoidZero a) => MonoidZero (SmartZero a) | |
| (CoMonoid a, MonoidZero a) => MonoidZero (Smart a) |
fromWithZero :: WithZero a -> Maybe aSource
CoMonoid, CoGroup, and CoMonoidZero (for matching)
Instances
| CoMonoid [a] | |
| CoMonoid (Set a) | |
| CoMonoid a => CoMonoid (WithZero a) | |
| CoSemiRing a => CoMonoid (Multiplicative a) | |
| CoSemiRing a => CoMonoid (Additive a) | |
| CoBoolean a => CoMonoid (Or a) | |
| CoBoolean a => CoMonoid (And a) | |
| CoMonoid a => CoMonoid (SmartGroup a) | |
| CoMonoid a => CoMonoid (SmartZero a) | |
| CoMonoid a => CoMonoid (Smart a) |
class CoMonoid a => CoGroup a whereSource
Instances
| CoField a => CoGroup (Multiplicative a) | |
| CoRing a => CoGroup (Additive a) | |
| CoGroup a => CoGroup (SmartGroup a) |
class CoMonoid a => CoMonoidZero a whereSource
Methods
isMonoidZero :: a -> BoolSource
Instances
| CoMonoid a => CoMonoidZero (WithZero a) | |
| CoSemiRing a => CoMonoidZero (Multiplicative a) | |
| CoBoolean a => CoMonoidZero (Or a) | |
| CoBoolean a => CoMonoidZero (And a) | |
| CoMonoidZero a => CoMonoidZero (SmartGroup a) | |
| CoMonoidZero a => CoMonoidZero (SmartZero a) | |
| CoMonoidZero a => CoMonoidZero (Smart a) |
associativeList :: CoMonoid a => a -> [a]Source