HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulemonoid-extras-0.6.2Haskell2010

Data.Monoid.Action

Monoid and semigroup actions.

  • 2 types
  • 2 classes
classclass Action m s where
#

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 = id
  • act (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 s

with 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 -> s

    Convert a value of type m to an action on s values.

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.Action
  • Num a => Action Integer (Product a)Defined in monoid-extras-0.6.2 · Data.Monoid.Action
  • Num a => Action Integer (Sum a)Defined in monoid-extras-0.6.2 · Data.Monoid.Action
  • Fractional a => Action Rational (Product a)Defined in monoid-extras-0.6.2 · Data.Monoid.Action
  • Fractional a => Action Rational (Sum a)Defined in monoid-extras-0.6.2 · Data.Monoid.Action
  • Group m => Action m (Conjugate m)Defined in monoid-extras-0.6.2 · Data.Monoid.Action
  • Action (Endo a) aDefined in monoid-extras-0.6.2 · Data.Monoid.Action

    Endo acts by application.

    Note that in order for this instance to satisfy the Action laws, whenever the type a has some sort of algebraic structure, the type Endo a must be considered to represent homomorphisms (structure-preserving maps) on a, even though there is no way to enforce this in the type system. For example, if a is an instance of Monoid, then one should only use Endo a values f with the property that f mempty = mempty and f (a <> b) = f a <> f b.

  • Action (SM a) ()Defined in monoid-extras-0.6.2 · Data.Monoid.MList
  • Action m n => Action (Split m) nDefined in monoid-extras-0.6.2 · Data.Monoid.Split

    By 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.Action

    Nothing acts as the identity; Just m acts as m.

  • (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.Strict

    Coproducts 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.Coproduct

    Coproducts act on other things by having each of the components act individually.

classclass Group m => Torsor m s where
#

An action of a group is "free transitive", "regular", or a "torsor" iff it is invertible.

Given an original value sOrig, and a value sActed that is the result of acting on sOrig by some m, it is possible to recover this m. This is encoded in the laws:

  • (m `act' s) `difference' s = m
  • (sActed `difference' sOrig) `act' sOrig = sActed

Methods

Instances1Torsor