proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.MonoidalTraversal

Description

The monoidal traversal optic and its free-profunctor apparatus. The mutually recursive TravFl/MonTravFl flavor classes and their leaf instances live in Proarrow.Optic.Traversal. A MonoidalTraversal distributes any StrongDistributiveProfunctor with no product-strength requirement; the profunctor-class encoding PTraversal converts to and from it via toPTraversal/fromPTraversal, the latter through the generic carrier ExOptic MonTravFl, made an SDP here by generators (the Day halves, the tensor-action witness Rep/Corep (ActionAt Tensor _) and the coproduct prism).

Synopsis

Documentation

type MonoidalTraversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (MonTravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #

type MonoidalTraversal' (s :: k) (a :: k) = MonoidalTraversal s s a a Source Github #

The generic carrier is a strong distributive profunctor, by generators

exBeside :: forall {k} (w :: FLAVOR k k) (a :: k) (b :: k) (s1 :: k) (t1 :: k) (s2 :: k) (t2 :: k). (Monoidal k, forall (p1 :: k +-> k) (p2 :: k +-> k) (q1 :: k +-> k) (q2 :: k +-> k). (w p1 q1, w p2 q2, Profunctor p1, Profunctor p2, Profunctor q1, Profunctor q2) => w (Beside p1 p2) (CoBeside q1 q2)) => ExOptic w a b s1 t1 -> ExOptic w a b s2 t2 -> ExOptic w a b (s1 ** s2) (t1 ** t2) Source Github #

exBesideSum :: forall {k} (w :: FLAVOR k k) (a :: k) (b :: k) (s1 :: k) (t1 :: k) (s2 :: k) (t2 :: k). (HasBinaryCoproducts k, forall (p1 :: k +-> k) (p2 :: k +-> k) (q1 :: k +-> k) (q2 :: k +-> k). (w p1 q1, w p2 q2, Profunctor p1, Profunctor p2, Profunctor q1, Profunctor q2) => w (BesideSum p1 p2) (CoBesideSum q1 q2)) => ExOptic w a b s1 t1 -> ExOptic w a b s2 t2 -> ExOptic w a b (s1 || s2) (t1 || t2) Source Github #

fromPTraversal :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (Distributive k, CopyDiscard k, SymMonoidal k) => PTraversal s t a b -> MonoidalTraversal s t a b Source Github #

The other half of the equivalence between the encodings: instantiate the profunctor-class traversal at ExOptic MonTravFl a b, an SDP by the instances above. Its tensor strength comes from the tensor-action witness Rep (ActionAt Tensor _), so this needs only CopyDiscard, already demanded by the coproduct prism, and no Cartesian. So Mat and FinRel qualify, but LINEAR, which cannot discard, does not. A Traversal follows since MonTravFl is a subflavor of TravFl.

monTraverseOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) p. (Distributive k, StrongDistributiveProfunctor p, (Ob a, Ob b) => c (ExOptic (MonTravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> p a b -> p s t Source Github #

Like traverseOf, but for a MonoidalTraversal: distributes any StrongDistributiveProfunctor with no product-strength requirement on the carrier. Every non-lens traversal (prism, Traversable functor, ...) is a monoidal traversal, so this accepts carriers like Writer w that are tensor-strong but not product-strong.

Accepts any encoding (cf. traverseOf): a PTraversal works directly, as does a (%)-composite.

type PTraversal (s :: j) (t :: j) (a :: j) (b :: j) = Optic (StrongDistributiveProfunctor :: (j +-> j) -> Constraint) s t a b Source Github #

A traversal in the profunctor-class-flavored encoding (cf. PIso), used by the GHC.Generics combinators below. Equivalent to Traversal via toPTraversal and fromPTraversal.

type PTraversal' (s :: j) (a :: j) = PTraversal s s a a Source Github #

toPTraversal :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). Distributive k => MonoidalTraversal s t a b -> PTraversal s t a b Source Github #

Half of the equivalence between the two traversal encodings: eliminate the existential witnesses with travP at the caller's profunctor.

type PTraversalFull (s :: j) (t :: j) (a :: j) (b :: j) = Optic ((StrongDistributiveProfunctor :: (j +-> j) -> Constraint) :&&: Strong (ProdAction :: j -> (PROD j, j) -> Type)) s t a b Source Github #

A full traversal in the profunctor-class encoding: distributes any profunctor carrying both distributive strength and product strength, the constraint travP demands. This is the Traversal analog of PTraversal, which drops the product strength (all it needs for a MonoidalTraversal). Equivalent to Traversal via toPTraversalFull and traversal.

traversal :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (Distributive k, CopyDiscard k, SymMonoidal k, HasProducts k, Ob a, Ob b, Ob s, Ob t) => (forall (r :: k +-> k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => r a b -> r s t) -> Traversal s t a b Source Github #

Build a Traversal from its profunctor-class form, by instantiating the rank-2 function at the generic carrier ExOptic TravFl a b (a StrongDistributiveProfunctor and Strong ProdAction, unlike ExOptic MonTravFl a b, since TravFl contains the product-lens witness). The Traversal analog of fromPTraversal.

toPTraversalFull :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). Distributive k => Traversal s t a b -> PTraversalFull s t a b Source Github #

Eliminate a Traversal to its profunctor-class form (the analog of toPTraversal): run travP at the caller's profunctor.

v1Optic :: PTraversal (V1 a) (V1 a') a a' Source Github #

u1Optic :: PTraversal (U1 a) (U1 a') a a' Source Github #

rec1Optic :: PTraversal (f a) (f a') a a' -> PTraversal (Rec1 f a) (Rec1 f a') a a' Source Github #

m1Optic :: forall f a a' i (k :: Meta). PTraversal (f a) (f a') a a' -> PTraversal (M1 i k f a) (M1 i k f a') a a' Source Github #

k1Optic :: PTraversal (K1 i k a) (K1 i k a') a a' Source Github #

plusOptic :: PTraversal (p a) (p a') a a' -> PTraversal (q a) (q a') a a' -> PTraversal ((p :+: q) a) ((p :+: q) a') a a' Source Github #

multOptic :: PTraversal (p a) (p a') a a' -> PTraversal (q a) (q a') a a' -> PTraversal ((p :*: q) a) ((p :*: q) a') a a' Source Github #

compOptic :: PTraversal (p (q a)) (p (q a')) (q a) (q a') -> PTraversal (q a) (q a') a a' -> PTraversal ((p :.: q) a) ((p :.: q) a') a a' Source Github #

Orphan instances

(Monoidal k, Ob a, Ob b, Flavor w, forall (x :: k). Ob x => w (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) x)) (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) x))) => Strong (Tensor :: k -> (k, k) -> Type) (ExOptic w a b :: k -> k -> Type) Source Github # 
Instance details

Methods

act :: forall (a0 :: k) (x :: k) (y :: k). Ob a0 => ExOptic w a b x y -> ExOptic w a b (Act (Tensor :: k -> (k, k) -> Type) a0 x) (Act (Tensor :: k -> (k, k) -> Type) a0 y) Source Github #

(Monoidal k, Ob a, Ob b, w (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type), forall (p1 :: k -> k -> Type) (p2 :: k -> k -> Type) (q1 :: k -> k -> Type) (q2 :: k -> k -> Type). (w p1 q1, w p2 q2, Profunctor p1, Profunctor p2, Profunctor q1, Profunctor q2) => w (Beside p1 p2) (CoBeside q1 q2)) => MonoidalProfunctor (ExOptic w a b :: k -> k -> Type) Source Github # 
Instance details

Methods

one :: ExOptic w a b (Unit :: k) (Unit :: k) Source Github #

(**) :: forall (x1 :: k) (x2 :: k) (y1 :: k) (y2 :: k). ExOptic w a b x1 x2 -> ExOptic w a b y1 y2 -> ExOptic w a b (x1 ** y1) (x2 ** y2) Source Github #

(CategoryOf k, Flavor w, forall (t :: k +-> k). (Traversable t, Representable t) => w t (RepCostar t)) => Traversing (ExOptic w a b :: k -> k -> Type) Source Github #

The generic carrier absorbs a traversable witness by composing the pair t/RepCostar t onto its legs with proact, like any other witness pair.

Instance details

Methods

traverseP :: forall (t :: k +-> k). (Traversable t, Representable t) => (t :.: ExOptic w a b) :~> (ExOptic w a b :.: t) Source Github #

(HasCoproducts k, Ob a, Ob b, Flavor w, forall (t :: k). Ob t => w (Rep (Coproduct t)) (Corep (Coproduct t))) => Strong (CoprodAction :: k -> (COPROD k, k) -> Type) (ExOptic w a b :: k -> k -> Type) Source Github # 
Instance details

Methods

act :: forall (a0 :: COPROD k) (x :: k) (y :: k). Ob a0 => ExOptic w a b x y -> ExOptic w a b (Act (CoprodAction :: k -> (COPROD k, k) -> Type) a0 x) (Act (CoprodAction :: k -> (COPROD k, k) -> Type) a0 y) Source Github #

(HasProducts k, Ob a, Ob b, Flavor w, forall (s :: k). Ob s => w (Rep (Product s)) (Corep (Product s))) => Strong (ProdAction :: k -> (PROD k, k) -> Type) (ExOptic w a b :: k -> k -> Type) Source Github # 
Instance details

Methods

act :: forall (a0 :: PROD k) (x :: k) (y :: k). Ob a0 => ExOptic w a b x y -> ExOptic w a b (Act (ProdAction :: k -> (PROD k, k) -> Type) a0 x) (Act (ProdAction :: k -> (PROD k, k) -> Type) a0 y) Source Github #

(HasCoproducts k, Ob a, Ob b, w (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type), forall (p1 :: k -> k -> Type) (p2 :: k -> k -> Type) (q1 :: k -> k -> Type) (q2 :: k -> k -> Type). (w p1 q1, w p2 q2, Profunctor p1, Profunctor p2, Profunctor q1, Profunctor q2) => w (BesideSum p1 p2) (CoBesideSum q1 q2)) => MonoidalProfunctor (Coprod (ExOptic w a b) :: COPROD k -> COPROD k -> Type) Source Github # 
Instance details

Methods

one :: Coprod (ExOptic w a b) (Unit :: COPROD k) (Unit :: COPROD k) Source Github #

(**) :: forall (x1 :: COPROD k) (x2 :: COPROD k) (y1 :: COPROD k) (y2 :: COPROD k). Coprod (ExOptic w a b) x1 x2 -> Coprod (ExOptic w a b) y1 y2 -> Coprod (ExOptic w a b) (x1 ** y1) (x2 ** y2) Source Github #