proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Tools.Diagrams.Svg

Description

String diagrams drawn as SVG. Svg is the category of diagrams of Proarrow.Tools.Diagrams.Dot, with the same meaning, but a diagram is laid out from how it is built instead of by Graphviz: a tensor puts its two sides next to each other, a composite stacks them with a band of curved wires in between, and a trace draws its loops around the side. Every coordinate is computed here, so every choice can be tweaked.

Unlike DOT, SVG is not strict about its unit: the unit is a wire of its own, I, so the unitors are arrows that can be drawn, a dotted wire ending on or leaving another wire. With explicitCoherence off, unit wires take up no room and are not drawn at all.

Nor is SVG self-dual on the nose: the dual of a wire Wire s is the wire Co s, shown with a superscript ⁻¹ and drawn as a hollow line. The arrows between a wire and its dual only relabel.

Both are only drawn: an arrow means the Dot diagram on the wires with the unit wires left out and the duals forgotten (Erase).

Synopsis

Wires

data W Source Github #

A wire: a labelled wire, the dual of one, or the unit wire.

Constructors

Wire Symbol 
Co Symbol 
I 

Instances

Instances details
CategoryOf W Source Github #

The discrete category on wires, so that lists of wires are objects of Strictified.

Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Associated Types

type (~>) 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type (~>) = WireId
type Ob (w :: W) 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type Ob (w :: W) = KnownWire w
Promonad WireId Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

id :: forall (a :: W). Ob a => WireId a a Source Github #

(.) :: forall (b :: W) (c :: W) (a :: W). WireId b c -> WireId a b -> WireId a c Source Github #

Profunctor WireId Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

dimap :: forall (c :: W) (a :: W) (b :: W) (d :: W). (c ~> a) -> (b ~> d) -> WireId a b -> WireId c d Source Github #

lmap :: forall (c :: W) (a :: W) (b :: W). (c ~> a) -> WireId a b -> WireId c b Source Github #

rmap :: forall (b :: W) (d :: W) (a :: W). (b ~> d) -> WireId a b -> WireId a d Source Github #

(\\) :: forall (a :: W) (b :: W) r. ((Ob a, Ob b) => r) -> WireId a b -> r Source Github #

type (~>) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type (~>) = WireId
type Ob (w :: W) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type Ob (w :: W) = KnownWire w

type family DualW (w :: W) :: W where ... Source Github #

The dual of a wire. The unit wire is its own dual.

Equations

DualW ('Wire s) = 'Co s 
DualW ('Co s) = 'Wire s 
DualW 'I = 'I 

type family DualList (ws :: [W]) :: [W] where ... Source Github #

The duals of the wires.

Equations

DualList ('[] :: [W]) = '[] :: [W] 
DualList (w ': ws) = DualW w ': DualList ws 

type family Erase (ws :: [W]) :: [Symbol] where ... Source Github #

The labels of the wires that carry something: the unit wires left out, and a dual wire labelled as the wire it is the dual of.

Equations

Erase ('[] :: [W]) = '[] :: [Symbol] 
Erase ('Wire s ': ws) = s ': Erase ws 
Erase ('Co s ': ws) = s ': Erase ws 
Erase ('I ': ws) = Erase ws 

class KnownWire (w :: W) where Source Github #

A wire whose label is known. The methods are facts about DualW and Erase that hold for each kind of wire, from which withIsListDual, withIsListErase, withEraseAppend, withDualDual and withEraseDual prove them for lists by induction.

Methods

wireInfo :: (String, WireKind) Source Github #

The label of the wire as it is shown, and its kind.

withKnownDualW :: (KnownWire (DualW w) => r) -> r Source Github #

withIsListEraseCons :: forall (ws :: [W]) r. IsList (Erase ws) => (IsList (Erase (w ': ws)) => r) -> r Source Github #

withEraseAppendCons :: forall (as :: [W]) (bs :: [W]) r. Erase (as ++ bs) ~ (Erase as ++ Erase bs) => (Erase (w ': (as ++ bs)) ~ (Erase (w ': as) ++ Erase bs) => r) -> r Source Github #

withDualDualW :: (DualW (DualW w) ~ w => r) -> r Source Github #

withEraseDualCons :: forall (ws :: [W]) r. Erase (DualList ws) ~ Erase ws => (Erase (DualList (w ': ws)) ~ Erase (w ': ws) => r) -> r Source Github #

Instances

Instances details
KnownWire 'I Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

wireInfo :: (String, WireKind) Source Github #

withKnownDualW :: (KnownWire (DualW 'I) => r) -> r Source Github #

withIsListEraseCons :: forall (ws :: [W]) r. IsList (Erase ws) => (IsList (Erase ('I ': ws)) => r) -> r Source Github #

withEraseAppendCons :: forall (as :: [W]) (bs :: [W]) r. Erase (as ++ bs) ~ (Erase as ++ Erase bs) => (Erase ('I ': (as ++ bs)) ~ (Erase ('I ': as) ++ Erase bs) => r) -> r Source Github #

withDualDualW :: (DualW (DualW 'I) ~ 'I => r) -> r Source Github #

withEraseDualCons :: forall (ws :: [W]) r. Erase (DualList ws) ~ Erase ws => (Erase (DualList ('I ': ws)) ~ Erase ('I ': ws) => r) -> r Source Github #

KnownSymbol s => KnownWire ('Co s) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

wireInfo :: (String, WireKind) Source Github #

withKnownDualW :: (KnownWire (DualW ('Co s)) => r) -> r Source Github #

withIsListEraseCons :: forall (ws :: [W]) r. IsList (Erase ws) => (IsList (Erase ('Co s ': ws)) => r) -> r Source Github #

withEraseAppendCons :: forall (as :: [W]) (bs :: [W]) r. Erase (as ++ bs) ~ (Erase as ++ Erase bs) => (Erase ('Co s ': (as ++ bs)) ~ (Erase ('Co s ': as) ++ Erase bs) => r) -> r Source Github #

withDualDualW :: (DualW (DualW ('Co s)) ~ 'Co s => r) -> r Source Github #

withEraseDualCons :: forall (ws :: [W]) r. Erase (DualList ws) ~ Erase ws => (Erase (DualList ('Co s ': ws)) ~ Erase ('Co s ': ws) => r) -> r Source Github #

KnownSymbol s => KnownWire ('Wire s) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

wireInfo :: (String, WireKind) Source Github #

withKnownDualW :: (KnownWire (DualW ('Wire s)) => r) -> r Source Github #

withIsListEraseCons :: forall (ws :: [W]) r. IsList (Erase ws) => (IsList (Erase ('Wire s ': ws)) => r) -> r Source Github #

withEraseAppendCons :: forall (as :: [W]) (bs :: [W]) r. Erase (as ++ bs) ~ (Erase as ++ Erase bs) => (Erase ('Wire s ': (as ++ bs)) ~ (Erase ('Wire s ': as) ++ Erase bs) => r) -> r Source Github #

withDualDualW :: (DualW (DualW ('Wire s)) ~ 'Wire s => r) -> r Source Github #

withEraseDualCons :: forall (ws :: [W]) r. Erase (DualList ws) ~ Erase ws => (Erase (DualList ('Wire s ': ws)) ~ Erase ('Wire s ': ws) => r) -> r Source Github #

data WireId (a :: W) (b :: W) where Source Github #

Constructors

WireId :: forall (a :: W). KnownWire a => WireId a a 

Instances

Instances details
Promonad WireId Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

id :: forall (a :: W). Ob a => WireId a a Source Github #

(.) :: forall (b :: W) (c :: W) (a :: W). WireId b c -> WireId a b -> WireId a c Source Github #

Profunctor WireId Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

dimap :: forall (c :: W) (a :: W) (b :: W) (d :: W). (c ~> a) -> (b ~> d) -> WireId a b -> WireId c d Source Github #

lmap :: forall (c :: W) (a :: W) (b :: W). (c ~> a) -> WireId a b -> WireId c b Source Github #

rmap :: forall (b :: W) (d :: W) (a :: W). (b ~> d) -> WireId a b -> WireId a d Source Github #

(\\) :: forall (a :: W) (b :: W) r. ((Ob a, Ob b) => r) -> WireId a b -> r Source Github #

withIsListDual :: forall (ws :: [W]) r. IsList ws => (IsList (DualList ws) => r) -> r Source Github #

The duals of a list of wires are a list of wires.

withIsListErase :: forall (ws :: [W]) r. IsList ws => (IsList (Erase ws) => r) -> r Source Github #

The erased wires of a list of wires are a list of labels.

withEraseAppend :: forall (as :: [W]) (bs :: [W]) r. IsList as => (Erase (as ++ bs) ~ (Erase as ++ Erase bs) => r) -> r Source Github #

Erasing commutes with appending.

withDualDual :: forall (ws :: [W]) r. IsList ws => (DualList (DualList ws) ~ ws => r) -> r Source Github #

Dualising twice gives the wires back.

withDualAppend :: forall (as :: [W]) (bs :: [W]) r. IsList as => (DualList (as ++ bs) ~ (DualList as ++ DualList bs) => r) -> r Source Github #

Dualising commutes with appending.

withEraseDual :: forall (ws :: [W]) r. IsList ws => (Erase (DualList ws) ~ Erase ws => r) -> r Source Github #

The duals of wires erase to the same labels as the wires.

wires :: forall (ws :: [W]). IsList ws => [(String, WireKind)] Source Github #

The labels of the wires of ws as they are shown, and their kinds.

wireKinds :: forall (ws :: [W]). IsList ws => [WireKind] Source Github #

The category

data SVG Source Github #

Constructors

S [W] 

Instances

Instances details
Monoidal SVG Source Github #

The unit is the unit wire, and the unitors absorb or create it.

Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Associated Types

type Unit 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type Unit = 'S '['I]
type (ls :: SVG) ** (rs :: SVG) 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type (ls :: SVG) ** (rs :: SVG) = 'S (UN 'S ls ++ UN 'S rs)

Methods

withOb2 :: forall (a :: SVG) (b :: SVG) r. (Ob a, Ob b) => (Ob (a ** b) => r) -> r Source Github #

leftUnitor :: forall (a :: SVG). Ob a => ((Unit :: SVG) ** a) ~> a Source Github #

leftUnitorInv :: forall (a :: SVG). Ob a => a ~> ((Unit :: SVG) ** a) Source Github #

rightUnitor :: forall (a :: SVG). Ob a => (a ** (Unit :: SVG)) ~> a Source Github #

rightUnitorInv :: forall (a :: SVG). Ob a => a ~> (a ** (Unit :: SVG)) Source Github #

associator :: forall (a :: SVG) (b :: SVG) (c :: SVG). (Ob a, Ob b, Ob c) => ((a ** b) ** c) ~> (a ** (b ** c)) Source Github #

associatorInv :: forall (a :: SVG) (b :: SVG) (c :: SVG). (Ob a, Ob b, Ob c) => (a ** (b ** c)) ~> ((a ** b) ** c) Source Github #

SymMonoidal SVG Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

swap :: forall (a :: SVG) (b :: SVG). (Ob a, Ob b) => (a ** b) ~> (b ** a) Source Github #

Closed SVG Source Github #

The exponential is the *-autonomous one, Dual (a ** Dual b), so curried wires show as duals.

Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Associated Types

type (a :: SVG) ~~> (b :: SVG) 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type (a :: SVG) ~~> (b :: SVG) = ExpSA a b

Methods

withObExp :: forall (a :: SVG) (b :: SVG) r. (Ob a, Ob b) => (Ob (a ~~> b) => r) -> r Source Github #

curry :: forall (a :: SVG) (b :: SVG) (c :: SVG). (Ob a, Ob b) => ((a ** b) ~> c) -> a ~> (b ~~> c) Source Github #

apply :: forall (a :: SVG) (b :: SVG). (Ob a, Ob b) => ((a ~~> b) ** a) ~> b Source Github #

(^^^) :: forall (a :: SVG) (b :: SVG) (x :: SVG) (y :: SVG). (b ~> y) -> (x ~> a) -> (a ~~> b) ~> (x ~~> y) Source Github #

CompactClosed SVG Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

distribDual :: forall (a :: SVG) (b :: SVG). (Ob a, Ob b) => Dual (a ** b) ~> (Dual a ** Dual b) Source Github #

dualUnit :: Dual (Unit :: SVG) ~> (Unit :: SVG) Source Github #

dualityUnit :: forall (a :: SVG). Ob a => (Unit :: SVG) ~> (a ** Dual a) Source Github #

dualityCounit :: forall (a :: SVG). Ob a => (Dual a ** a) ~> (Unit :: SVG) Source Github #

CopyDiscard SVG Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

copy :: forall (a :: SVG). Ob a => a ~> (a ** a) Source Github #

discard :: forall (a :: SVG). Ob a => a ~> (Unit :: SVG) Source Github #

Hypergraph SVG Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

StarAutonomous SVG Source Github #

The dual of a wire is its Co wire. Duals come from dualCup and dualCap, which mean a cup or cap and are drawn as a bend, so a dual wire is drawn hollow wherever it runs.

Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Associated Types

type Dual (a :: SVG) 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type Dual (a :: SVG) = 'S (DualList (UN 'S a))

Methods

withObDual :: forall (a :: SVG) r. Ob a => (Ob (Dual a) => r) -> r Source Github #

dual :: forall (a :: SVG) (b :: SVG). (a ~> b) -> Dual b ~> Dual a Source Github #

dualInv :: forall (a :: SVG) (b :: SVG). (Ob a, Ob b) => (Dual a ~> Dual b) -> b ~> a Source Github #

linDist :: forall (a :: SVG) (b :: SVG) (c :: SVG). (Ob a, Ob b, Ob c) => ((a ** b) ~> Dual c) -> a ~> Dual (b ** c) Source Github #

linDistInv :: forall (a :: SVG) (b :: SVG) (c :: SVG). (Ob a, Ob b, Ob c) => (a ~> Dual (b ** c)) -> (a ** b) ~> Dual c Source Github #

doubleNeg :: forall (a :: SVG). Ob a => Dual (Dual a) ~> a Source Github #

doubleNegInv :: forall (a :: SVG). Ob a => a ~> Dual (Dual a) Source Github #

CategoryOf SVG Source Github #

The category string diagrams are drawn in: an object S ws is the list of wires along a boundary.

Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Associated Types

type (~>) 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type (~>) = Svg
type Ob (a :: SVG) 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type Ob (a :: SVG) = (Is 'S a, IsList (UN 'S a))
Labelled SVG Source Github #

Derived operations are drawn as what they are made of.

Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

label :: forall (a :: SVG) (b :: SVG). String -> (a ~> b) -> a ~> b Source Github #

Promonad Svg Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

id :: forall (a :: SVG). Ob a => Svg a a Source Github #

(.) :: forall (b :: SVG) (c :: SVG) (a :: SVG). Svg b c -> Svg a b -> Svg a c Source Github #

MonoidalProfunctor Svg Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

one :: Svg (Unit :: SVG) (Unit :: SVG) Source Github #

(**) :: forall (x1 :: SVG) (x2 :: SVG) (y1 :: SVG) (y2 :: SVG). Svg x1 x2 -> Svg y1 y2 -> Svg (x1 ** y1) (x2 ** y2) Source Github #

Profunctor Svg Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

dimap :: forall (c :: SVG) (a :: SVG) (b :: SVG) (d :: SVG). (c ~> a) -> (b ~> d) -> Svg a b -> Svg c d Source Github #

lmap :: forall (c :: SVG) (a :: SVG) (b :: SVG). (c ~> a) -> Svg a b -> Svg c b Source Github #

rmap :: forall (b :: SVG) (d :: SVG) (a :: SVG). (b ~> d) -> Svg a b -> Svg a d Source Github #

(\\) :: forall (a :: SVG) (b :: SVG) r. ((Ob a, Ob b) => r) -> Svg a b -> r Source Github #

Costrong (Tensor :: SVG -> (SVG, SVG) -> Type) Svg Source Github #

The traced wires loop round the side of the diagram they are nearest to.

Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

coact :: forall (a :: SVG) (x :: SVG) (y :: SVG). (Ob a, Ob x, Ob y) => Svg (Act (Tensor :: SVG -> (SVG, SVG) -> Type) a x) (Act (Tensor :: SVG -> (SVG, SVG) -> Type) a y) -> Svg x y Source Github #

Ob as => Frobenius ('S as :: SVG) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Ob as => CocommutativeComonoid ('S as :: SVG) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Ob as => CommutativeMonoid ('S as :: SVG) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Ob as => Comonoid ('S as :: SVG) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

counit :: 'S as ~> (Unit :: SVG) Source Github #

comult :: 'S as ~> ('S as ** 'S as) Source Github #

Ob as => Monoid ('S as :: SVG) Source Github #

The unit point takes the unit wire in, and the discard point gives it out.

Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

mempty :: (Unit :: SVG) ~> 'S as Source Github #

mappend :: ('S as ** 'S as) ~> 'S as Source Github #

type Unit Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type Unit = 'S '['I]
type (~>) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type (~>) = Svg
type Dual (a :: SVG) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type Dual (a :: SVG) = 'S (DualList (UN 'S a))
type Ob (a :: SVG) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type Ob (a :: SVG) = (Is 'S a, IsList (UN 'S a))
type (ls :: SVG) ** (rs :: SVG) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type (ls :: SVG) ** (rs :: SVG) = 'S (UN 'S ls ++ UN 'S rs)
type (a :: SVG) ~~> (b :: SVG) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

type (a :: SVG) ~~> (b :: SVG) = ExpSA a b

data Svg (a :: SVG) (b :: SVG) where Source Github #

A diagram: its meaning, as a Dot diagram on the erased wires, and how it was built, which is drawn when it is rendered.

Constructors

Svg :: forall (as :: [W]) (bs :: [W]). (IsList as, IsList bs) => Dot ('D (Erase as)) ('D (Erase bs)) -> Diagram -> Svg ('S as) ('S bs) 

Instances

Instances details
Promonad Svg Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

id :: forall (a :: SVG). Ob a => Svg a a Source Github #

(.) :: forall (b :: SVG) (c :: SVG) (a :: SVG). Svg b c -> Svg a b -> Svg a c Source Github #

MonoidalProfunctor Svg Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

one :: Svg (Unit :: SVG) (Unit :: SVG) Source Github #

(**) :: forall (x1 :: SVG) (x2 :: SVG) (y1 :: SVG) (y2 :: SVG). Svg x1 x2 -> Svg y1 y2 -> Svg (x1 ** y1) (x2 ** y2) Source Github #

Profunctor Svg Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

dimap :: forall (c :: SVG) (a :: SVG) (b :: SVG) (d :: SVG). (c ~> a) -> (b ~> d) -> Svg a b -> Svg c d Source Github #

lmap :: forall (c :: SVG) (a :: SVG) (b :: SVG). (c ~> a) -> Svg a b -> Svg c b Source Github #

rmap :: forall (b :: SVG) (d :: SVG) (a :: SVG). (b ~> d) -> Svg a b -> Svg a d Source Github #

(\\) :: forall (a :: SVG) (b :: SVG) r. ((Ob a, Ob b) => r) -> Svg a b -> r Source Github #

Costrong (Tensor :: SVG -> (SVG, SVG) -> Type) Svg Source Github #

The traced wires loop round the side of the diagram they are nearest to.

Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

coact :: forall (a :: SVG) (x :: SVG) (y :: SVG). (Ob a, Ob x, Ob y) => Svg (Act (Tensor :: SVG -> (SVG, SVG) -> Type) a x) (Act (Tensor :: SVG -> (SVG, SVG) -> Type) a y) -> Svg x y Source Github #

Show (Svg a b) Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Methods

showsPrec :: Int -> Svg a b -> ShowS Github #

show :: Svg a b -> String Github #

showList :: [Svg a b] -> ShowS Github #

svg :: forall (as :: [W]) (bs :: [W]). (IsList as, IsList bs) => ((IsList (Erase as), IsList (Erase bs)) => Dot ('D (Erase as)) ('D (Erase bs))) -> Diagram -> Svg ('S as) ('S bs) Source Github #

A diagram from its meaning, which may use that the erased wires are lists, and how it is drawn.

drawnAs :: forall (as :: [W]) (bs :: [W]). (IsList as, IsList bs, Erase as ~ Erase bs) => Diagram -> Svg ('S as) ('S bs) Source Github #

A diagram that means the identity on the erased wires, drawn as given.

relabel :: forall (a :: SVG) (b :: SVG). (Ob a, Ob b, Erase (UN 'S a) ~ Erase (UN 'S b)) => a ~> b Source Github #

An arrow between wires that erase to the same labels, a wire and its dual for example: in meaning the identity. It is drawn as nothing, the wires carrying on in the style of their new kinds.

data Options Source Github #

Choices about what to draw.

Constructors

Options 

Fields

  • explicitIdentities :: Bool

    draw each identity, line included, as a wire in a dashed frame; otherwise an identity is not drawn at all

  • explicitCoherence :: Bool

    draw the unit wires dotted, the unitors as a unit wire running into another wire or out of it, and the associators with brackets for the groupings they go between; otherwise none of these are drawn, and unit wires take up no room

  • explicitSwaps :: Bool

    draw each swap as a crossing of its own; otherwise its crossing is drawn in the band where the wires next change position

  • fixedSpiders :: Bool

    keep the two legs of a copy or merge point in the order they are listed; otherwise they may trade places to avoid a crossing, which the points being commutative allows

Instances

Instances details
Show Options Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

defaultOptions :: Options Source Github #

Nothing drawn that the meaning does not need, legs in order.

meaningOf :: forall (as :: [W]) (bs :: [W]). Svg ('S as) ('S bs) -> Dot ('D (Erase as)) ('D (Erase bs)) Source Github #

The meaning of a diagram, forgetting how it is drawn.

withRightUnit :: forall (as :: [W]) r. IsList as => ((IsList (as ++ '['I]), Erase (as ++ '['I]) ~ Erase as) => r) -> r Source Github #

Wires with a unit wire on the right are a list, and erase to the same labels.

rebracketed :: forall (as :: [W]) (bs :: [W]) (cs :: [W]). (IsList as, IsList bs, IsList cs) => Grouping -> Svg ('S (as ++ (bs ++ cs))) ('S (as ++ (bs ++ cs))) Source Github #

An associator, from the given grouping to the other one.

dualCup :: forall (a :: SVG). Ob a => (Unit :: SVG) ~> (a ** Dual a) Source Github #

A wire bent upwards, a on the left and its dual on the right. It means cup, and is drawn as one bend that turns into the dual at its apex.

dualCap :: forall (a :: SVG). Ob a => (Dual a ** a) ~> (Unit :: SVG) Source Github #

A wire bent downwards, the dual of a on the left and a on the right. It means cap, and is drawn as one bend that turns into the dual at its apex.

dualCupS :: forall (a :: SVG). Ob a => ('[] :: [SVG]) ~> '[a, Dual a] Source Github #

dualCup as a strictified arrow. The *-autonomous structure is built from it, not from the compact closed dualityUnit, so that the laws relating the two compare different definitions.

dualCapS :: forall (a :: SVG). Ob a => '[Dual a, a] ~> ('[] :: [SVG]) Source Github #

dualCap as a strictified arrow.

Building diagrams

node :: forall (as :: [W]) (bs :: [W]). (IsList as, IsList bs) => String -> Svg ('S as) ('S bs) Source Github #

A box with the given name, its inputs along the top and its outputs along the bottom, each output labelled with its wire.

line :: forall (a :: Symbol). KnownSymbol a => Svg ('S '['Wire a]) ('S '['Wire a]) Source Github #

A wire, the identity on it.

swapNode :: forall (a :: Symbol) (b :: Symbol). (KnownSymbol a, KnownSymbol b) => Svg ('S '['Wire a, 'Wire b]) ('S '['Wire b, 'Wire a]) Source Github #

A crossing of fixed height. A plain swap is drawn as a crossing too, but in the band where the wires next change position.

unitAdj :: forall (l :: Symbol) (r :: Symbol). (KnownSymbol l, KnownSymbol r) => Svg ('S ('[] :: [W])) ('S '['Wire l, 'Wire r]) Source Github #

The unit of an adjunction, drawn as a box named η.

counitAdj :: forall (l :: Symbol) (r :: Symbol). (KnownSymbol l, KnownSymbol r) => Svg ('S '['Wire r, 'Wire l]) ('S ('[] :: [W])) Source Github #

The counit of an adjunction, drawn as a box named ϵ.

data WireKind Source Github #

What kind of wire a wire is, which decides how it is drawn.

Constructors

Plain 
UnitWire 
DualWire 

Instances

Instances details
Show WireKind Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Eq WireKind Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

Diagrams

data Diagram Source Github #

How a diagram was built. The options come in only when it is drawn: hideUnits takes out what explicitCoherence would show, and layout decides the rest.

Constructors

Ident [WireKind]

the identity on wires of the given kinds

Permute Bool [WireKind] [Int]

wires of the given kinds, output j continuing input p !! j; when the flag is set, its crossings are drawn on their own

Straight [WireKind] [WireKind]

wires carrying straight on, as many out as in, possibly of other kinds

Node String [WireKind] [(String, WireKind)]

a box with a name, the kinds of its inputs, and the labels and kinds of its outputs

Points PointKind [WireKind]

a point of the given kind on each wire

Bend BendKind [WireKind] [WireKind]

bends joining each wire of the first kinds to its dual, of the second kinds

Rebracket Grouping [WireKind] [WireKind] [WireKind]

an associator from the given grouping, on three lists of wires

Unitor Side Direction [WireKind]

a unitor on wires of the given kinds

UnitEnd

a unit wire ending

UnitStart

a unit wire starting

Seq Diagram Diagram

the first diagram above the second

Beside Diagram Diagram

two diagrams side by side

Trace [WireKind] Diagram

the first inputs and outputs, of the given kinds, fed back

Instances

Instances details
Show Diagram Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

data PointKind Source Github #

The points a (co)monoid is drawn with.

Instances

Instances details
Show PointKind Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

data BendKind Source Github #

Whether a bend opens downwards, a cup, or upwards, a cap.

Constructors

Cup 
Cap 

Instances

Instances details
Show BendKind Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

data Grouping Source Github #

Which pair an associator groups first: (a ⊗ b) ⊗ c or a ⊗ (b ⊗ c).

Constructors

LeftFirst 
RightFirst 

Instances

Instances details
Show Grouping Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

data Side Source Github #

Which side of the other wires a unit wire joins them.

Constructors

OnLeft 
OnRight 

Instances

Instances details
Show Side Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

data Direction Source Github #

Whether a unitor ends a unit wire on another wire, or starts one from it.

Constructors

Absorb 
Create 

Instances

Instances details
Show Direction Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

hideUnits :: Diagram -> Diagram Source Github #

The diagram with its unit wires left out, and its unitors and associators turned into wires carrying straight on.

layout :: Options -> Diagram -> Layout Source Github #

The diagram laid out with the given options.

visible :: Options -> [(String, WireKind)] -> [(String, WireKind)] Source Github #

The boundary wires that are drawn with the given options.

Layout

type Pt = (Double, Double) Source Github #

A point in the plane, y growing downwards.

data Path Source Github #

The course of a piece of wire.

Constructors

Line Pt Pt

straight from one point to another

Curve Pt Pt

from one point down to another, leaving and arriving vertically

Loop (NonEmpty Pt)

along the given corners, rounded

Quarter Pt Pt

a quarter of an ellipse, leaving the first point vertically and reaching the second horizontally: half of a bend

Instances

Instances details
Show Path Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

data Shape Source Github #

What a diagram is drawn with.

Constructors

Piece WireKind Path

a piece of wire of the given kind: plain, dotted for a unit wire, hollow for a dual one

Box Pt Pt String

a box between two corners, with a name

Frame Pt Pt

the dashed frame of an identity, between two corners

Bracket Pt Pt Bool

a bracket grouping wires, from one point to another, its ends pointing down or up

Point Pt Bool

a point on a wire, filled for a comonoid and hollow for a monoid

Label Pt String

the label of the wire leaving a box

Boundary Pt String

the label of a boundary wire, centred

Equals Pt

the equals sign of an equation

Instances

Instances details
Show Shape Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

move :: Double -> Double -> Shape -> Shape Source Github #

A shape moved right by dx and down by dy.

data Port Source Github #

Where a wire enters a drawing along its top or leaves it along its bottom: how far along, the kind of wire, and, for a leg of a copy or merge point that may trade places with the point's other leg, which point it is a leg of.

Constructors

Port 

Instances

Instances details
Show Port Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

shiftPort :: Double -> Port -> Port Source Github #

A port moved right by dx.

data Geo Source Github #

A drawn diagram: its size, its input and output ports, and its shapes.

Constructors

Geo 

Instances

Instances details
Show Geo Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

data Layout Source Github #

How a diagram is drawn. A diagram that only permutes its wires has no height of its own: its crossings are drawn in the band where the wires next change position, so that a swap next to a box does not make the box taller.

Constructors

Wiring [Int] [WireKind] [WireKind]

output j continues input p !! j, with the kinds of the inputs and of the outputs

Stage Geo 

Instances

Instances details
Show Layout Source Github # 
Instance details

Defined in Proarrow.Tools.Diagrams.Svg

slot :: Double Source Github #

The distance between neighbouring wires.

stub :: Double Source Github #

The length of wire above and below a box.

boxHeight :: Double Source Github #

The height of a box.

loopGap :: Double Source Github #

The distance between the rails of neighbouring trace loops.

loopClearance :: Double Source Github #

How far the innermost trace loop runs below and above the diagram it loops round, clear of the wire labels.

textWidth :: String -> Double Source Github #

The width of a name, roughly, in the box font.

slots :: Int -> [Double] Source Github #

The positions of n wires, one slot apart.

ports :: [Double] -> [WireKind] -> [Port] Source Github #

Ports at the given positions, for wires of the given kinds.

wiringGeo :: Double -> [Int] -> [WireKind] -> [WireKind] -> Geo Source Github #

A permutation of wires of the given kinds, drawn over the given height.

verticals :: Double -> [Double] -> [WireKind] -> [Shape] Source Github #

Straight wires of the given kinds at the given positions, from the top down to h.

toGeo :: Double -> Layout -> Geo Source Github #

A layout as geometry, a permutation drawn over the given height.

stretch :: Double -> Geo -> Geo Source Github #

Geometry made taller, centred, with its wires extended to the new top and bottom.

tensor :: Layout -> Layout -> Layout Source Github #

Two layouts side by side, as tall as the taller one.

compose :: Layout -> Layout -> Layout Source Github #

The layout of after . before. A permutation is absorbed into the layout next to it, so its crossings end up in the next band.

stack :: Geo -> Geo -> Geo Source Github #

before above after, with a band of wires between them. The two are placed so that the wires between them move sideways as little as possible.

untangle :: [Double] -> [Port] -> [Port] Source Github #

Ports with the legs of each point that may trade places reordered, so that they run to their targets without crossing each other.

bandHeight :: Double -> Double Source Github #

The height of a band whose wires move sideways by at most d.

nodeGeo :: [WireKind] -> [(String, WireKind)] -> String -> Geo Source Github #

A box with inputs of the given kinds, and outputs with the given labels and kinds. Unit wires get no label.

points :: Bool -> PointKind -> [WireKind] -> Layout Source Github #

The points of a (co)monoid, one on each wire of the given kinds; nothing drawn when there are no wires. The legs of copy and merge points may trade places when free.

swapHeight :: Double Source Github #

The height of a swap drawn on its own.

permutation :: Bool -> [WireKind] -> [Int] -> Layout Source Github #

A permutation of wires of the given kinds, drawn on its own when explicit.

identity :: Bool -> [WireKind] -> Layout Source Github #

The identity on wires of the given kinds, drawn in a dashed frame when explicit.

bend :: BendKind -> [WireKind] -> [WireKind] -> Layout Source Github #

Bends joining each wire of the given kinds to its dual: for a Cup the wires and then their duals leave along the bottom, for a Cap the duals and then the wires enter along the top. Each bend changes style at its apex.

rebracket :: Grouping -> [WireKind] -> [WireKind] -> [WireKind] -> Geo Source Github #

An associator from the grouping given to the other one, on wires of the given kinds: the wires with a bracket over the pair grouped at the top and one under the pair grouped at the bottom.

unitor :: Side -> Direction -> [WireKind] -> Geo Source Github #

A unitor on wires of the given kinds: a dotted unit wire that runs into the outermost wire on its side or out of it.

unitEnd :: Geo Source Github #

The end of a unit wire.

mirror :: Geo -> Geo Source Github #

Geometry upside down: its inputs become its outputs and the other way round, so that a merge point becomes a copy point, a cup a cap, and so on. A point is filled when it was hollow and hollow when it was filled, as the points of a comonoid are the mirror images of a monoid's. A piece of wire still runs from top to bottom, except a bend's, which runs towards its apex.

loops :: Int -> Geo -> Geo Source Github #

The first k wires fed back from the outputs to the inputs, each looping round the side where it crosses fewer other wires. The loops on one side are nested: the one whose ends are nearest that side runs innermost.

Rendering

labelRow :: Double Source Github #

The height of the row of boundary labels.

framed :: Double -> Double -> [(String, WireKind)] -> [(String, WireKind)] -> Geo -> Geo Source Github #

Geometry with its boundary: the input labels above and the output labels below, each joined to its wire by a band top and bottom tall. Legs that may trade places are put in the boundary's order.

inOrder :: [Port] -> [Double] Source Github #

The positions of ports, the legs of each point that may trade places put in the order of the wires.

boundaryBands :: Geo -> (Double, Double) Source Github #

The height of the bands joining the boundary to the wires.

render :: forall (as :: [W]) (bs :: [W]). Svg ('S as) ('S bs) -> String Source Github #

The diagram as an SVG document, with the defaultOptions.

renderWith :: forall (as :: [W]) (bs :: [W]). Options -> Svg ('S as) ('S bs) -> String Source Github #

The diagram as an SVG document.

renderEquation :: forall (as :: [W]) (bs :: [W]). Svg ('S as) ('S bs) -> Svg ('S as) ('S bs) -> String Source Github #

Two parallel diagrams side by side, with an equals sign between them, with the defaultOptions.

renderEquationWith :: forall (as :: [W]) (bs :: [W]). Options -> Svg ('S as) ('S bs) -> Svg ('S as) ('S bs) -> String Source Github #

Two parallel diagrams side by side, with an equals sign between them. Neither is simplified: the picture shows two different diagrams that mean the same.

sideBySide :: forall (as :: [W]) (bs :: [W]). (IsList as, IsList bs) => Options -> [Diagram] -> String Source Github #

Diagrams from the wires as to the wires bs as one SVG document: side by side, each with the boundary labels, stretched to the height of the tallest, and with an equals sign between each and the next.

lawSvgs :: forall (cs :: [Kind -> Constraint]). (Laws cs, All cs SVG) => [(String, String)] Source Github #

The laws of cs drawn with the defaultOptions, see lawSvgsWith.

lawSvgsWith :: forall (cs :: [Kind -> Constraint]). (Laws cs, All cs SVG) => Options -> [(String, String)] Source Github #

The laws of cs, each drawn as an equation by renderEquationWith, with its name. The object variables are single wires Wire "a" to Wire "e", and the arrows a law asks for are nodes with the names it gives them.

document :: Geo -> String Source Github #

An SVG document showing the geometry. Wires, outlines and text use the current colour. Boxes are not filled, and the wires stop at the edge of a hollow point, so the background shows through both. Only the core of a dual wire is painted, in --sd-paper (white when it is not set), which a page can set to its background.

segment :: Path -> (Pt, Pt, String) Source Github #

Where a piece of wire starts and ends, and the SVG path from its start.

joined :: [(Pt, Pt, String)] -> [String] Source Github #

Pieces of wire joined where one ends where the next starts, each chain as one path. A chain starts at a piece that no other piece leads into.

shape :: Shape -> String Source Github #

One shape as SVG.

kappa :: Double Source Github #

How far along its tangent a cubic curve's control point lies, as a fraction of the radius, for the curve to be a quarter circle.

bendRadius :: Double Source Github #

The radius of a bend, and of the corners of a trace loop, so that a small loop is a cup and a cap joined by straight wire.

rounded :: NonEmpty Pt -> String Source Github #

A path from the first of the given corners along the rest, each corner rounded with a quarter circle of radius bendRadius, or less where the wire on either side of it is too short. A stretch of wire between two corners is shared between them; one at either end belongs to its corner alone.