| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Proarrow.Optic.Traversal
Description
The traversal: the many-focus optic, distributing any
StrongDistributiveProfunctor with product strength
through the foci. This module keeps the mutually-recursive TravFl/MonTravFl flavor
classes and their leaf witnesses (Traversable and Cotraversable functors, the product lens,
the coproduct prism, Beside/BesideSum juxtaposition and the unit/zero witnesses). The
free-profunctor apparatus lives in Proarrow.Optic.MonoidalTraversal. A traversal subtypes to
Fold and Setter. Build with traversed (from a
Traversable), fromTravVL (from a Prelude traversal) or
traversal (from the profunctor-class form), eliminate with
traverseOf.
Synopsis
- class (SetterFl p q, FoldFl p q) => TravFl (p :: k +-> k) (q :: k +-> k) where
- travP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => p s a -> q b t -> r a b -> r s t
- class TravFl p q => MonTravFl (p :: k +-> k) (q :: k +-> k) where
- monTravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). StrongDistributiveProfunctor r => p s a -> q b t -> r a b -> r s t
- type Traversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (TravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Traversal' (s :: k) (a :: k) = Traversal s s a a
- traverseOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) p. (Distributive k, StrongDistributiveProfunctor p, Strong (ProdAction :: k -> (PROD k, k) -> Type) p, (Ob a, Ob b) => c (ExOptic (TravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> p a b -> p s t
- traversed :: forall {k} (t :: k +-> k) (a :: k) (b :: k). (Distributive k, CopyDiscard k, Traversable t, Representable t, Ob a, Ob b) => Traversal (t % a) (t % b) a b
- type Beside (p1 :: k +-> k) (p2 :: k +-> k) = (Rep (MultRep :: k -> (k, k) -> Type) :.: (p1 :**: p2)) :.: Rep (Diag :: k +-> (k, k))
- type CoBeside (q1 :: k +-> k) (q2 :: k +-> k) = (Corep (Diag :: k +-> (k, k)) :.: (q1 :**: q2)) :.: Corep (MultRep :: k -> (k, k) -> Type)
- type BesideSum (p1 :: k +-> k) (p2 :: k +-> k) = (Rep (PlusRep :: k -> (k, k) -> Type) :.: (p1 :**: p2)) :.: Rep (Diag :: k +-> (k, k))
- type CoBesideSum (q1 :: k +-> k) (q2 :: k +-> k) = (Corep (Diag :: k +-> (k, k)) :.: (q1 :**: q2)) :.: Corep (PlusRep :: k -> (k, k) -> Type)
- data UnitW (s :: k) (x :: k) where
- data CoUnitW (x :: k) (t :: k) where
- data ZeroW (s :: k) (x :: k) where
- ZeroW :: forall {k} (x :: k) (s :: k). Ob x => (s ~> (InitialObject :: k)) -> ZeroW s x
- data CoZeroW (x :: k) (t :: k) where
- CoZeroW :: forall {k} (x :: k) (t :: k). Ob x => ((InitialObject :: k) ~> t) -> CoZeroW x t
- newtype Baz t b a = Baz {
- runBaz :: forall (f :: Type -> Type). Applicative f => (a -> f b) -> f t
- newtype Bazaar a b t = Bazaar (forall (f :: Type -> Type). Applicative f => (a -> f b) -> f t)
- sold :: Baz t b b -> t
- fromTravVL :: forall s t a b. (forall (f :: Type -> Type). Applicative f => (a -> f b) -> s -> f t) -> Traversal s t a b
Documentation
class (SetterFl p q, FoldFl p q) => TravFl (p :: k +-> k) (q :: k +-> k) where Source Github #
Minimal complete definition
Nothing
Methods
travP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => p s a -> q b t -> r a b -> r s t Source Github #
Distribute a traversal-strength profunctor. Only the product-lens witness needs
(to carry the residual through the categorical product). Every other
witness distributes a plain Strong ProdActionStrongDistributiveProfunctor and inherits travP from monTravP.
Instances
| (Distributive k, CopyDiscard k, Traversable t, Representable t) => TravFl (t :: k +-> k) (RepCostar t :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal Methods travP :: forall r (s :: k) (a :: k) (b :: k) (t0 :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => t s a -> RepCostar t b t0 -> r a b -> r s t0 Source Github # | |
| Monoidal k => TravFl (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| HasInitialObject k => TravFl (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| CategoryOf k => TravFl (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| (Monoidal k, SNatI n) => TravFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.PowerGrate | |
| (Distributive k, CopyDiscard k, Cotraversable t, Corepresentable t) => TravFl (CorepStar t :: k -> k -> Type) (t :: k +-> k) Source Github # | A corepresentable |
Defined in Proarrow.Optic.Traversal Methods travP :: forall r (s :: k) (a :: k) (b :: k) (t0 :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => CorepStar t s a -> t b t0 -> r a b -> r s t0 Source Github # | |
| (TravFl p1 q1, TravFl p2 q2, Monoidal k) => TravFl (Beside p1 p2 :: k -> k -> Type) (CoBeside q1 q2 :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| (TravFl p1 q1, TravFl p2 q2, HasBinaryCoproducts k) => TravFl (BesideSum p1 p2 :: k -> k -> Type) (CoBesideSum q1 q2 :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal Methods travP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => BesideSum p1 p2 s a -> CoBesideSum q1 q2 b t -> r a b -> r s t Source Github # | |
| Comonoid m => TravFl (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| (CopyDiscard k, HasCoproducts k, Ob t) => TravFl (Rep (Coproduct t) :: k -> k -> Type) (Corep (Coproduct t) :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| (HasBinaryProducts k, Ob s) => TravFl (Rep (Product s) :: k -> k -> Type) (Corep (Product s) :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| (TravFl f g, TravFl f' g') => TravFl (f :.: f' :: i -> i -> Type) (g' :.: g :: i -> i -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
class TravFl p q => MonTravFl (p :: k +-> k) (q :: k +-> k) where Source Github #
A monoidal traversal sits between PowerGrate and
Traversal: it distributes any StrongDistributiveProfunctor without the product-strength a
lens-as-traversal needs. Every traversal witness except the product lens is a monoidal traversal.
Methods
monTravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). StrongDistributiveProfunctor r => p s a -> q b t -> r a b -> r s t Source Github #
Instances
type Traversal (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (TravFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
type Traversal' (s :: k) (a :: k) = Traversal s s a a Source Github #
traverseOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) p. (Distributive k, StrongDistributiveProfunctor p, Strong (ProdAction :: k -> (PROD k, k) -> Type) p, (Ob a, Ob b) => c (ExOptic (TravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> p a b -> p s t Source Github #
Distribute any StrongDistributiveProfunctor (not only a Star f, the van-Laarhoven shape)
through any optic that is at least a Traversal, by handing it to travP.
The optic may be in any encoding: the constraint asks its class to hold for the generic carrier
. A ExOptic TravFl a bProstrong-flavored optic discharges it via
forall p q. w p q => , a Sub TravFl p q(%)-composite one conjunct at a
time, and a profunctor-class one (PTraversalFull) through the
carrier's by-generator instances.
traversed :: forall {k} (t :: k +-> k) (a :: k) (b :: k). (Distributive k, CopyDiscard k, Traversable t, Representable t, Ob a, Ob b) => Traversal (t % a) (t % b) a b Source Github #
Build a traversal from a Traversable (representable) functor t: it focuses every element
the functor holds. This is the one weak-flavor builder that is primitive: a
Traversables traversal is not reachable by convert from any single stronger optic. The
witness is t itself paired with (see RepCostar tTravFl above). The two legs are the
representable universal and the identity repUnivRepCostar.
The free traversal profunctor
type Beside (p1 :: k +-> k) (p2 :: k +-> k) = (Rep (MultRep :: k -> (k, k) -> Type) :.: (p1 :**: p2)) :.: Rep (Diag :: k +-> (k, k)) Source Github #
Witness pair for traversing two juxtaposed (tensored) parts in sequence, both focusing x:
Beside p1 p2 s x = exists s1 s2. (s ~> s1 ** s2, p1 s1 x, p2 s2 x)
spelled as a composite through (k, k): split the source with the tensor (),
run the witnesses side by side (Rep MultRep:**:), and identify the foci with the diagonal ().
Rep DiagDay is the same composite with in place of
the diagonal, tensoring the foci instead. Identifying them is necessary: a Day witness pair admits
no componentwise Corep MultReptravP, which would have to split a StrongDistributiveProfunctor value at a
tensor. So DayFl optics focus pairs, while this one visits both foci in turn.
type CoBeside (q1 :: k +-> k) (q2 :: k +-> k) = (Corep (Diag :: k +-> (k, k)) :.: (q1 :**: q2)) :.: Corep (MultRep :: k -> (k, k) -> Type) Source Github #
type BesideSum (p1 :: k +-> k) (p2 :: k +-> k) = (Rep (PlusRep :: k -> (k, k) -> Type) :.: (p1 :**: p2)) :.: Rep (Diag :: k +-> (k, k)) Source Github #
Witness pair for traversing one of two alternative (coproduct) parts: Beside with the tensor
replaced by the coproduct (, Rep PlusReps ~> s1 || s2, and ,
Corep PlusRept1 || t2 ~> t). Here identifying the foci and tensoring them agree, since x1 || x2 ~> x is a
pair (x1 ~> x, x2 ~> x). So this is Day convolution over the coproduct.
type CoBesideSum (q1 :: k +-> k) (q2 :: k +-> k) = (Corep (Diag :: k +-> (k, k)) :.: (q1 :**: q2)) :.: Corep (PlusRep :: k -> (k, k) -> Type) Source Github #
The covariant half of the BesideSum witness pair.
data UnitW (s :: k) (x :: k) where Source Github #
Witness pair with no foci at all: decompose to Unit and rebuild.
UnitW and CoUnitW are the halves of DayUnit, one per side,
with a phantom focus; with Beside/CoBeside they are the Day-monoidal structure on profunctors
split at the focus. The split is forced: a whole DayUnit on the decomposition side would demand
Unit ~> a for an arbitrary focus a.
Unlike Beside this is not a composite: the nullary analogue would pass through the unit
category (), which can coincide with k and so overlap the generic composition instances.
Instances
| Monoidal k => Profunctor (UnitW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal Methods dimap :: forall (c :: k) (a :: k) (b :: k) (d :: k). (c ~> a) -> (b ~> d) -> UnitW a b -> UnitW c d Source Github # lmap :: forall (c :: k) (a :: k) (b :: k). (c ~> a) -> UnitW a b -> UnitW c b Source Github # rmap :: forall (b :: k) (d :: k) (a :: k). (b ~> d) -> UnitW a b -> UnitW a d Source Github # (\\) :: forall (a :: k) (b :: k) r. ((Ob a, Ob b) => r) -> UnitW a b -> r Source Github # | |
| Monoidal k => Proadjunction (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
| Monoidal k => FoldFl (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
| Monoidal k => SetterFl (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
| Monoidal k => MonTravFl (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| Monoidal k => TravFl (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
data CoUnitW (x :: k) (t :: k) where Source Github #
Instances
| Monoidal k => Profunctor (CoUnitW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal Methods dimap :: forall (c :: k) (a :: k) (b :: k) (d :: k). (c ~> a) -> (b ~> d) -> CoUnitW a b -> CoUnitW c d Source Github # lmap :: forall (c :: k) (a :: k) (b :: k). (c ~> a) -> CoUnitW a b -> CoUnitW c b Source Github # rmap :: forall (b :: k) (d :: k) (a :: k). (b ~> d) -> CoUnitW a b -> CoUnitW a d Source Github # (\\) :: forall (a :: k) (b :: k) r. ((Ob a, Ob b) => r) -> CoUnitW a b -> r Source Github # | |
| Monoidal k => Proadjunction (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
| Monoidal k => FoldFl (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
| Monoidal k => SetterFl (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
| Monoidal k => MonTravFl (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| Monoidal k => TravFl (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
data ZeroW (s :: k) (x :: k) where Source Github #
Witness pair for the impossible case: decompose to the initial object. These are the halves of
the (unspelled) unit of Day convolution over the coproduct monoidal structure, cf.
UnitW/CoUnitW.
Constructors
| ZeroW :: forall {k} (x :: k) (s :: k). Ob x => (s ~> (InitialObject :: k)) -> ZeroW s x |
Instances
| HasInitialObject k => Profunctor (ZeroW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal Methods dimap :: forall (c :: k) (a :: k) (b :: k) (d :: k). (c ~> a) -> (b ~> d) -> ZeroW a b -> ZeroW c d Source Github # lmap :: forall (c :: k) (a :: k) (b :: k). (c ~> a) -> ZeroW a b -> ZeroW c b Source Github # rmap :: forall (b :: k) (d :: k) (a :: k). (b ~> d) -> ZeroW a b -> ZeroW a d Source Github # (\\) :: forall (a :: k) (b :: k) r. ((Ob a, Ob b) => r) -> ZeroW a b -> r Source Github # | |
| HasInitialObject k => Proadjunction (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
| HasInitialObject k => FoldFl (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
| HasInitialObject k => SetterFl (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
| HasInitialObject k => MonTravFl (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| HasInitialObject k => TravFl (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
data CoZeroW (x :: k) (t :: k) where Source Github #
The covariant half of the ZeroW witness pair: rebuilds the target from InitialObject.
Constructors
| CoZeroW :: forall {k} (x :: k) (t :: k). Ob x => ((InitialObject :: k) ~> t) -> CoZeroW x t |
Instances
| HasInitialObject k => Profunctor (CoZeroW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal Methods dimap :: forall (c :: k) (a :: k) (b :: k) (d :: k). (c ~> a) -> (b ~> d) -> CoZeroW a b -> CoZeroW c d Source Github # lmap :: forall (c :: k) (a :: k) (b :: k). (c ~> a) -> CoZeroW a b -> CoZeroW c b Source Github # rmap :: forall (b :: k) (d :: k) (a :: k). (b ~> d) -> CoZeroW a b -> CoZeroW a d Source Github # (\\) :: forall (a :: k) (b :: k) r. ((Ob a, Ob b) => r) -> CoZeroW a b -> r Source Github # | |
| HasInitialObject k => Proadjunction (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
| HasInitialObject k => FoldFl (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
| HasInitialObject k => SetterFl (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
| HasInitialObject k => MonTravFl (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
| HasInitialObject k => TravFl (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Traversal | |
Van Laarhoven traversals
newtype Baz t b a Source Github #
The van Laarhoven form of a traversal with target t and new focus b, as a functor of the
old focus a: run with any applicative handling of the foci.
Constructors
| Baz | |
Fields
| |
Instances
| Functor (Baz t b) Source Github # | |
| Foldable (Baz t b) Source Github # | |
Defined in Proarrow.Optic.Traversal Methods fold :: Monoid m => Baz t b m -> m Github # foldMap :: Monoid m => (a -> m) -> Baz t b a -> m Github # foldMap' :: Monoid m => (a -> m) -> Baz t b a -> m Github # foldr :: (a -> b0 -> b0) -> b0 -> Baz t b a -> b0 Github # foldr' :: (a -> b0 -> b0) -> b0 -> Baz t b a -> b0 Github # foldl :: (b0 -> a -> b0) -> b0 -> Baz t b a -> b0 Github # foldl' :: (b0 -> a -> b0) -> b0 -> Baz t b a -> b0 Github # foldr1 :: (a -> a -> a) -> Baz t b a -> a Github # foldl1 :: (a -> a -> a) -> Baz t b a -> a Github # toList :: Baz t b a -> [a] Github # null :: Baz t b a -> Bool Github # length :: Baz t b a -> Int Github # elem :: Eq a => a -> Baz t b a -> Bool Github # maximum :: Ord a => Baz t b a -> a Github # minimum :: Ord a => Baz t b a -> a Github # | |
| Traversable (Baz t b) Source Github # | Handle the foci, keeping the rest of the traversal: run at |
Defined in Proarrow.Optic.Traversal | |
newtype Bazaar a b t Source Github #
Constructors
| Bazaar (forall (f :: Type -> Type). Applicative f => (a -> f b) -> f t) |
Instances
| Applicative (Bazaar a b) Source Github # | |
Defined in Proarrow.Optic.Traversal Methods pure :: a0 -> Bazaar a b a0 Github # (<*>) :: Bazaar a b (a0 -> b0) -> Bazaar a b a0 -> Bazaar a b b0 Github # liftA2 :: (a0 -> b0 -> c) -> Bazaar a b a0 -> Bazaar a b b0 -> Bazaar a b c Github # (*>) :: Bazaar a b a0 -> Bazaar a b b0 -> Bazaar a b b0 Github # (<*) :: Bazaar a b a0 -> Bazaar a b b0 -> Bazaar a b a0 Github # | |
| Functor (Bazaar a b) Source Github # | |
sold :: Baz t b b -> t Source Github #
Rebuild the target once every focus has its new type: run at Identity.
fromTravVL :: forall s t a b. (forall (f :: Type -> Type). Applicative f => (a -> f b) -> s -> f t) -> Traversal s t a b Source Github #
Orphan instances
| (FoldFl p1 q1, FoldFl p2 q2, Monoidal k) => FoldFl (Beside p1 p2 :: k -> k -> Type) (CoBeside q1 q2 :: k -> k -> Type) Source Github # | |
| (FoldFl p1 q1, FoldFl p2 q2, HasBinaryCoproducts k) => FoldFl (BesideSum p1 p2 :: k -> k -> Type) (CoBesideSum q1 q2 :: k -> k -> Type) Source Github # | |
| Comonoid m => FoldFl (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) Source Github # | The tensor-action witness pair |
| (SetterFl p1 q1, SetterFl p2 q2, Monoidal k) => SetterFl (Beside p1 p2 :: k -> k -> Type) (CoBeside q1 q2 :: k -> k -> Type) Source Github # | |
| (SetterFl p1 q1, SetterFl p2 q2, HasBinaryCoproducts k) => SetterFl (BesideSum p1 p2 :: k -> k -> Type) (CoBesideSum q1 q2 :: k -> k -> Type) Source Github # | |