| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Proarrow.Optic.Tracer
Contents
Description
The tracer: the write-only optic whose residual sits on the source and target side,
Tracer s t a b = exists m. (m ** s ~> a, b ~> m ** t)
witnessed by /CorepRep( (ActionAt Tensor m)TracerFl), a setter witness pair
read the other way round. Running it forwards closes a feedback loop through the residual, so it
distributes any Costrong profunctor (tracerP) and is a Setter
exactly in a TracedMonoidal category. Run backwards
(over . re) it needs no trace. Build with tracer,
eliminate with tracerOf or recover the legs with withTracer. fromPTracer/toPTracer
mediate with PTracer ().Optic (Costrong Tensor)
Synopsis
- class (SetterFl p q, SetterFl q p) => TracerFl (p :: k +-> k) (q :: k +-> k) where
- tracerP :: forall {k} p q (s :: k) (a :: k) (b :: k) (t :: k) r. (TracerFl p q, Costrong (Tensor :: k -> (k, k) -> Type) r) => p s a -> q b t -> r a b -> r s t
- type Tracer (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (TracerFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Tracer' (s :: k) (a :: k) = Tracer s s a a
- tracer :: forall {k} (m :: k) (s :: k) (t :: k) (a :: k) (b :: k). (TracedMonoidal k, Ob m, Ob s, Ob t, Ob a, Ob b) => ((m ** s) ~> a) -> (b ~> (m ** t)) -> Tracer s t a b
- tracerOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Monoidal k, Costrong (Tensor :: k -> (k, k) -> Type) r, c (ExOptic (TracerFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t
- withTracer :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Monoidal k, (Ob a, Ob b) => c (ExOptic (TracerFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> (forall (m :: k). Ob m => ((m ** s) ~> a) -> (b ~> (m ** t)) -> r) -> r
- type PTracer (s :: j) (t :: j) (a :: j) (b :: j) = Optic (Costrong (Tensor :: j -> (j, j) -> Type)) s t a b
- fromPTracer :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). TracedMonoidal k => PTracer s t a b -> Tracer s t a b
- toPTracer :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). CategoryOf k => Tracer s t a b -> PTracer s t a b
Documentation
class (SetterFl p q, SetterFl q p) => TracerFl (p :: k +-> k) (q :: k +-> k) where Source Github #
The tracer flavor: a witness pair with legs m ** s ~> a and b ~> m ** t for an
existential residual m, an pair with the witnesses' roles swapped. It is
the ActFl Tensor counterpart of Prostrong, as
Costrong TensorMonLensFl is of
.Strong Tensor
A tracer pair and its flip are both setter pairs, so over works on a
tracer and on its re, and
typechecks. The converse
fails: a flipped setter (e.g. a flipped lens witness) need not have a trace.convert t :: Optic (Prostrong (Flip SetterFl)) s t a b
TracedMonoidal sits in the instance context of the tensor-action witness, so ordinary setters
don't pick up the constraint. Monoidal sits on the method so that the identity witness needs
only CategoryOf and IsoFl can include this flavor.
Methods
withTracerP :: forall (s :: k) (a :: k) (b :: k) (t :: k) r. Monoidal k => p s a -> q b t -> (forall (m :: k). Ob m => ((m ** s) ~> a) -> (b ~> (m ** t)) -> r) -> r Source Github #
Recover the two legs, with the residual m existential.
Instances
| CategoryOf k => TracerFl (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # | |
| (TracedMonoidal k, Ob m) => TracerFl (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Tracer | |
| (TracerFl f g, TracerFl f' g') => TracerFl (f :.: f' :: k -> k -> Type) (g' :.: g :: k -> k -> Type) Source Github # | |
tracerP :: forall {k} p q (s :: k) (a :: k) (b :: k) (t :: k) r. (TracerFl p q, Costrong (Tensor :: k -> (k, k) -> Type) r) => p s a -> q b t -> r a b -> r s t Source Github #
type Tracer (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (TracerFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
tracer :: forall {k} (m :: k) (s :: k) (t :: k) (a :: k) (b :: k). (TracedMonoidal k, Ob m, Ob s, Ob t, Ob a, Ob b) => ((m ** s) ~> a) -> (b ~> (m ** t)) -> Tracer s t a b Source Github #
Build a tracer from its two legs and a chosen residual m: m ** s ~> a decomposes the source
(given the residual), b ~> m ** t rebuilds the target and produces the residual to feed back.
tracerOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Monoidal k, Costrong (Tensor :: k -> (k, k) -> Type) r, c (ExOptic (TracerFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t Source Github #
Distribute any Costrong profunctor through a tracer (or any stronger optic). At the hom this
is over, computing the feedback loop through the residual.
Accepts any encoding (cf. traverseOf): a PTracer works directly, as
does a (%)-composite.
withTracer :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Monoidal k, (Ob a, Ob b) => c (ExOptic (TracerFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> (forall (m :: k). Ob m => ((m ** s) ~> a) -> (b ~> (m ** t)) -> r) -> r Source Github #
Eliminate any optic that is at least an iso and at most a tracer to its two legs, recovering
the existential residual m, in either encoding: run it at its witness pair (ExOptic TracerFl,
via withLegs) and read the legs off with withTracerP.
type PTracer (s :: j) (t :: j) (a :: j) (b :: j) = Optic (Costrong (Tensor :: j -> (j, j) -> Type)) s t a b Source Github #
A tracer in the profunctor-class-flavored encoding (cf. PIso). Equivalent to
Tracer via toPTracer and fromPTracer.
fromPTracer :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). TracedMonoidal k => PTracer s t a b -> Tracer s t a b Source Github #
toPTracer :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). CategoryOf k => Tracer s t a b -> PTracer s t a b Source Github #
Orphan instances
| (Monoidal k, Ob a, Ob b, Flavor w, forall (m :: k). Ob m => w (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m)) (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m))) => Costrong (Tensor :: k -> (k, k) -> Type) (ExOptic w a b :: k -> k -> Type) Source Github # | The generic carrier absorbs the residual of a |
| (TracedMonoidal k, Ob m) => SetterFl (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) Source Github # | The tracer witness: the tensor-action pair read the other way round, |