proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.MonoidalTraversal

Description

The monoidal traversal optic and its free-profunctor apparatus, split out of Proarrow.Optic.Traversal (which keeps the mutually-recursive TravRes/MonTravRes flavor classes and their leaf instances). 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 free MonTravRes-strong profunctor ExOptic MonTravRes (an SDP, via the tensor-strength witness TensorW).

Synopsis

Documentation

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

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

data TensorW (a :: k) (s :: k) (x :: k) where Source Github #

Witness pair for tensor strength: the focus x sits inside a ** x with the residual a carried on the left. This is the tensor-action dual of the coproduct-action prism witness Rep (Coproduct t)/Corep (Coproduct t) (whose monTravP calls act @CoprodAction): here monTravP calls act @Tensor -- exactly the strength any StrongDistributiveProfunctor already carries. Unlike the product-lens Rep (Product a) that used to witness Strong Tensor for the free traversal, this needs no Strong ProdAction and no tensor = product (Cartesian): it is a genuine MonTravRes, so the free monoidal-traversal profunctor ExOptic MonTravRes is MonStrong.

Constructors

TensorW :: forall {k} (a :: k) (x :: k) (s :: k). (Ob a, Ob x) => (s ~> (a ** x)) -> TensorW a s x 

Instances

Instances details
(Monoidal k, Ob a) => Profunctor (TensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

dimap :: forall (c :: k) (a0 :: k) (b :: k) (d :: k). (c ~> a0) -> (b ~> d) -> TensorW a a0 b -> TensorW a c d Source Github #

lmap :: forall (c :: k) (a0 :: k) (b :: k). (c ~> a0) -> TensorW a a0 b -> TensorW a c b Source Github #

rmap :: forall (b :: k) (d :: k) (a0 :: k). (b ~> d) -> TensorW a a0 b -> TensorW a a0 d Source Github #

(\\) :: forall (a0 :: k) (b :: k) r. ((Ob a0, Ob b) => r) -> TensorW a a0 b -> r Source Github #

(Monoidal k, Ob a) => Proadjunction (TensorW a :: k -> k -> Type) (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

unit :: forall (a0 :: k). Ob a0 => (CoTensorW a :.: TensorW a) a0 a0 Source Github #

counit :: (TensorW a :.: CoTensorW a) :~> ((~>) :: CAT k) Source Github #

(CopyDiscard k, Ob a) => FoldRes (TensorW a :: k -> k -> Type) (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

foldMapP :: forall (m :: k) (s :: k) (a0 :: k). Monoid m => TensorW a s a0 -> (a0 ~> m) -> s ~> m Source Github #

(Monoidal k, Ob a) => SetterRes (TensorW a :: k -> k -> Type) (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

overP :: forall (s :: k) (a0 :: k) (b :: k) (t :: k). TensorW a s a0 -> CoTensorW a b t -> (a0 ~> b) -> s ~> t Source Github #

(CopyDiscard k, Ob a) => MonTravRes (TensorW a :: k -> k -> Type) (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

monTravP :: forall r (s :: k) (a0 :: k) (b :: k) (t :: k). StrongDistributiveProfunctor r => TensorW a s a0 -> CoTensorW a b t -> r a0 b -> r s t Source Github #

(CopyDiscard k, Ob a) => TravRes (TensorW a :: k -> k -> Type) (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

travP :: forall r (s :: k) (a0 :: k) (b :: k) (t :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => TensorW a s a0 -> CoTensorW a b t -> r a0 b -> r s t Source Github #

data CoTensorW (a :: k) (x :: k) (t :: k) where Source Github #

The covariant half of the TensorW witness pair: rebuilds the target around the carried residual, (a ** x) ~> t.

Constructors

CoTensorW :: forall {k} (a :: k) (x :: k) (t :: k). (Ob a, Ob x) => ((a ** x) ~> t) -> CoTensorW a x t 

Instances

Instances details
(Monoidal k, Ob a) => Profunctor (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

dimap :: forall (c :: k) (a0 :: k) (b :: k) (d :: k). (c ~> a0) -> (b ~> d) -> CoTensorW a a0 b -> CoTensorW a c d Source Github #

lmap :: forall (c :: k) (a0 :: k) (b :: k). (c ~> a0) -> CoTensorW a a0 b -> CoTensorW a c b Source Github #

rmap :: forall (b :: k) (d :: k) (a0 :: k). (b ~> d) -> CoTensorW a a0 b -> CoTensorW a a0 d Source Github #

(\\) :: forall (a0 :: k) (b :: k) r. ((Ob a0, Ob b) => r) -> CoTensorW a a0 b -> r Source Github #

(Monoidal k, Ob a) => Proadjunction (TensorW a :: k -> k -> Type) (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

unit :: forall (a0 :: k). Ob a0 => (CoTensorW a :.: TensorW a) a0 a0 Source Github #

counit :: (TensorW a :.: CoTensorW a) :~> ((~>) :: CAT k) Source Github #

(CopyDiscard k, Ob a) => FoldRes (TensorW a :: k -> k -> Type) (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

foldMapP :: forall (m :: k) (s :: k) (a0 :: k). Monoid m => TensorW a s a0 -> (a0 ~> m) -> s ~> m Source Github #

(Monoidal k, Ob a) => SetterRes (TensorW a :: k -> k -> Type) (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

overP :: forall (s :: k) (a0 :: k) (b :: k) (t :: k). TensorW a s a0 -> CoTensorW a b t -> (a0 ~> b) -> s ~> t Source Github #

(CopyDiscard k, Ob a) => MonTravRes (TensorW a :: k -> k -> Type) (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

monTravP :: forall r (s :: k) (a0 :: k) (b :: k) (t :: k). StrongDistributiveProfunctor r => TensorW a s a0 -> CoTensorW a b t -> r a0 b -> r s t Source Github #

(CopyDiscard k, Ob a) => TravRes (TensorW a :: k -> k -> Type) (CoTensorW a :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalTraversal

Methods

travP :: forall r (s :: k) (a0 :: k) (b :: k) (t :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => TensorW a s a0 -> CoTensorW a b t -> r a0 b -> r s t Source Github #

besideTensor :: forall {k} (a :: k) (b :: k) (s1 :: k) (t1 :: k) (s2 :: k) (t2 :: k). (Monoidal k, Ob a, Ob b) => ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b s1 t1 -> ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b s2 t2 -> ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b (s1 ** s2) (t1 ** t2) Source Github #

besideSum :: forall {k} (a :: k) (b :: k) (s1 :: k) (t1 :: k) (s2 :: k) (t2 :: k). (HasBinaryCoproducts k, Ob a, Ob b) => ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b s1 t1 -> ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b s2 t2 -> ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b (s1 || s2) (t1 || t2) Source Github #

besideTensorT :: forall {k} (a :: k) (b :: k) (s1 :: k) (t1 :: k) (s2 :: k) (t2 :: k). (Monoidal k, Ob a, Ob b) => ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b s1 t1 -> ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b s2 t2 -> ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b (s1 ** s2) (t1 ** t2) Source Github #

TravRes copy of besideTensor. Kept as a separate concrete function (rather than generalizing besideTensor over the flavor) to avoid destabilizing the solver.

besideSumT :: forall {k} (a :: k) (b :: k) (s1 :: k) (t1 :: k) (s2 :: k) (t2 :: k). (HasBinaryCoproducts k, Ob a, Ob b) => ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b s1 t1 -> ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b s2 t2 -> ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) 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-flavored traversal at the free monoidal-traversal profunctor ExOptic MonTravRes. Because that carrier's MonStrong instance uses the tensor-strength witness TensorW (not a product lens), this needs no Cartesian (tensor = product), only CopyDiscard (a discard a ~> Unit for the residual) -- which is exactly what the coproduct-prism side (Strong CoprodAction (ExOptic MonTravRes)) already demanded, so no constraint is added beyond relaxing Cartesian to CopyDiscard -- enabling e.g. the biproduct categories Mat and FinRel (but not LINEAR, which cannot discard). A Traversal is recovered for free wherever one is needed, since MonTravRes@ is a SubFlavor of TravRes.

monTraverseOf :: forall {k} (w :: FLAVOR k k) (s :: k) (t :: k) (a :: k) (b :: k) p. (Distributive k, StrongDistributiveProfunctor p, SubFlavor w (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint)) => Optic (Prostrong w) 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.

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 -- exactly 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 van-Laarhoven / profunctor-class form, by instantiating the rank-2 function at the free full-traversal profunctor ExOptic TravRes (an StrongDistributiveProfunctor and Strong ProdAction, unlike ExOptic MonTravRes). 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

IsOptic (StrongDistributiveProfunctor :: (j +-> j) -> Constraint) Source Github # 
Instance details

Methods

withProfunctor :: forall (p :: j +-> j) r. StrongDistributiveProfunctor p => (Profunctor p => r) -> r Source Github #

(CopyDiscard k, Ob a, Ob b) => Strong (Tensor :: k -> (k, k) -> Type) (ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b :: k -> k -> Type) Source Github # 
Instance details

Methods

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

(CopyDiscard k, Ob a, Ob b) => Strong (Tensor :: k -> (k, k) -> Type) (ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b :: k -> k -> Type) Source Github # 
Instance details

Methods

act :: forall (a0 :: k) (x :: k) (y :: k). Ob a0 => ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b x y -> ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) 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) => MonoidalProfunctor (ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b :: k -> k -> Type) Source Github # 
Instance details

Methods

one :: ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b (Unit :: k) (Unit :: k) Source Github #

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

(Monoidal k, Ob a, Ob b) => MonoidalProfunctor (ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b :: k -> k -> Type) Source Github # 
Instance details

Methods

one :: ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b (Unit :: k) (Unit :: k) Source Github #

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

(HasCoproducts k, CopyDiscard k, Ob a, Ob b) => Strong (CoprodAction :: k -> (COPROD k, k) -> Type) (ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b :: k -> k -> Type) Source Github # 
Instance details

Methods

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

(HasCoproducts k, CopyDiscard k, Ob a, Ob b) => Strong (CoprodAction :: k -> (COPROD k, k) -> Type) (ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b :: k -> k -> Type) Source Github # 
Instance details

Methods

act :: forall (a0 :: COPROD k) (x :: k) (y :: k). Ob a0 => ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b x y -> ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) 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) => Strong (ProdAction :: k -> (PROD k, k) -> Type) (ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b :: k -> k -> Type) Source Github # 
Instance details

Methods

act :: forall (a0 :: PROD k) (x :: k) (y :: k). Ob a0 => ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b x y -> ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) 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) => MonoidalProfunctor (Coprod (ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b) :: COPROD k -> COPROD k -> Type) Source Github # 
Instance details

Methods

one :: Coprod (ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) 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 (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b) x1 x2 -> Coprod (ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b) y1 y2 -> Coprod (ExOptic (MonTravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b) (x1 ** y1) (x2 ** y2) Source Github #

(HasCoproducts k, Ob a, Ob b) => MonoidalProfunctor (Coprod (ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b) :: COPROD k -> COPROD k -> Type) Source Github # 
Instance details

Methods

one :: Coprod (ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) 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 (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b) x1 x2 -> Coprod (ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b) y1 y2 -> Coprod (ExOptic (TravRes :: (k +-> k) -> (k +-> k) -> Constraint) a b) (x1 ** y1) (x2 ** y2) Source Github #