Arrow Typeclass Hierarchy¶
Category_, Arrow, ArrowChoice, ArrowApply, ArrowLoop, ArrowZero, ArrowPlus, the Hughes-style arrow tower.
typeclasses
¶
Hughes-style arrow typeclass interfaces.
Each abstract typeclass declares the operations an arrow instance
must provide. Concrete instances (Function, VRel,
Stochastic, Kleisli(M), Cokleisli(W), LinearMap) live
in quivers.arrows.instances.
References
- Hughes, J. (2000). Generalising Monads to Arrows. Science of Computer Programming, 37(1–3), 67–111. doi:10.1016/S0167-6423(99)00023-4
Category_
¶
Bases: ABC
A category of computations.
Provides identity at every object plus binary composition. The
underscore disambiguates from quivers.dsl.ast_nodes.CategoryDecl
and quivers.stochastic.categories.Category which use the same
word in different senses.
Laws:
compose(id, f) = f(left identity)compose(f, id) = f(right identity)compose(compose(f, g), h) = compose(f, compose(g, h))(associativity)
id_arr
abstractmethod
¶
id_A : A ⇝ A.
Source code in src/quivers/arrows/typeclasses.py
38 39 40 | |
Arrow
¶
Bases: Category_, ABC
An arrow: Category_ with arr and first.
Adds:
arr— lift a pure morphism into the arrow.first— apply on the left of a pair, threading a context.
Defaults derivable from these and compose:
second f = swap >>> first f >>> swap;
f *** g = first f >>> second g (the parallel-product combinator);
f &&& g = arr (\x. (x, x)) >>> (f *** g).
Hughes 2000 §3 lists the seven arrow laws.
arr
abstractmethod
¶
Lift a pure morphism: arr(f) : A ⇝ B from f : A → B.
Source code in src/quivers/arrows/typeclasses.py
63 64 65 | |
ArrowChoice
¶
Bases: Arrow, ABC
An arrow with sum-elimination: left and (derivably) right.
Adds:
left_arr— apply on the left of a coproduct.
Derived: right_arr, +++, |||.
left_arr
abstractmethod
¶
f : A ⇝ B ⊢ left(f, C) : (A + C) ⇝ (B + C).
Source code in src/quivers/arrows/typeclasses.py
82 83 84 | |
ArrowApply
¶
Bases: Arrow, ABC
An arrow that can apply arrow-valued data: app.
ArrowApply instances are equivalent in expressive power to
quivers.monadic.typeclasses.Monad; the bridges in
quivers.monadic.bridges realise the conversion in both
directions.
app
abstractmethod
¶
app : Hom(A, B) ⊗ A ⇝ B.
Hom(A, B) is the internal hom of the arrow's underlying
symmetric monoidal closed structure.
Source code in src/quivers/arrows/typeclasses.py
96 97 98 99 100 101 102 | |
ArrowLoop
¶
Bases: Arrow, ABC
An arrow with feedback: loop.
Encodes traced symmetric monoidal structure on the arrow category.
For an arrow f : (A ⊗ C) ⇝ (B ⊗ C), loop(f) : A ⇝ B
closes the loop on C. In Function, this is the
least-fixed-point operator; in VRel, it is the iterative
trace; in Stochastic and Kern, it is the
cartesian / sampled trace.
The chart-fold parser combinator of
quivers.dsl.ast_nodes.ExprChartFold is denotationally
an loop_arr invocation on the appropriate arrow.
loop_arr
abstractmethod
¶
f : (A ⊗ C) ⇝ (B ⊗ C) ⊢ loop(f) : A ⇝ B.
Source code in src/quivers/arrows/typeclasses.py
121 122 123 | |
ArrowZero
¶
Bases: Arrow, ABC
An arrow with a designated bottom at every hom: zero_arr.
zero_arr
abstractmethod
¶
zero : A ⇝ B — the bottom element of Hom(A, B).
Source code in src/quivers/arrows/typeclasses.py
129 130 131 | |