Maintainer | bastiaan.heeren@ou.nl |
---|---|
Stability | provisional |
Portability | portable (depends on ghc) |
Safe Haskell | None |
Language | Haskell98 |
- 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 =
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
.
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.
Groups
Monoids with a zero element
class Monoid a => MonoidZero a where Source
Monoid a => MonoidZero (WithZero a) Source | |
SemiRing a => MonoidZero (Multiplicative a) Source | |
Boolean a => MonoidZero (Or a) Source | |
Boolean a => MonoidZero (And a) Source | |
(CoGroup a, MonoidZero a, Group a) => MonoidZero (SmartGroup a) Source | |
(CoMonoidZero a, MonoidZero a) => MonoidZero (SmartZero a) Source | |
(CoMonoid a, MonoidZero a) => MonoidZero (Smart a) Source |
Functor WithZero Source | |
Applicative WithZero Source | |
Foldable WithZero Source | |
Traversable WithZero Source | |
Eq a => Eq (WithZero a) Source | |
Ord a => Ord (WithZero a) Source | |
Monoid a => Monoid (WithZero a) Source | |
CoMonoid a => CoMonoidZero (WithZero a) Source | |
CoMonoid a => CoMonoid (WithZero a) Source | |
Monoid a => MonoidZero (WithZero a) Source |
fromWithZero :: WithZero a -> Maybe a Source
CoMonoid, CoGroup, and CoMonoidZero (for matching)
CoMonoid [a] Source | |
CoMonoid (Set a) Source | |
CoMonoid a => CoMonoid (WithZero a) Source | |
CoSemiRing a => CoMonoid (Multiplicative a) Source | |
CoSemiRing a => CoMonoid (Additive a) Source | |
CoBoolean a => CoMonoid (Or a) Source | |
CoBoolean a => CoMonoid (And a) Source | |
CoMonoid a => CoMonoid (SmartGroup a) Source | |
CoMonoid a => CoMonoid (SmartZero a) Source | |
CoMonoid a => CoMonoid (Smart a) Source |
class CoMonoid a => CoMonoidZero a where Source
isMonoidZero :: a -> Bool Source
CoMonoid a => CoMonoidZero (WithZero a) Source | |
CoSemiRing a => CoMonoidZero (Multiplicative a) Source | |
CoBoolean a => CoMonoidZero (Or a) Source | |
CoBoolean a => CoMonoidZero (And a) Source | |
CoMonoidZero a => CoMonoidZero (SmartGroup a) Source | |
CoMonoidZero a => CoMonoidZero (SmartZero a) Source | |
CoMonoidZero a => CoMonoidZero (Smart a) Source |
associativeList :: CoMonoid a => a -> [a] Source