Safe Haskell | Safe |
---|---|
Language | Haskell98 |
Compatibility layer for Data.Semigroup
Documentation
class Semigroup a where Source
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.
Monoid Ordering | |
Monoid () | |
Monoid All | |
Monoid Any | |
Monoid ByteString | |
Monoid ByteString | |
Monoid IntSet | |
Monoid Doc | |
Monoid CDialect | |
Monoid BuildInfo | |
Monoid BenchmarkInterface | |
Monoid Benchmark | |
Monoid TestSuiteInterface | |
Monoid TestSuite | |
Monoid Executable | |
Monoid Library | |
Monoid ModuleRenaming | |
Monoid SetupBuildInfo | |
Monoid BenchmarkFlags | |
Monoid TestFlags | |
Monoid TestShowDetails | |
Monoid ReplFlags | |
Monoid BuildFlags | |
Monoid CleanFlags | |
Monoid HaddockFlags | |
Monoid HscolourFlags | |
Monoid RegisterFlags | |
Monoid SDistFlags | |
Monoid InstallFlags | |
Monoid CopyFlags | |
Monoid ConfigFlags | |
Monoid GlobalFlags | |
Monoid GhcOptions | |
Monoid [a] | |
Ord a => Monoid (Max a) | |
Ord a => Monoid (Min 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) | Lift a semigroup into |
Monoid (IntMap a) | |
Ord a => Monoid (Set a) | |
Monoid (Seq a) | |
Monoid (Condition a) | |
(Semigroup dir, Monoid dir) => Monoid (InstallDirs dir) | |
Ord a => Monoid (NubListR a) | |
Ord a => Monoid (NubList a) | Monoid operations on NubLists. For a valid Monoid instance we need to satistfy the required monoid laws; identity, associativity and closure. Identity : by inspection:
mempty Associativity : by inspection:
(NubList xs Closure : appending two lists of type a and removing duplicates obviously does not change the type. |
HasUnitId a => Monoid (PackageIndex a) | |
Monoid (Flag a) | |
Monoid b => Monoid (a -> b) | |
(Monoid a, Monoid b) => Monoid (a, b) | |
Monoid a => Monoid (Const a b) | |
Monoid (Proxy k s) | |
Ord k => Monoid (Map k v) | |
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | |
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) |