HORIZON HASKELLDocslts/ghc-9.14.x7a6c33e2026-10-12Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 7a6c33e · 2026-10-12

Modulemonoid-extras-0.7.0.2Haskell2010

Data.Monoid.MList

Heterogeneous lists of monoids.

Contents
  1. Heterogeneous monoidal lists
  2. Accessing embedded values
  3. Monoid actions of heterogeneous lists
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.

value(*:) :: a -> l -> a ::: l
#
classclass 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.

Instances2MList
  • MList ()Defined in monoid-extras-0.7.0.2 · Data.Monoid.MList
  • MList l => MList (a ::: l)Defined in monoid-extras-0.7.0.2 · Data.Monoid.MList

Accessing embedded values

classclass (:>:) 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 -> Maybe a

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

  • alt :: (Maybe a -> Maybe a) -> l -> l

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

Instances2:>:
  • MList t => (a ::: t) :>: aDefined in monoid-extras-0.7.0.2 · Data.Monoid.MList
  • t :>: a => (b ::: t) :>: aDefined in monoid-extras-0.7.0.2 · Data.Monoid.MList

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.

newtypenewtype 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

Instances3Show, Action
  • Show m => Show (SM m)Defined in monoid-extras-0.7.0.2 · Data.Monoid.MList
  • Action (SM a) ()Defined in monoid-extras-0.7.0.2 · Data.Monoid.MList
  • (Action a a', Action (SM a) l) => Action (SM a) (Maybe a', l)Defined in monoid-extras-0.7.0.2 · Data.Monoid.MList

Orphan instances

1 instance