Type class for monoid (and semigroup) actions, where monoidal
values of type m "act" on values of another type s.
Instances are required to satisfy the laws
act mempty = idact (m1 `mappend` m2) = act m1 . act m2
Semigroup instances are required to satisfy the second law but with
(<>) instead of mappend. Additionally, if the type s has
any algebraic structure, act m should be a homomorphism. For
example, if s is also a monoid we should have act m mempty =
mempty and act m (s1 `mappend` s2) = (act m s1) `mappend`
(act m s2).
By default, act = const id, so for a type M which should have
no action on anything, it suffices to write
instance Action M swith no method implementations.
It is a bit awkward dealing with instances of Action, since it
is a multi-parameter type class but we can't add any functional
dependencies---the relationship between monoids and the types on
which they act is truly many-to-many. In practice, this library
has chosen to have instance selection for Action driven by the
first type parameter. That is, you should never write an
instance of the form Action m SomeType since it will overlap
with instances of the form Action SomeMonoid t. Newtype
wrappers can be used to (awkwardly) get around this.
Methods
act :: m -> s -> sConvert a value of type
mto an action onsvalues.
Instances15Action, …
Action () lDefined in monoid-extras-0.6.2 · Data.Monoid.Action()acts as the identity.Semigroup m => Action m (Regular m)Defined in monoid-extras-0.6.2 · Data.Monoid.ActionNum a => Action Integer (Product a)Defined in monoid-extras-0.6.2 · Data.Monoid.ActionNum a => Action Integer (Sum a)Defined in monoid-extras-0.6.2 · Data.Monoid.ActionFractional a => Action Rational (Product a)Defined in monoid-extras-0.6.2 · Data.Monoid.ActionFractional a => Action Rational (Sum a)Defined in monoid-extras-0.6.2 · Data.Monoid.ActionGroup m => Action m (Conjugate m)Defined in monoid-extras-0.6.2 · Data.Monoid.ActionAction (Endo a) aDefined in monoid-extras-0.6.2 · Data.Monoid.ActionEndoacts by application.Note that in order for this instance to satisfy the
Actionlaws, whenever the typeahas some sort of algebraic structure, the typeEndo amust be considered to represent homomorphisms (structure-preserving maps) ona, even though there is no way to enforce this in the type system. For example, ifais an instance ofMonoid, then one should only useEndo avaluesfwith the property thatf mempty = memptyandf (a <> b) = f a <> f b.Action (SM a) ()Defined in monoid-extras-0.6.2 · Data.Monoid.MListAction m n => Action (Split m) nDefined in monoid-extras-0.6.2 · Data.Monoid.SplitBy default, the action of a split monoid is the same as for the underlying monoid, as if the split were removed.
Action m s => Action (Maybe m) sDefined in monoid-extras-0.6.2 · Data.Monoid.ActionNothingacts as the identity;Just macts asm.(Action a a', Action (SM a) l) => Action (SM a) (Maybe a', l)Defined in monoid-extras-0.6.2 · Data.Monoid.MList(Action (SM a) l2, Action l1 l2) => Action (a, l1) l2Defined in monoid-extras-0.6.2 · Data.Monoid.MList · orphan(Action m n, Action m r, Action n r, Semigroup n) => Action (m :+: n) rDefined in monoid-extras-0.6.2 · Data.Monoid.Coproduct.StrictCoproducts act on other things by having each of the components act individually.
(Action m r, Action n r) => Action (m :+: n) rDefined in monoid-extras-0.6.2 · Data.Monoid.CoproductCoproducts act on other things by having each of the components act individually.