Arrow Theories¶
Each TypeclassTheory declares the operations and laws one arrow class introduces
(type class hierarchy): ThCategory_, ThArrow,
ThArrowChoice, ThArrowApply, ThArrowLoop, ThArrowZero, and ThArrowPlus, with the pair and
sum combinators of ThProducts and ThSums that the laws mention (Hughes, 2000). As for the
typeclass theories, a class's theory is the
colimit of its extension diagram. The identity law, for
instance, requires composition with an identity to leave an arrow unchanged.
theories
¶
Theories of the arrow typeclass tower, composed by colimit.
Each Hughes-style arrow typeclass has a
TypeclassTheory here, built
as in quivers.monadic.theories: one node
per class of the extension closure, one inclusion per extension edge, and
the class's theory as the colimit, with provenance naming the class that
declared each law. Arrows are elements of the universe sort U like
functions, and compose(f, g) is f >>> g (first f, then
g).
ThCategory_:id_arrandcomposewith the identity and associativity laws.ThProductsandThSums: the pair and injection combinators the arrow laws mention (pair,fst,snd,cross,assoc,unassoc,swap;inl,inr,inlfn,plus), each with its defining equations overThCombinators.ThArrow:arrandfirstwith the seven laws of Hughes (identity and composition ofarr;firstofarr, of a composite, and its commutation withfst, withid *** g, and withassoc). It isThCategory_andThProductsglued alongThCombinators, whose universe sort both use.ThArrowChoice:left_arrwith its laws onarr, composites, andinl.ThArrowApply:app_arrwith the lawfirst(arr(λx. arr(λy. (x, y)))) >>> app_arr = id_arr, the lambdas named byarrpairandpairwith.ThArrowLoop:loop_arrwith the left and right tightening, sliding, vanishing, and superposing laws of Paterson,seconddefined throughswap.ThArrowZeroandThArrowPlus:zero_arrandalt_arrwith the monoid laws.
The bridges in quivers.monadic.bridges
correspond to theory morphisms ThMonad → ThArrowApply (the Kleisli
construction) and back (the ArrowMonad construction).
ThCategory_
module-attribute
¶
ThCategory_ = TypeclassTheory(name='ThCategory_', operations=(operation('id_arr'), operation('compose', 'f', 'g')), equations=(law('category_left_identity', 'compose(id_arr(), f)', 'f'), law('category_right_identity', 'compose(f, id_arr())', 'f'), law('category_associativity', 'compose(compose(f, g), h)', 'compose(f, compose(g, h))')), extends=(ThCombinators,))
The theory of Category_.
ThProducts
module-attribute
¶
ThProducts = TypeclassTheory(name='ThProducts', operations=(operation('pair', 'x', 'y'), operation('fst'), operation('snd'), operation('cross', 'f', 'g'), operation('assoc'), operation('unassoc'), operation('swap')), equations=(law('product_fst', 'app(fst(), pair(x, y))', 'x'), law('product_snd', 'app(snd(), pair(x, y))', 'y'), law('product_cross', 'app(cross(f, g), pair(x, y))', 'pair(app(f, x), app(g, y))'), law('product_assoc', 'app(assoc(), pair(pair(x, y), z))', 'pair(x, pair(y, z))'), law('product_unassoc', 'app(unassoc(), pair(x, pair(y, z)))', 'pair(pair(x, y), z)'), law('product_swap', 'app(swap(), pair(x, y))', 'pair(y, x)')), extends=(ThCombinators,))
Pairs and the functions on them the arrow laws use.
ThSums
module-attribute
¶
ThSums = TypeclassTheory(name='ThSums', operations=(operation('inl', 'x'), operation('inr', 'y'), operation('inlfn'), operation('plus', 'f', 'g')), equations=(law('sum_inlfn', 'app(inlfn(), x)', 'inl(x)'), law('sum_plus_inl', 'app(plus(f, g), inl(x))', 'inl(app(f, x))'), law('sum_plus_inr', 'app(plus(f, g), inr(y))', 'inr(app(g, y))')), extends=(ThCombinators,))
Injections and the functions on sums the choice laws use.
ThArrow
module-attribute
¶
ThArrow = TypeclassTheory(name='ThArrow', operations=(operation('arr', 'f'), operation('first', 'a')), equations=(law('arrow_identity', 'arr(id())', 'id_arr()'), law('arrow_composition', 'arr(app(app(dot(), g), f))', 'compose(arr(f), arr(g))'), law('arrow_first_arr', 'first(arr(f))', 'arr(cross(f, id()))'), law('arrow_first_compose', 'first(compose(f, g))', 'compose(first(f), first(g))'), law('arrow_first_fst', 'compose(first(f), arr(fst()))', 'compose(arr(fst()), f)'), law('arrow_first_cross', 'compose(first(f), arr(cross(id(), g)))', 'compose(arr(cross(id(), g)), first(f))'), law('arrow_first_assoc', 'compose(first(first(f)), arr(assoc()))', 'compose(arr(assoc()), first(f))')), extends=(ThCategory_, ThProducts))
The theory of Arrow.
ThArrowChoice
module-attribute
¶
ThArrowChoice = TypeclassTheory(name='ThArrowChoice', operations=(operation('left_arr', 'a'),), equations=(law('choice_left_arr', 'left_arr(arr(f))', 'arr(plus(f, id()))'), law('choice_left_compose', 'left_arr(compose(f, g))', 'compose(left_arr(f), left_arr(g))'), law('choice_left_inl', 'compose(f, arr(inlfn()))', 'compose(arr(inlfn()), left_arr(f))')), extends=(ThArrow, ThSums))
The theory of ArrowChoice.
ThArrowApply
module-attribute
¶
ThArrowApply = TypeclassTheory(name='ThArrowApply', operations=(operation('app_arr'), operation('pairwith', 'x'), operation('arrpair')), equations=(law('apply_pairwith', 'app(pairwith(x), y)', 'pair(x, y)'), law('apply_arrpair', 'app(arrpair(), x)', 'arr(pairwith(x))'), law('apply_identity', 'compose(first(arr(arrpair())), app_arr())', 'id_arr()')), extends=(ThArrow,))
The theory of ArrowApply.
ThArrowLoop
module-attribute
¶
ThArrowLoop = TypeclassTheory(name='ThArrowLoop', operations=(operation('loop_arr', 'a'), operation('second', 'a')), equations=(law('loop_second', 'second(f)', 'compose(arr(swap()), compose(first(f), arr(swap())))'), law('loop_left_tightening', 'loop_arr(compose(first(h), f))', 'compose(h, loop_arr(f))'), law('loop_right_tightening', 'loop_arr(compose(f, first(h)))', 'compose(loop_arr(f), h)'), law('loop_sliding', 'loop_arr(compose(f, arr(cross(id(), k))))', 'loop_arr(compose(arr(cross(id(), k)), f))'), law('loop_vanishing', 'loop_arr(loop_arr(f))', 'loop_arr(compose(arr(unassoc()), compose(f, arr(assoc()))))'), law('loop_superposing', 'second(loop_arr(f))', 'loop_arr(compose(arr(assoc()), compose(second(f), arr(unassoc()))))')), extends=(ThArrow,))
The theory of ArrowLoop.
ThArrowZero
module-attribute
¶
ThArrowZero = TypeclassTheory(name='ThArrowZero', operations=(operation('zero_arr'),), extends=(ThArrow,))
The theory of ArrowZero.
ThArrowPlus
module-attribute
¶
ThArrowPlus = TypeclassTheory(name='ThArrowPlus', operations=(operation('alt_arr', 'f', 'g'),), equations=(law('plus_left_identity', 'alt_arr(zero_arr(), f)', 'f'), law('plus_right_identity', 'alt_arr(f, zero_arr())', 'f'), law('plus_associativity', 'alt_arr(alt_arr(f, g), h)', 'alt_arr(f, alt_arr(g, h))')), extends=(ThArrowZero,))
The theory of ArrowPlus.
The theory constants are documented on the arrows overview.
Cited sources¶
John Hughes. Generalising Monads to Arrows. Science of Computer Programming, 37(1–3):67–111, 2000. URL: https://www.sciencedirect.com/science/article/pii/S0167642399000234, doi:10.1016/S0167-6423(99)00023-4.