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 #

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

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

_1 :: forall {k} (a :: k) (b :: k) (c :: k). (SymMonoidal k, Ob a, Ob b, Ob c) => MonoidalOptic (a ** c) (b ** c) a b Source Github #

_2 :: forall {k} (a :: k) (b :: k) (c :: k). (SymMonoidal k, Ob a, Ob b, Ob c) => MonoidalOptic (c ** a) (c ** b) a b Source Github #

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 % - (Proarrow.Promonad): a structure map m % a ~> a, coherent with the monad's unit and multiplication. The free algebras m % s are the ones an algebraic lens is built from (algebraicLens).

There are deliberately no instances for the unit or for products of algebras, and there cannot be: Unit and (**) are type families, which may not head an instance. That is why withAlgP passes the structure map as a value -- the composition instance pairs two algebras with unparRep and the identity witness supplies the unit one with unpar0Rep, neither needing an Algebra instance. A witness pair whose residual is the unit is the identity optic up to the unitors, so nothing is lost.

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. The flavor itself asks only that the functor m % be oplax monoidal, enough to pair and discard residuals; the monad structure arrives with each Algebra witness, not with the flavor. The algebra is what lets put see a whole m-computation of sources rather than one: classifyOf collapses m % s to a single residual through it. Every algebraic lens is a MonoidalLens (the MonLensFl superclass: the residual is a comonoid), so it views, sets, folds and traverses as a lens does. withAlgP hands the algebra over as a value, so composites pair algebras without an instance for the product.

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 -- rather than 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 -- generalizing "set" to combine every s the computation might produce (via its residual's Algebra) rather than 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), the meet of the two flavors. This is what lets it compose with a kaleidoscope to a kaleidoscope again (Clarke et al., Remark 3.28): a lens composed with a kaleidoscope is not a kaleidoscope, since a product functor is not applicative, but a product by a monoid is. The algebra and the monoid on the residual are assumed to agree, as they do for the free algebra l % s of the list monad (join and ++) that classifyingLens uses.

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.