Data.Monoid
#Monoid
class (Semigroup m) <= Monoid m where
A Monoid
is a Semigroup
with a value mempty
, which is both a
left and right unit for the associative operation <>
:
- Left unit:
(mempty <> x) = x
- Right unit:
(x <> mempty) = x
Monoid
s are commonly used as the result of fold operations, where
<>
is used to combine individual results, and mempty
gives the result
of folding an empty collection of elements.
Members
mempty :: m
Instances
#power
power :: forall m. Monoid m => m -> Int -> m
Append a value to itself a certain number of times. For the
Multiplicative
type, and for a non-negative power, this is the same as
normal number exponentiation.
If the second argument is negative this function will return mempty
(unlike normal number exponentiation). The Monoid
constraint alone
is not enough to write a power
function with the property that power x
n
cancels with power x (-n)
, i.e. power x n <> power x (-n) = mempty
.
For that, we would additionally need the ability to invert elements, i.e.
a Group.
#guard
#MonoidRecord
class (SemigroupRecord rowlist row subrow) <= MonoidRecord rowlist row subrow | rowlist -> row subrow where
A class for records where all fields have Monoid
instances, used to
implement the Monoid
instance for records.
Members
memptyRecord :: RLProxy rowlist -> Record subrow
Instances
MonoidRecord Nil row ()
(IsSymbol key, Monoid focus, Cons key focus subrowTail subrow, MonoidRecord rowlistTail row subrowTail) => MonoidRecord (Cons key focus rowlistTail) row subrow
Re-exports from Data.Semigroup
#Semigroup
class Semigroup a
The Semigroup
type class identifies an associative operation on a type.
Instances are required to satisfy the following law:
- Associativity:
(x <> y) <> z = x <> (y <> z)
One example of a Semigroup
is String
, with (<>)
defined as string
concatenation.
Instances
#SemigroupRecord
class SemigroupRecord rowlist row subrow | rowlist -> subrow
A class for records where all fields have Semigroup
instances, used to
implement the Semigroup
instance for records.
Instances
SemigroupRecord Nil row ()
(IsSymbol key, Cons key focus subrowTail subrow, SemigroupRecord rowlistTail row subrowTail, Semigroup focus) => SemigroupRecord (Cons key focus rowlistTail) row subrow
#(<>)
Operator alias for Data.Semigroup.append (right-associative / precedence 5)
Modules
- Control.Alt
- Control.Alternative
- Control.Applicative
- Control.Apply
- Control.Biapplicative
- Control.Biapply
- Control.Bind
- Control.Category
- Control.Comonad
- Control.Extend
- Control.Lazy
- Control.Monad
- Control.Monad.Gen
- Control.Monad.Gen.Class
- Control.Monad.Gen.Common
- Control.Monad.Rec.Class
- Control.Monad.ST
- Control.Monad.ST.Class
- Control.Monad.ST.Global
- Control.Monad.ST.Internal
- Control.Monad.ST.Ref
- Control.MonadPlus
- Control.MonadZero
- Control.Plus
- Control.Semigroupoid
- Data.Array
- Data.Array.NonEmpty
- Data.Array.NonEmpty.Internal
- Data.Array.Partial
- Data.Array.ST
- Data.Array.ST.Iterator
- Data.Array.ST.Partial
- Data.Bifoldable
- Data.Bifunctor
- Data.Bifunctor.Clown
- Data.Bifunctor.Flip
- Data.Bifunctor.Join
- Data.Bifunctor.Joker
- Data.Bifunctor.Product
- Data.Bifunctor.Wrap
- Data.Bitraversable
- Data.Boolean
- Data.BooleanAlgebra
- Data.Bounded
- Data.Char
- Data.Char.Gen
- Data.Char.Utils
- Data.CommutativeRing
- Data.Distributive
- Data.DivisionRing
- Data.Either
- Data.Either.Inject
- Data.Either.Nested
- Data.Enum
- Data.Enum.Gen
- Data.Eq
- Data.EuclideanRing
- Data.Field
- Data.Foldable
- Data.FoldableWithIndex
- Data.Function
- Data.Function.Uncurried
- Data.Functor
- Data.Functor.Invariant
- Data.FunctorWithIndex
- Data.HeytingAlgebra
- Data.Identity
- Data.Int
- Data.Int.Bits
- Data.Maybe
- Data.Maybe.First
- Data.Maybe.Last
- Data.Monoid
- Data.Monoid.Additive
- Data.Monoid.Alternate
- Data.Monoid.Conj
- Data.Monoid.Disj
- Data.Monoid.Dual
- Data.Monoid.Endo
- Data.Monoid.Multiplicative
- Data.NaturalTransformation
- Data.Newtype
- Data.NonEmpty
- Data.Ord
- Data.Ord.Down
- Data.Ord.Max
- Data.Ord.Min
- Data.Ord.Unsafe
- Data.Ordering
- Data.Ring
- Data.Semigroup
- Data.Semigroup.First
- Data.Semigroup.Foldable
- Data.Semigroup.Last
- Data.Semigroup.Traversable
- Data.Semiring
- Data.Show
- Data.String
- Data.String.CaseInsensitive
- Data.String.CodePoints
- Data.String.CodeUnits
- Data.String.Common
- Data.String.Gen
- Data.String.NonEmpty
- Data.String.NonEmpty.CaseInsensitive
- Data.String.NonEmpty.CodePoints
- Data.String.NonEmpty.CodeUnits
- Data.String.NonEmpty.Internal
- Data.String.Pattern
- Data.String.Regex
- Data.String.Regex.Flags
- Data.String.Regex.Unsafe
- Data.String.Unsafe
- Data.String.Utils
- Data.Symbol
- Data.Traversable
- Data.Traversable.Accum
- Data.Traversable.Accum.Internal
- Data.TraversableWithIndex
- Data.Tuple
- Data.Tuple.Nested
- Data.Unfoldable
- Data.Unfoldable1
- Data.Unit
- Data.Void
- Effect
- Effect.Class
- Effect.Class.Console
- Effect.Console
- Effect.Ref
- Effect.Uncurried
- Effect.Unsafe
- Global
- Global.Unsafe
- MCPrelude
- Main
- Math
- PSCI.Support
- Partial
- Partial.Unsafe
- Prelude
- Prim
- Prim.Boolean
- Prim.Ordering
- Prim.Row
- Prim.RowList
- Prim.Symbol
- Prim.TypeError
- Record.Unsafe
- Type.Data.Row
- Type.Data.RowList
- Type.Equality
- Unsafe.Coerce