monoid-extras-0.6.2: Various extra monoid-related definitions and utilities
Copyright(c) 2011 diagrams-core team (see LICENSE)
LicenseBSD-style (see LICENSE)
Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Monoid.Action

Description

Monoid and semigroup actions.

Synopsis

Documentation

class Action m s where Source #

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.

Minimal complete definition

Nothing

Methods

act :: m -> s -> s Source #

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

Instances

Instances details
Action () l Source #

() acts as the identity.

Instance details

Defined in Data.Monoid.Action

Methods

act :: () -> l -> l Source #

Fractional a => Action Rational (Product a) Source # 
Instance details

Defined in Data.Monoid.Action

Methods

act :: Rational -> Product a -> Product a Source #

Fractional a => Action Rational (Sum a) Source # 
Instance details

Defined in Data.Monoid.Action

Methods

act :: Rational -> Sum a -> Sum a Source #

Num a => Action Integer (Product a) Source # 
Instance details

Defined in Data.Monoid.Action

Methods

act :: Integer -> Product a -> Product a Source #

Num a => Action Integer (Sum a) Source # 
Instance details

Defined in Data.Monoid.Action

Methods

act :: Integer -> Sum a -> Sum a Source #

Group m => Action m (Conjugate m) Source # 
Instance details

Defined in Data.Monoid.Action

Methods

act :: m -> Conjugate m -> Conjugate m Source #

Semigroup m => Action m (Regular m) Source # 
Instance details

Defined in Data.Monoid.Action

Methods

act :: m -> Regular m -> Regular m Source #

Action (Endo a) a Source #

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.

Instance details

Defined in Data.Monoid.Action

Methods

act :: Endo a -> a -> a Source #

Action (SM a) () Source # 
Instance details

Defined in Data.Monoid.MList

Methods

act :: SM a -> () -> () Source #

Action m n => Action (Split m) n Source #

By default, the action of a split monoid is the same as for the underlying monoid, as if the split were removed.

Instance details

Defined in Data.Monoid.Split

Methods

act :: Split m -> n -> n Source #

Action m s => Action (Maybe m) s Source #

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

Instance details

Defined in Data.Monoid.Action

Methods

act :: Maybe m -> s -> s Source #

(Action a a', Action (SM a) l) => Action (SM a) (Maybe a', l) Source # 
Instance details

Defined in Data.Monoid.MList

Methods

act :: SM a -> (Maybe a', l) -> (Maybe a', l) Source #

(Action m r, Action n r) => Action (m :+: n) r Source #

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

Instance details

Defined in Data.Monoid.Coproduct

Methods

act :: (m :+: n) -> r -> r Source #

(Action m n, Action m r, Action n r, Semigroup n) => Action (m :+: n) r Source #

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

Instance details

Defined in Data.Monoid.Coproduct.Strict

Methods

act :: (m :+: n) -> r -> r Source #

(Action (SM a) l2, Action l1 l2) => Action (a, l1) l2 Source # 
Instance details

Defined in Data.Monoid.MList

Methods

act :: (a, l1) -> l2 -> l2 Source #

newtype Regular m Source #

Any monoid acts on itself by left multiplication. This newtype witnesses this action: getRegular $ Regular m1 `act` Regular m2 = m1 <> m2

Constructors

Regular 

Fields

Instances

Instances details
Semigroup m => Action m (Regular m) Source # 
Instance details

Defined in Data.Monoid.Action

Methods

act :: m -> Regular m -> Regular m Source #

Group m => Torsor m (Regular m) Source # 
Instance details

Defined in Data.Monoid.Action

Methods

difference :: Regular m -> Regular m -> m Source #

newtype Conjugate m Source #

Any group acts on itself by conjugation.

Constructors

Conjugate 

Fields

Instances

Instances details
Group m => Action m (Conjugate m) Source # 
Instance details

Defined in Data.Monoid.Action

Methods

act :: m -> Conjugate m -> Conjugate m Source #

class Group m => Torsor m s where Source #

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:

Methods

difference :: s -> s -> m Source #

difference sActed sOrig is the element m such that sActed = m `act` sOrig.

Instances

Instances details
Group m => Torsor m (Regular m) Source # 
Instance details

Defined in Data.Monoid.Action

Methods

difference :: Regular m -> Regular m -> m Source #