proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.Action

Description

Optics for an arbitrary MonoidalAction: the ActFl flavor, whose witness pair is a matched pair of arrows into/out of the action at some residual; its specialisation to the tensor's self-action gives MonoidalOptic. Also home to the __algebraic lens__ (AlgLensFl), the tensor-action pair with an Algebra-for-a-monad residual, and its list-monad case, the classifying lens (ClassifyFl), which is moreover a kaleidoscope.

Synopsis

Documentation

class (MonoidalAction act, Profunctor p, Profunctor q) => ActFl (act :: (m, k) +-> k) (p :: k +-> k) (q :: k +-> k) where Source Github #

Any MonoidalAction gives rise to a flavor: the witness pair is a matched pair of arrows into/out of the action for some shared, existentially hidden index x. LensFl/PrismFl are (unspelled-out) special cases of this for ProdAction/CoprodAction.

Methods

withActP :: forall (s :: k) (a :: k) (b :: k) (t :: k) r. p s a -> q b t -> (forall (x :: m). Ob x => (s ~> Act act x a) -> (Act act x b ~> t) -> r) -> r Source Github #

Instances

Instances details
MonoidalAction act => ActFl (act :: (m, k) +-> k) (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Action

Methods

withActP :: forall (s :: k) (a :: k) (b :: k) (t :: k) r. Id s a -> Id b t -> (forall (x :: m). Ob x => (s ~> Act act x a) -> (Act act x b ~> t) -> r) -> r Source Github #

(MonoidalAction act, Ob x) => ActFl (act :: (m, j) +-> j) (Rep (ActionAt act x) :: j -> j -> Type) (Corep (ActionAt act x) :: j -> j -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Action

Methods

withActP :: forall (s :: j) (a :: j) (b :: j) (t :: j) r. Rep (ActionAt act x) s a -> Corep (ActionAt act x) b t -> (forall (x0 :: m). Ob x0 => (s ~> Act act x0 a) -> (Act act x0 b ~> t) -> r) -> r Source Github #

(ActFl act f g, ActFl act f' g') => ActFl (act :: (m, i) +-> i) (f :.: f' :: i -> i -> Type) (g' :.: g :: i -> i -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Action

Methods

withActP :: forall (s :: i) (a :: i) (b :: i) (t :: i) r. (f :.: f') s a -> (g' :.: g) b t -> (forall (x :: m). Ob x => (s ~> Act act x a) -> (Act act x b ~> t) -> r) -> r Source Github #

runMonoidalOptic :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (SymMonoidal k, (Ob a, Ob b) => c (ExOptic (ActFl (Tensor :: k -> (k, k) -> Type)) a b)) => Optic c s t a b -> (s ** b) ~> (a ** t) Source Github #

Connect a tensor-action optic's forward and backward passes. The forward pass produces the focus a and a residual, which the backward pass consumes together with b to produce t. The residual is used once; no copying, discarding or tracing is required.

class (Monad m, Ob a) => Algebra (m :: k +-> k) (a :: k) where Source Github #

An Eilenberg-Moore algebra for the monad m (a representable Promonad on k, acting as the functor m % -, see Proarrow.Promonad): a structure map m % a ~> a, coherent with the monad's unit and multiplication. The free algebras m % s are the ones algebraicLens uses.

Unit and (**) are type families, which may not head an instance, so there are no instances for the unit or for products of algebras. withAlgP passes the structure map as a value instead, and the witnesses combine those with unparRep and unpar0Rep.

Methods

algebra :: (m % a) ~> a Source Github #

Instances

Instances details
(Monad (Star m), Ob (m a), Ob a) => Algebra (Star m :: k -> k -> Type) (m a :: k) Source Github #

The free algebras of a monad m, wrapped as the representable promonad Star m.

Instance details

Defined in Proarrow.Optic.Action

Methods

algebra :: (Star m % m a) ~> m a Source Github #

class (OplaxMonoidalRep m, MonLensFl p q) => AlgLensFl (m :: k +-> k) (p :: k +-> k) (q :: k +-> k) where Source Github #

The algebraic-lens flavor (Riley, Categories of Optics; Clarke et al.): the tensor-action witness pair Rep/Corep (ActionAt Tensor x) of Proarrow.Optic.MonoidalLens (legs s ~> x ** a and x ** b ~> t), with the residual x an Algebra for m. Through the algebra put sees a whole m-computation of sources: classifyOf collapses m % s to a single residual. The flavor asks only that m % be oplax monoidal, to pair and discard residuals; the monad structure comes with each Algebra witness. Every algebraic lens is a MonoidalLens (MonLensFl superclass), so it views, sets, folds and traverses as a lens does.

Methods

withAlgP :: forall (s :: k) (a :: k) (b :: k) (t :: k) r. p s a -> q b t -> (forall (x :: k). Ob x => ((m % x) ~> x) -> (s ~> (x ** a)) -> ((x ** b) ~> t) -> r) -> r Source Github #

Recover the two legs and the algebra of the (existential) residual x.

Instances

Instances details
OplaxMonoidalRep m => AlgLensFl (m :: k +-> k) (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Action

Methods

withAlgP :: forall (s :: k) (a :: k) (b :: k) (t :: k) r. Id s a -> Id b t -> (forall (x :: k). Ob x => ((m % x) ~> x) -> (s ~> (x ** a)) -> ((x ** b) ~> t) -> r) -> r Source Github #

(OplaxMonoidalRep m, Algebra m x, Comonoid x) => AlgLensFl (m :: k +-> k) (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) x) :: k -> k -> Type) (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) x) :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Action

Methods

withAlgP :: forall (s :: k) (a :: k) (b :: k) (t :: k) r. Rep (ActionAt (Tensor :: k -> (k, k) -> Type) x) s a -> Corep (ActionAt (Tensor :: k -> (k, k) -> Type) x) b t -> (forall (x0 :: k). Ob x0 => ((m % x0) ~> x0) -> (s ~> (x0 ** a)) -> ((x0 ** b) ~> t) -> r) -> r Source Github #

(AlgLensFl m f g, AlgLensFl m f' g') => AlgLensFl (m :: k +-> k) (f :.: f' :: k -> k -> Type) (g' :.: g :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Action

Methods

withAlgP :: forall (s :: k) (a :: k) (b :: k) (t :: k) r. (f :.: f') s a -> (g' :.: g) b t -> (forall (x :: k). Ob x => ((m % x) ~> x) -> (s ~> (x ** a)) -> ((x ** b) ~> t) -> r) -> r Source Github #

type AlgebraicLens (m :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (AlgLensFl m)) s t a b Source Github #

An algebraic lens: like a Lens, but put is allowed to combine information monadically (get :: s ~> a, put :: m % s ** b ~> t) instead of only ever seeing the last s.

algebraicLens :: forall {k} (m :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Algebra m (m % s), Comonoid (m % s), Comonoid s, OplaxMonoidalRep m, Ob a, Ob b) => (s ~> a) -> (((m % s) ** b) ~> t) -> AlgebraicLens m s t a b Source Github #

Build an algebraic lens from get and a monadic put; the residual is the free algebra m % s itself (which must be a comonoid, as must s to be kept alongside its focus).

classifyOf :: forall {k} (m :: k +-> k) (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (OplaxMonoidalRep m, Comonoid a, (Ob a, Ob b) => c (ExOptic (AlgLensFl m) a b)) => Optic c s t a b -> ((m % s) ** b) ~> t Source Github #

Classify a monadic computation of s's through an AlgebraicLens (or any stronger optic, in any encoding), given a replacement focus b. This generalizes "set" to combine every s the computation might produce (via its residual's Algebra) instead of only ever seeing the last one. The focus a is discarded under the monad, hence must be a comonoid.

(.?) :: forall f (c :: (Type -> Type -> Type) -> Constraint) s t a b. (Monad f, Functor f, c (ExOptic (AlgLensFl (Star f)) a b)) => Optic c s t a b -> b -> f s -> t infixl 8 Source Github #

classifyOf for a Haskell monad, curried: optic .? b $ fs.

class (AlgLensFl l p q, KaleidoFl p q) => ClassifyFl (l :: k +-> k) (p :: k +-> k) (q :: k +-> k) Source Github #

The classifying lens (Clarke et al., Example 3.11): the algebraic lens for the list monad, here for any monad l whose algebras are monoids. Tensoring with a monoid is an applicative functor (the writer applicative), so a classifying lens is also a kaleidoscope (KaleidoFl), and composes with a kaleidoscope to a kaleidoscope (Clarke et al., Remark 3.28), which a plain lens does not. The algebra and the monoid on the residual are assumed to agree, as they do for the free list algebra l % s (join and ++).

Instances

Instances details
OplaxMonoidalRep l => ClassifyFl (l :: k +-> k) (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Action

(OplaxMonoidalRep l, Algebra l x, Monoid x, Comonoid x, SymMonoidal k, HasCoproducts k) => ClassifyFl (l :: k +-> k) (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) x) :: k -> k -> Type) (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) x) :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Action

(ClassifyFl l f g, ClassifyFl l f' g') => ClassifyFl (l :: i +-> i) (f :.: f' :: i -> i -> Type) (g' :.: g :: i -> i -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Action

type ClassifyingLens (l :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (ClassifyFl l)) s t a b Source Github #

classifyingLens :: forall {k} (l :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Algebra l (l % s), Monoid (l % s), Comonoid (l % s), Comonoid s, OplaxMonoidalRep l, SymMonoidal k, HasCoproducts k, Ob a, Ob b) => (s ~> a) -> (((l % s) ** b) ~> t) -> ClassifyingLens l s t a b Source Github #

Build a classifying lens from get and a classify :: l % s ** b ~> t; the residual is the free algebra l % s, e.g. the list of sources.

type MonoidalOptic (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (ActFl (Tensor :: k -> (k, k) -> Type))) s t a b Source Github #

Tensor-action optics without a copying/discarding requirement on the residual.

monoidalOptic :: forall {k} (m :: k) (s :: k) (t :: k) (a :: k) (b :: k). (Monoidal k, Ob m, Ob a, Ob b) => (s ~> (m ** a)) -> ((m ** b) ~> t) -> MonoidalOptic s t a b Source Github #