diagrams-core-0.5: Core libraries for diagrams EDSL

Maintainerdiagrams-discuss@googlegroups.com
Safe HaskellNone

Graphics.Rendering.Diagrams.MList

Contents

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.

data Nil Source

The empty heterogeneous list.

Constructors

Nil 

data a ::: l Source

Cons for heterogeneous lists.

Constructors

Missing l

The a value is missing, and should be construed as mempty.

a ::: l

An a value followed by a heterogeneous list l.

Instances

(Action a a', Action (SM a) l) => Action (SM a) (::: a' l) 
(Eq a, Eq l) => Eq (::: a l) 
(Ord a, Ord l) => Ord (::: a l) 
(Show a, Show l) => Show (::: a l) 
(Semigroup a, Semigroup tl, Monoid tl) => Monoid (::: a tl)

Heterogeneous monoidal lists are themselves instances of Monoid as long as all their elements are, where mappend is done elementwise.

(Semigroup a, Semigroup tl) => Semigroup (::: a tl) 
(Monoid a, ToTuple l) => ToTuple (::: a l) 
MList l => MList (::: a l) 
(Monoid a, Action (SM a) l2, Action l1 l2) => Action (::: a l1) l2 
:>: t a => (::: b t) :>: a 
(MList t, Monoid a) => (::: a t) :>: a 
Newtype (QDiagram b v m) (UDTree (UpAnnots v m) (DownAnnots v) (Prim b v)) 

class MList l whereSource

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

Methods

empty :: lSource

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 Nil 
MList l => MList (::: a l) 

Converting to tuples

type family Tuple l :: *Source

A type function to compute the tuple-based representation for instances of MList.

class ToTuple l whereSource

toTuple can be used to convert a heterogeneous list to its tuple-based representation.

Methods

toTuple :: l -> Tuple lSource

Instances

ToTuple Nil 
(Monoid a, ToTuple l) => ToTuple (::: a l) 

Accessing embedded values

class l :>: a whereSource

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 -> lSource

Inject a value into an otherwise empty heterogeneous list.

get :: l -> aSource

Get the value of type a from a heterogeneous list.

alt :: (a -> a) -> l -> lSource

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

Instances

:>: t a => (::: b t) :>: a 
(MList t, Monoid a) => (::: a t) :>: a 

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 Source

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

Monoid m => Monoid (SM m) 
Monoid a => Action (SM a) Nil 
(Action a a', Action (SM a) l) => Action (SM a) (::: a' l)