| 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 /
withTracerP) -- a setter witness pair read the other way round, equivalently an ActFl
Tensor pair with the roles of the two witnesses swapped. 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 at all. Build with
tracer, eliminate with tracerOf (or over at the hom) or recover the
legs with withTracer; fromPTracer/toPTracer mediate with the profunctor-class-flavored
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 whose legs are m ** s ~> a and b ~> m ** t for an
existential residual m -- the residual functor is applied to the source and target rather
than to the foci, i.e. an pair with the roles of the two witnesses swapped.
ActFl TensorwithTracerP recovers the legs (the withMonLensP of tracers), and
distributing a Costrong profunctor (tracerP) is derived from them. This is the
counterpart of Prostrong the way Costrong TensorMonLensFl is of
.Strong Tensor
Every tracer witness pair is a setter pair (SetterFl superclass, so over,
set, (%~) all work) and its flip is one too
(, so SetterFl q p works without a trace, and
over . re -- the converse fails, since a
flipped setter need not have a trace, e.g. a flipped lens witness, so tracers are the subflavor of
flipped setters that can also run forwards);
convert t :: Optic (Prostrong (Flip SetterFl)) s t a bTracedMonoidal rides in the instance context of the tensor-action witness, not in the
method, so ordinary setters keep their honest constraints. Monoidal sits on the method rather
than the class 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, |