| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Proarrow.Tools.Laws
Description
Laws stated as code, polymorphic in the category. A law of the structures cs takes five
object variables and a supply of named arbitrary arrows, and returns an equation between two
arrows. The proarrow:testing library checks laws by running them with random objects and
arrows, in a category whose arrows also carry their own description, so that a failing law
prints as the code it was built from.
A derived operation (a function defined from the class methods, like
doubleNeg) would print as its definition. label
names it instead.
A class's laws are an instance of Laws for the list of structures they mention, the same list
the class's free-category structure requires, e.g.
. The instances live next to their
classes.Laws SymMonoidalStructures
Synopsis
- class Laws (cs :: [Kind -> Constraint]) where
- data Law (cs :: [Kind -> Constraint]) = Law String (LawBody cs)
- lawName :: forall (cs :: [Kind -> Constraint]). Law cs -> String
- type LawBody (cs :: [Kind -> Constraint]) = forall {k} (a :: k) (b :: k) (c :: k) (d :: k) (e :: k) (m :: Type -> Type). (Labelled k, All cs k, Monad m, Ob a, Ob b, Ob c, Ob d, Ob e) => (forall (x :: k) (y :: k). (Ob x, Ob y) => String -> m (x ~> y)) -> m (Equation k)
- data ProEquation (p :: j +-> k) where
- (:=:) :: forall {j} {k} (p :: j +-> k) (a :: k) (b :: j). p a b -> p a b -> ProEquation p
- InK :: forall {j} {k} (p :: j +-> k). Equation k -> ProEquation p
- InJ :: forall {j} {k} (p :: j +-> k). Equation j -> ProEquation p
- type Equation k = ProEquation (Hom k)
- withSides :: Equation k -> (forall (a :: k) (b :: k). (a ~> b) -> (a ~> b) -> r) -> r
- class ArrowEquation i r where
- fromArrowEquation :: Equation i -> r
- (===) :: forall {i} m r (a :: i) (b :: i). (Applicative m, ArrowEquation i r) => (a ~> b) -> (a ~> b) -> m r
- (=:=) :: forall {j} {k} m p (a :: k) (b :: j). Applicative m => p a b -> p a b -> m (ProEquation p)
- data Inverses k where
- type PureLawBody (cs :: [Kind -> Constraint]) (r :: Kind -> Type) = forall {k} (a :: k) (b :: k) (c :: k) (d :: k) (e :: k). (Labelled k, All cs k, Ob a, Ob b, Ob c, Ob d, Ob e) => r k
- leftInverse :: CategoryOf k => Inverses k -> Equation k
- rightInverse :: CategoryOf k => Inverses k -> Equation k
- inverses :: forall (cs :: [Kind -> Constraint]). String -> PureLawBody cs Inverses -> [Law cs]
- data Bijection (m :: Type -> Type) k where
- type BijectionBody (cs :: [Kind -> Constraint]) = forall {k} (a :: k) (b :: k) (c :: k) (d :: k) (e :: k) (m :: Type -> Type). (Labelled k, All cs k, Monad m, Ob a, Ob b, Ob c, Ob d, Ob e) => (forall (x :: k) (y :: k). (Ob x, Ob y) => String -> m (x ~> y)) -> Bijection m k
- bijection :: forall (cs :: [Kind -> Constraint]). String -> BijectionBody cs -> [Law cs]
- class ProLaws (c :: (j +-> k) -> Constraint) where
- data ProLaw (c :: (j +-> k) -> Constraint)
- = ProLaw String (ProLawBody c)
- | ProLaw3 String (ProLawBody3 c)
- proLawName :: forall {j} {k} (c :: (j +-> k) -> Constraint). ProLaw c -> String
- type ProLawBody (cl :: (j +-> k) -> Constraint) = forall (p :: j +-> k) (a :: k) (b :: j) (c :: k) (d :: j) (e :: k) (f :: j) (m :: Type -> Type). (cl p, Labelled j, Labelled k, Monad m, Ob a, Ob b, Ob c, Ob d, Ob e, Ob f) => p a b -> (forall (x :: k) (y :: k). (Ob x, Ob y) => String -> m (x ~> y)) -> (forall (x :: j) (y :: j). (Ob x, Ob y) => String -> m (x ~> y)) -> m (ProEquation p)
- type ProLawBody3 (cl :: (j +-> k) -> Constraint) = forall (p :: j +-> k) (a :: k) (b :: j) (c :: k) (d :: j) (e :: k) (f :: j) (m :: Type -> Type). (cl p, Labelled j, Labelled k, Monad m, Ob a, Ob b, Ob c, Ob d, Ob e, Ob f) => p a b -> p c d -> p e f -> (forall (x :: k) (y :: k). (Ob x, Ob y) => String -> m (x ~> y)) -> (forall (x :: j) (y :: j). (Ob x, Ob y) => String -> m (x ~> y)) -> m (ProEquation p)
- class CategoryOf k => Labelled k where
Laws
class Laws (cs :: [Kind -> Constraint]) where Source Github #
The laws of the structures cs. A class with a new kind of object also needs support in the
testing library before its laws can be checked, see Proarrow.Testing.Laws.Run.
For example, the laws of a functor on objects Sq with action sq on arrows:
instance Laws '[HasSquare] where
laws =
[ Law "sq identity" \ @a _ -> withObSq @_ @a (sq (obj @a) === id)
, Law "sq composition" \ @a @b @c mor -> do
f <- mor @a @b "f"
g <- mor @b @c "g"
sq (g . f) === sq g . sq f
]
Instances
| Laws SymMonoidalStructures Source Github # |
|
Defined in Proarrow.Category.Monoidal | |
| Laws ClosedStructures Source Github # |
|
Defined in Proarrow.Category.Monoidal.Closed | |
| Laws CompactClosedStructures Source Github # |
|
Defined in Proarrow.Category.Monoidal.CompactClosed | |
| Laws CopyDiscardStructures Source Github # |
|
Defined in Proarrow.Category.Monoidal.CopyDiscard | |
| Laws DialogueStructures Source Github # |
|
Defined in Proarrow.Category.Monoidal.Dialogue | |
| Laws DistributiveStructures Source Github # | The tensor distributes over coproducts and is absorbed by the initial object:
|
Defined in Proarrow.Category.Monoidal.Distributive | |
| Laws FrobeniusStructures Source Github # | The supplied monoids and comonoids are special and satisfy the Frobenius law. Their monoid and comonoid laws, and their commutativity, are separate instances, in Proarrow.Monoid. |
Defined in Proarrow.Category.Monoidal.Hypergraph | |
| Laws IsoMixStructures Source Github # |
|
Defined in Proarrow.Category.Monoidal.IsoMix | |
| Laws StarAutonomousStructures Source Github # |
|
Defined in Proarrow.Category.Monoidal.StarAutonomous | |
| Laws TracedStructures Source Github # | The trace laws, for |
Defined in Proarrow.Category.Monoidal.Strength | |
| Laws '[Monoidal, SymMonoidal, Supplies CocommutativeComonoid] Source Github # | The supplied comonoids are cocommutative: |
Defined in Proarrow.Monoid Methods laws :: [Law '[Monoidal, SymMonoidal, Supplies CocommutativeComonoid]] Source Github # | |
| Laws '[Monoidal, SymMonoidal, Supplies CommutativeMonoid] Source Github # | The supplied monoids are commutative: |
Defined in Proarrow.Monoid Methods laws :: [Law '[Monoidal, SymMonoidal, Supplies CommutativeMonoid]] Source Github # | |
| Laws '[Monoidal, Supplies Comonoid] Source Github # | In a category that supplies comonoids, every object is one: |
| Laws '[Monoidal, Supplies Monoid] Source Github # | In a category that supplies monoids, every object is one: |
| Laws '[Monoidal] Source Github # | The tensor is a bifunctor, and the unitors and the associator are natural isomorphisms satisfying the triangle and pentagon identities. |
| Laws '[HasBinaryCoproducts] Source Github # | The universal property of the binary coproduct: the injections recover the components of
|
Defined in Proarrow.Colimit.BinaryCoproduct | |
| Laws '[HasInitialObject] Source Github # | Every arrow out of the initial object is |
Defined in Proarrow.Colimit.Initial | |
| Laws '[CategoryOf] Source Github # |
|
Defined in Proarrow.Tools.Laws | |
| Laws '[HasBinaryProducts] Source Github # | The universal property of the binary product: the projections recover the components of
|
Defined in Proarrow.Limit.BinaryProduct | |
| Laws '[HasTerminalObject] Source Github # | Every arrow into the terminal object is |
Defined in Proarrow.Limit.Terminal | |
lawName :: forall (cs :: [Kind -> Constraint]). Law cs -> String Source Github #
The name of a law, used as its test's name.
type LawBody (cs :: [Kind -> Constraint]) = forall {k} (a :: k) (b :: k) (c :: k) (d :: k) (e :: k) (m :: Type -> Type). (Labelled k, All cs k, Monad m, Ob a, Ob b, Ob c, Ob d, Ob e) => (forall (x :: k) (y :: k). (Ob x, Ob y) => String -> m (x ~> y)) -> m (Equation k) Source Github #
Equations
data ProEquation (p :: j +-> k) where Source Github #
Two parallel elements of a profunctor claimed to be equal, or an equation between arrows of its
codomain (InK) or domain (InJ).
Constructors
| (:=:) :: forall {j} {k} (p :: j +-> k) (a :: k) (b :: j). p a b -> p a b -> ProEquation p infix 1 | |
| InK :: forall {j} {k} (p :: j +-> k). Equation k -> ProEquation p | |
| InJ :: forall {j} {k} (p :: j +-> k). Equation j -> ProEquation p |
Instances
| ArrowEquation j (ProEquation p) Source Github # | |
Defined in Proarrow.Tools.Laws Methods fromArrowEquation :: Equation j -> ProEquation p Source Github # | |
| ArrowEquation k (ProEquation p) Source Github # | |
Defined in Proarrow.Tools.Laws Methods fromArrowEquation :: Equation k -> ProEquation p Source Github # | |
type Equation k = ProEquation (Hom k) Source Github #
Two parallel arrows claimed to be equal: an equation between elements of the hom profunctor.
withSides :: Equation k -> (forall (a :: k) (b :: k). (a ~> b) -> (a ~> b) -> r) -> r Source Github #
class ArrowEquation i r where Source Github #
The equations that an equation between arrows of i can be the result of: those of a
profunctor law whose codomain (InK) or domain (InJ) is i. An Equation is one of these,
at the hom profunctor. When the codomain and the domain are the same category either
constructor says the same, and InK is used.
Methods
fromArrowEquation :: Equation i -> r Source Github #
An equation between arrows of i, as an r.
Instances
| ArrowEquation j (ProEquation p) Source Github # | |
Defined in Proarrow.Tools.Laws Methods fromArrowEquation :: Equation j -> ProEquation p Source Github # | |
| ArrowEquation k (ProEquation p) Source Github # | |
Defined in Proarrow.Tools.Laws Methods fromArrowEquation :: Equation k -> ProEquation p Source Github # | |
(===) :: forall {i} m r (a :: i) (b :: i). (Applicative m, ArrowEquation i r) => (a ~> b) -> (a ~> b) -> m r infix 1 Source Github #
An equation between arrows as the result of a law body, in whichever category of the law the
arrows are in: l .=== r = pure (fromArrowEquation (l :=: r))
(=:=) :: forall {j} {k} m p (a :: k) (b :: j). Applicative m => p a b -> p a b -> m (ProEquation p) infix 1 Source Github #
Inverses
data Inverses k where Source Github #
A pair of arrows claimed to be inverse to each other, see inverses.
type PureLawBody (cs :: [Kind -> Constraint]) (r :: Kind -> Type) = forall {k} (a :: k) (b :: k) (c :: k) (d :: k) (e :: k). (Labelled k, All cs k, Ob a, Ob b, Ob c, Ob d, Ob e) => r k Source Github #
The body of a law that asks for no arrows: given five object variables, an r k.
leftInverse :: CategoryOf k => Inverses k -> Equation k Source Github #
g . f = id and f . g = id for .Inverses f g
rightInverse :: CategoryOf k => Inverses k -> Equation k Source Github #
g . f = id and f . g = id for .Inverses f g
inverses :: forall (cs :: [Kind -> Constraint]). String -> PureLawBody cs Inverses -> [Law cs] Source Github #
The two laws saying that a pair of arrows f, g are inverse to each other: g is a left
and a right inverse of f.
Bijections
data Bijection (m :: Type -> Type) k where Source Github #
Two maps between hom-sets claimed to be inverse to each other, see bijection, with how to
ask for an arrow of either hom-set.
type BijectionBody (cs :: [Kind -> Constraint]) = forall {k} (a :: k) (b :: k) (c :: k) (d :: k) (e :: k) (m :: Type -> Type). (Labelled k, All cs k, Monad m, Ob a, Ob b, Ob c, Ob d, Ob e) => (forall (x :: k) (y :: k). (Ob x, Ob y) => String -> m (x ~> y)) -> Bijection m k Source Github #
The body of a bijection: given five object variables and a supply of named arbitrary arrows,
the two maps, with how to ask for an arrow of each hom-set.
bijection :: forall (cs :: [Kind -> Constraint]). String -> BijectionBody cs -> [Law cs] Source Github #
The two laws saying that maps to and from between hom-sets are inverse to each other:
from (to f) = f and to (from g) = g. Each asks only for the arrow it needs, so an empty
hom-set on the other side discards nothing.
The laws of a category
Profunctor laws
class ProLaws (c :: (j +-> k) -> Constraint) where Source Github #
The laws of the profunctor class c, for any profunctor p with c p. The instances for
classes that Proarrow.Category.Instance.Free depends on live here.
Instances
| ProLaws (DaggerProfunctor :: (j +-> j) -> Constraint) Source Github # |
|
Defined in Proarrow.Tools.Laws Methods proLaws :: [ProLaw (DaggerProfunctor :: (j +-> j) -> Constraint)] Source Github # | |
| ProLaws (Promonad :: CAT j -> Constraint) Source Github # |
|
Defined in Proarrow.Promonad | |
| ProLaws (Procomonad :: (j +-> j) -> Constraint) Source Github # |
|
Defined in Proarrow.Promonad Methods proLaws :: [ProLaw (Procomonad :: (j +-> j) -> Constraint)] Source Github # | |
| ProLaws (Finitary :: (j +-> k) -> Constraint) Source Github # |
|
Defined in Proarrow.Category.Enriched.Finitary | |
| ProLaws (MonoidalProfunctor :: (j +-> k) -> Constraint) Source Github # |
|
Defined in Proarrow.Category.Monoidal Methods proLaws :: [ProLaw (MonoidalProfunctor :: (j +-> k) -> Constraint)] Source Github # | |
| ProLaws (Profunctor :: (j +-> k) -> Constraint) Source Github # |
|
Defined in Proarrow.Tools.Laws Methods proLaws :: [ProLaw (Profunctor :: (j +-> k) -> Constraint)] Source Github # | |
| ProLaws (Corepresentable :: (j +-> k) -> Constraint) Source Github # |
|
Defined in Proarrow.Tools.Laws Methods proLaws :: [ProLaw (Corepresentable :: (j +-> k) -> Constraint)] Source Github # | |
| ProLaws (Representable :: (j +-> k) -> Constraint) Source Github # |
|
Defined in Proarrow.Tools.Laws Methods proLaws :: [ProLaw (Representable :: (j +-> k) -> Constraint)] Source Github # | |
| ProLaws (Costrong (Tensor :: j -> (j, j) -> Type) :: (j +-> j) -> Constraint) Source Github # | The laws of costrength for the tensor acting on its own category: |
| ProLaws (Strong (Tensor :: j -> (j, j) -> Type) :: (j +-> j) -> Constraint) Source Github # | The laws of strength for the tensor acting on its own category: acting by the |
| ProLaws (LeftProadjoint q :: (j +-> k) -> Constraint) Source Github # | The zigzag law for elements of the left adjoint |
Defined in Proarrow.Adjunction | |
| ProLaws (Proadjunction p :: (j +-> k) -> Constraint) Source Github # | The zigzag law for elements of the right adjoint |
Defined in Proarrow.Adjunction | |
data ProLaw (c :: (j +-> k) -> Constraint) Source Github #
Constructors
| ProLaw String (ProLawBody c) | |
| ProLaw3 String (ProLawBody3 c) |
proLawName :: forall {j} {k} (c :: (j +-> k) -> Constraint). ProLaw c -> String Source Github #
The name of a profunctor law, used as its test's name.
type ProLawBody (cl :: (j +-> k) -> Constraint) = forall (p :: j +-> k) (a :: k) (b :: j) (c :: k) (d :: j) (e :: k) (f :: j) (m :: Type -> Type). (cl p, Labelled j, Labelled k, Monad m, Ob a, Ob b, Ob c, Ob d, Ob e, Ob f) => p a b -> (forall (x :: k) (y :: k). (Ob x, Ob y) => String -> m (x ~> y)) -> (forall (x :: j) (y :: j). (Ob x, Ob y) => String -> m (x ~> y)) -> m (ProEquation p) Source Github #
The body of a ProLaw: given a profunctor p :: j , six object variables alternating
between +-> kk and j, an element p :: p a b between the first two, and a supply of named
arbitrary arrows for each of k and j, produce a ProEquation. The element picks its
endpoints, so that a test can draw it where p has elements, and a test draws the other
variables so that there are arrows e and ~> c ~> ab . A body binds as many
of the variables as it uses, e.g. ~> d ~> f\ @_ @a @b p morK _ -> ....
type ProLawBody3 (cl :: (j +-> k) -> Constraint) = forall (p :: j +-> k) (a :: k) (b :: j) (c :: k) (d :: j) (e :: k) (f :: j) (m :: Type -> Type). (cl p, Labelled j, Labelled k, Monad m, Ob a, Ob b, Ob c, Ob d, Ob e, Ob f) => p a b -> p c d -> p e f -> (forall (x :: k) (y :: k). (Ob x, Ob y) => String -> m (x ~> y)) -> (forall (x :: j) (y :: j). (Ob x, Ob y) => String -> m (x ~> y)) -> m (ProEquation p) Source Github #
The body of a ProLaw3: a ProLawBody with three elements p :: p a b, p' :: p c d and
p'' :: p e f, which pick all six object variables. A law that needs arbitrary objects uses the
endpoints of an element it does not otherwise use.