| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
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 is the wire Wire s, shown
with a superscript ⁻¹ and drawn as a hollow line. The arrows between a wire and its dual only
relabel.Co s
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
- data W
- type family DualW (w :: W) :: W where ...
- type family DualList (ws :: [W]) :: [W] where ...
- type family Erase (ws :: [W]) :: [Symbol] where ...
- class KnownWire (w :: W) where
- wireInfo :: (String, WireKind)
- withKnownDualW :: (KnownWire (DualW w) => r) -> r
- withIsListEraseCons :: forall (ws :: [W]) r. IsList (Erase ws) => (IsList (Erase (w ': ws)) => r) -> r
- 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
- withDualDualW :: (DualW (DualW w) ~ w => r) -> r
- withEraseDualCons :: forall (ws :: [W]) r. Erase (DualList ws) ~ Erase ws => (Erase (DualList (w ': ws)) ~ Erase (w ': ws) => r) -> r
- data WireId (a :: W) (b :: W) where
- withIsListDual :: forall (ws :: [W]) r. IsList ws => (IsList (DualList ws) => r) -> r
- withIsListErase :: forall (ws :: [W]) r. IsList ws => (IsList (Erase ws) => r) -> r
- withEraseAppend :: forall (as :: [W]) (bs :: [W]) r. IsList as => (Erase (as ++ bs) ~ (Erase as ++ Erase bs) => r) -> r
- withDualDual :: forall (ws :: [W]) r. IsList ws => (DualList (DualList ws) ~ ws => r) -> r
- withDualAppend :: forall (as :: [W]) (bs :: [W]) r. IsList as => (DualList (as ++ bs) ~ (DualList as ++ DualList bs) => r) -> r
- withEraseDual :: forall (ws :: [W]) r. IsList ws => (Erase (DualList ws) ~ Erase ws => r) -> r
- wires :: forall (ws :: [W]). IsList ws => [(String, WireKind)]
- wireKinds :: forall (ws :: [W]). IsList ws => [WireKind]
- data SVG = S [W]
- data Svg (a :: SVG) (b :: SVG) where
- 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)
- drawnAs :: forall (as :: [W]) (bs :: [W]). (IsList as, IsList bs, Erase as ~ Erase bs) => Diagram -> Svg ('S as) ('S bs)
- relabel :: forall (a :: SVG) (b :: SVG). (Ob a, Ob b, Erase (UN 'S a) ~ Erase (UN 'S b)) => a ~> b
- data Options = Options {}
- defaultOptions :: Options
- meaningOf :: forall (as :: [W]) (bs :: [W]). Svg ('S as) ('S bs) -> Dot ('D (Erase as)) ('D (Erase bs))
- withRightUnit :: forall (as :: [W]) r. IsList as => ((IsList (as ++ '['I]), Erase (as ++ '['I]) ~ Erase as) => r) -> r
- rebracketed :: forall (as :: [W]) (bs :: [W]) (cs :: [W]). (IsList as, IsList bs, IsList cs) => Grouping -> Svg ('S (as ++ (bs ++ cs))) ('S (as ++ (bs ++ cs)))
- dualCup :: forall (a :: SVG). Ob a => (Unit :: SVG) ~> (a ** Dual a)
- dualCap :: forall (a :: SVG). Ob a => (Dual a ** a) ~> (Unit :: SVG)
- dualCupS :: forall (a :: SVG). Ob a => ('[] :: [SVG]) ~> '[a, Dual a]
- dualCapS :: forall (a :: SVG). Ob a => '[Dual a, a] ~> ('[] :: [SVG])
- node :: forall (as :: [W]) (bs :: [W]). (IsList as, IsList bs) => String -> Svg ('S as) ('S bs)
- line :: forall (a :: Symbol). KnownSymbol a => Svg ('S '['Wire a]) ('S '['Wire a])
- swapNode :: forall (a :: Symbol) (b :: Symbol). (KnownSymbol a, KnownSymbol b) => Svg ('S '['Wire a, 'Wire b]) ('S '['Wire b, 'Wire a])
- unitAdj :: forall (l :: Symbol) (r :: Symbol). (KnownSymbol l, KnownSymbol r) => Svg ('S ('[] :: [W])) ('S '['Wire l, 'Wire r])
- counitAdj :: forall (l :: Symbol) (r :: Symbol). (KnownSymbol l, KnownSymbol r) => Svg ('S '['Wire r, 'Wire l]) ('S ('[] :: [W]))
- data WireKind
- data Diagram
- = Ident [WireKind]
- | Permute Bool [WireKind] [Int]
- | Straight [WireKind] [WireKind]
- | Node String [WireKind] [(String, WireKind)]
- | Points PointKind [WireKind]
- | Bend BendKind [WireKind] [WireKind]
- | Rebracket Grouping [WireKind] [WireKind] [WireKind]
- | Unitor Side Direction [WireKind]
- | UnitEnd
- | UnitStart
- | Seq Diagram Diagram
- | Beside Diagram Diagram
- | Trace [WireKind] Diagram
- data PointKind
- data BendKind
- data Grouping
- data Side
- data Direction
- hideUnits :: Diagram -> Diagram
- noUnits :: [WireKind] -> [WireKind]
- layout :: Options -> Diagram -> Layout
- visible :: Options -> [(String, WireKind)] -> [(String, WireKind)]
- type Pt = (Double, Double)
- data Path
- data Shape
- move :: Double -> Double -> Shape -> Shape
- data Port = Port {}
- port :: Double -> WireKind -> Port
- shiftPort :: Double -> Port -> Port
- data Geo = Geo {}
- data Layout
- slot :: Double
- stub :: Double
- boxHeight :: Double
- loopGap :: Double
- loopClearance :: Double
- textWidth :: String -> Double
- slots :: Int -> [Double]
- width :: Int -> Double
- ports :: [Double] -> [WireKind] -> [Port]
- wiringGeo :: Double -> [Int] -> [WireKind] -> [WireKind] -> Geo
- verticals :: Double -> [Double] -> [WireKind] -> [Shape]
- toGeo :: Double -> Layout -> Geo
- layoutHeight :: Layout -> Double
- stretch :: Double -> Geo -> Geo
- tensor :: Layout -> Layout -> Layout
- compose :: Layout -> Layout -> Layout
- inverse :: [Int] -> [Int]
- stack :: Geo -> Geo -> Geo
- untangle :: [Double] -> [Port] -> [Port]
- bandHeight :: Double -> Double
- nodeGeo :: [WireKind] -> [(String, WireKind)] -> String -> Geo
- points :: Bool -> PointKind -> [WireKind] -> Layout
- swapHeight :: Double
- permutation :: Bool -> [WireKind] -> [Int] -> Layout
- identity :: Bool -> [WireKind] -> Layout
- bend :: BendKind -> [WireKind] -> [WireKind] -> Layout
- rebracket :: Grouping -> [WireKind] -> [WireKind] -> [WireKind] -> Geo
- unitor :: Side -> Direction -> [WireKind] -> Geo
- unitEnd :: Geo
- mirror :: Geo -> Geo
- loops :: Int -> Geo -> Geo
- labelRow :: Double
- framed :: Double -> Double -> [(String, WireKind)] -> [(String, WireKind)] -> Geo -> Geo
- inOrder :: [Port] -> [Double]
- boundaryBands :: Geo -> (Double, Double)
- render :: forall (as :: [W]) (bs :: [W]). Svg ('S as) ('S bs) -> String
- renderWith :: forall (as :: [W]) (bs :: [W]). Options -> Svg ('S as) ('S bs) -> String
- renderEquation :: forall (as :: [W]) (bs :: [W]). Svg ('S as) ('S bs) -> Svg ('S as) ('S bs) -> String
- renderEquationWith :: forall (as :: [W]) (bs :: [W]). Options -> Svg ('S as) ('S bs) -> Svg ('S as) ('S bs) -> String
- sideBySide :: forall (as :: [W]) (bs :: [W]). (IsList as, IsList bs) => Options -> [Diagram] -> String
- lawSvgs :: forall (cs :: [Kind -> Constraint]). (Laws cs, All cs SVG) => [(String, String)]
- lawSvgsWith :: forall (cs :: [Kind -> Constraint]). (Laws cs, All cs SVG) => Options -> [(String, String)]
- document :: Geo -> String
- segment :: Path -> (Pt, Pt, String)
- joined :: [(Pt, Pt, String)] -> [String]
- path :: String -> String
- shape :: Shape -> String
- kappa :: Double
- bendRadius :: Double
- rounded :: NonEmpty Pt -> String
- pt :: Pt -> String
- num :: Double -> String
Wires
A wire: a labelled wire, the dual of one, or the unit wire.
Instances
| CategoryOf W Source Github # | The discrete category on wires, so that lists of wires are objects of | ||||||||
Defined in Proarrow.Tools.Diagrams.Svg Associated Types
| |||||||||
| Promonad WireId Source Github # | |||||||||
| Profunctor WireId Source Github # | |||||||||
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 # | |||||||||
Defined in Proarrow.Tools.Diagrams.Svg | |||||||||
| type Ob (w :: W) Source Github # | |||||||||
Defined in Proarrow.Tools.Diagrams.Svg | |||||||||
type family DualW (w :: W) :: W where ... Source Github #
The dual of a wire. The unit wire is its own dual.
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.
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
data WireId (a :: W) (b :: W) where Source Github #
Instances
| Promonad WireId Source Github # | |
| Profunctor WireId Source Github # | |
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.
The category
Instances
| Monoidal SVG Source Github # | The unit is the unit wire, and the unitors absorb or create it. | ||||||||
Defined in Proarrow.Tools.Diagrams.Svg Associated Types
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 # | |||||||||
| Closed SVG Source Github # | The exponential is the *-autonomous one, | ||||||||
Defined in Proarrow.Tools.Diagrams.Svg Associated Types
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 # | |||||||||
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 # | |||||||||
| Hypergraph SVG Source Github # | |||||||||
Defined in Proarrow.Tools.Diagrams.Svg | |||||||||
| StarAutonomous SVG Source Github # | The dual of a wire is its | ||||||||
Defined in Proarrow.Tools.Diagrams.Svg 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 | ||||||||
Defined in Proarrow.Tools.Diagrams.Svg | |||||||||
| Labelled SVG Source Github # | Derived operations are drawn as what they are made of. | ||||||||
| Promonad Svg Source Github # | |||||||||
| MonoidalProfunctor Svg Source Github # | |||||||||
| Profunctor Svg Source Github # | |||||||||
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. | ||||||||
| Ob as => Frobenius ('S as :: SVG) Source Github # | |||||||||
Defined in Proarrow.Tools.Diagrams.Svg | |||||||||
| Ob as => CocommutativeComonoid ('S as :: SVG) Source Github # | |||||||||
Defined in Proarrow.Tools.Diagrams.Svg | |||||||||
| Ob as => CommutativeMonoid ('S as :: SVG) Source Github # | |||||||||
Defined in Proarrow.Tools.Diagrams.Svg | |||||||||
| Ob as => Comonoid ('S as :: SVG) 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. | ||||||||
| type Unit Source Github # | |||||||||
Defined in Proarrow.Tools.Diagrams.Svg | |||||||||
| type (~>) Source Github # | |||||||||
Defined in Proarrow.Tools.Diagrams.Svg | |||||||||
| type Dual (a :: SVG) Source Github # | |||||||||
| type Ob (a :: SVG) Source Github # | |||||||||
| type (ls :: SVG) ** (rs :: SVG) Source Github # | |||||||||
| type (a :: SVG) ~~> (b :: SVG) Source Github # | |||||||||
Defined in Proarrow.Tools.Diagrams.Svg | |||||||||
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
| Promonad Svg Source Github # | |
| MonoidalProfunctor Svg Source Github # | |
| Profunctor Svg Source Github # | |
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. |
| Show (Svg a b) Source 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.
Choices about what to draw.
Constructors
| Options | |
Fields
| |
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 ϵ.
What kind of wire a wire is, which decides how it is drawn.
Diagrams
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 |
| 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 |
data PointKind Source Github #
The points a (co)monoid is drawn with.
Constructors
| UnitPoint | |
| DiscardPoint | |
| CopyPoint | |
| MergePoint |
Whether a bend opens downwards, a cup, or upwards, a cap.
Which pair an associator groups first: (a ⊗ b) ⊗ c or a ⊗ (b ⊗ c).
Constructors
| LeftFirst | |
| RightFirst |
Which side of the other wires a unit wire joins them.
data Direction Source Github #
Whether a unitor ends a unit wire on another wire, or starts one from it.
hideUnits :: Diagram -> Diagram Source Github #
The diagram with its unit wires left out, and its unitors and associators turned into wires carrying straight on.
visible :: Options -> [(String, WireKind)] -> [(String, WireKind)] Source Github #
The boundary wires that are drawn with the given options.
Layout
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 |
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 |
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.
A drawn diagram: its size, its input and output ports, and its shapes.
Constructors
| Geo | |
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.
loopClearance :: Double Source Github #
How far the innermost trace loop runs below and above the diagram it loops round, clear of the wire labels.
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.
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.
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
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 to Wire "a", and the arrows a law asks for are Wire "e"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.
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.