monoid-extras-0.5: Various extra monoid-related definitions and utilities

Data.Monoid.MList

Description

Heterogeneous lists of monoids.

Synopsis

# Heterogeneous monoidal lists

The idea of heterogeneous lists has been around for a long time. Here, we adopt heterogeneous lists where the element types are all monoids: this allows us to leave out identity values, so that a heterogeneous list containing only a single non-identity value can be created without incurring constraints due to all the other types, by leaving all the other values out.

type (:::) a l = (Option a, l) infixr 5 #

(*:) :: a -> l -> a ::: l infixr 5 #

class MList l where #

Type class for heterogeneous monoidal lists, with a single method allowing construction of an empty list.

Methods

empty :: l #

The empty heterogeneous list of type l. Of course, empty == mempty, but unlike mempty, empty does not require Monoid constraints on all the elements of l.

Instances
 MList () # Instance detailsDefined in Data.Monoid.MList Methodsempty :: () # MList l => MList (a ::: l) # Instance detailsDefined in Data.Monoid.MList Methodsempty :: a ::: l #

# Accessing embedded values

class l :>: a where #

The relation l :>: a holds when a is the type of an element in l. For example, (Char ::: Int ::: Bool ::: Nil) :>: Int.

Methods

inj :: a -> l #

Inject a value into an otherwise empty heterogeneous list.

get :: l -> Option a #

Get the value of type a from a heterogeneous list, if there is one.

alt :: (Option a -> Option a) -> l -> l #

Alter the value of type a by applying the given function to it.

Instances
 t :>: a => (b ::: t) :>: a # Instance detailsDefined in Data.Monoid.MList Methodsinj :: a -> b ::: t #get :: (b ::: t) -> Option a #alt :: (Option a -> Option a) -> (b ::: t) -> b ::: t # MList t => (a ::: t) :>: a # Instance detailsDefined in Data.Monoid.MList Methodsinj :: a -> a ::: t #get :: (a ::: t) -> Option a #alt :: (Option a -> Option a) -> (a ::: t) -> a ::: t #

# Monoid actions of heterogeneous lists

Monoidal heterogeneous lists may act on one another as you would expect, with each element in the first list acting on each in the second. Unfortunately, coding this up in type class instances is a bit fiddly.

newtype SM m #

SM, an abbreviation for "single monoid" (as opposed to a heterogeneous list of monoids), is only used internally to help guide instance selection when defining the action of heterogeneous monoidal lists on each other.

Constructors

 SM m
Instances
 Show m => Show (SM m) # Instance detailsDefined in Data.Monoid.MList MethodsshowsPrec :: Int -> SM m -> ShowS #show :: SM m -> String #showList :: [SM m] -> ShowS # Action (SM a) () # Instance detailsDefined in Data.Monoid.MList Methodsact :: SM a -> () -> () # (Action a a', Action (SM a) l) => Action (SM a) (Option a', l) # Instance detailsDefined in Data.Monoid.MList Methodsact :: SM a -> (Option a', l) -> (Option a', l) #

# Orphan instances

 (Action (SM a) l2, Action l1 l2) => Action (a, l1) l2 # Instance details Methodsact :: (a, l1) -> l2 -> l2 #