proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.Glass

Description

The glass (Clarke et al., Profunctor optics: a categorical update): the optic for the combined action of the product and the exponential,

Glass s t a b = exists c d. (s ~> c && (d ~~> a), (c && (d ~~> b)) ~> t)

which collapses to the single leg (s && ((s ~~> a) ~~> b)) ~> t: given the source and a way to turn any selector s ~~> a into a b, produce a t. A lens is the case d = Unit, a grate the case c = Unit, so GlassFl is the join of LensFl and GrateFl. Like AffineTravFl it has no witnesses of its own: its generating pairs are the product pair and the exponential pair, and glass packs its single leg as their composite.

It sits directly below SetterFl: a glass sets, but it neither folds (grates do not) nor distributes an applicative (lenses do not).

Synopsis

Documentation

class SetterFl p q => GlassFl (p :: k +-> k) (q :: k +-> k) where Source Github #

The glass flavor. Its one method is the collapsed leg; everything is stated in a cartesian closed category, where the residual can be copied and selectors can be internalised.

Methods

glassP :: forall (s :: k) (a :: k) (b :: k) (t :: k). CCC k => p s a -> q b t -> (s && Mod s a b) ~> t Source Github #

Instances

Instances details
CategoryOf k => GlassFl (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Glass

Methods

glassP :: forall (s :: k) (a :: k) (b :: k) (t :: k). CCC k => Id s a -> Id b t -> (s && Mod s a b) ~> t Source Github #

(Monoidal k, Ob m) => GlassFl (MonLensRep m :: k -> k -> Type) (MonLensCorep m :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalLens

Methods

glassP :: forall (s :: k) (a :: k) (b :: k) (t :: k). CCC k => MonLensRep m s a -> MonLensCorep m b t -> (s && Mod s a b) ~> t Source Github #

(Monoidal k, HasCoproducts k, SNatI n) => GlassFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github #

A power grate is a glass: ignore the source, and for each of the n positions feed the consumer the selector "project this focus". The selectors come from splitPow of sl, the consumer is copied n times with fanOut, powZip pairs them, and powDist applies each. Everything is stated with the CopyDiscard structure that CCC provides, so the tensor and the product never have to be identified by hand.

Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

glassP :: forall (s :: k) (a :: k) (b :: k) (t :: k). CCC k => Pow n s a -> CoPow n b t -> (s && Mod s a b) ~> t Source Github #

Comonoid m => GlassFl (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalLens

Methods

glassP :: forall (s :: k) (a :: k) (b :: k) (t :: k). CCC k => Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) s a -> Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) b t -> (s && Mod s a b) ~> t Source Github #

(Closed k, Ob d) => GlassFl (Rep (Exp d) :: k -> k -> Type) (Corep (Exp d) :: k -> k -> Type) Source Github #

The exponential pair, a grate witness: the source is ignored, and the consumer is fed the selector \s -> h s d for each point d of the exponent.

Instance details

Defined in Proarrow.Optic.Glass

Methods

glassP :: forall (s :: k) (a :: k) (b :: k) (t :: k). CCC k => Rep (Exp d) s a -> Corep (Exp d) b t -> (s && Mod s a b) ~> t Source Github #

(HasBinaryProducts k, Ob c) => GlassFl (Rep (Product c) :: k -> k -> Type) (Corep (Product c) :: k -> k -> Type) Source Github #

The product pair, a lens witness: the selector is the lens's own get, applied to the source at hand; the residual is kept.

Instance details

Defined in Proarrow.Optic.Glass

Methods

glassP :: forall (s :: k) (a :: k) (b :: k) (t :: k). CCC k => Rep (Product c) s a -> Corep (Product c) b t -> (s && Mod s a b) ~> t Source Github #

(GlassFl f g, GlassFl f' g') => GlassFl (f :.: f' :: k -> k -> Type) (g' :.: g :: k -> k -> Type) Source Github #

Composition threads the selector through: the outer glass is given the consumer \sel -> inner (sel s, \sel' -> k (sel' . sel)).

Instance details

Defined in Proarrow.Optic.Glass

Methods

glassP :: forall (s :: k) (a :: k) (b :: k) (t :: k). CCC k => (f :.: f') s a -> (g' :.: g) b t -> (s && Mod s a b) ~> t Source Github #

type Mod (s :: k) (a :: k) (b :: k) = (s ~~> a) ~~> b Source Github #

A modifier: given a selector s ~~> a for reading the focus out of the source, it produces the new focus b. It is the right half of a glass's single leg, and the whole of a grate's argument.

applySel :: forall {k} (s :: k) (a :: k) (b :: k). (Closed k, Ob s, Ob a, Ob b) => (s ~> a) -> Mod s a b ~> b Source Github #

Feed a fixed selector s ~> a to a Mod.

withObSel :: forall {k} (s :: k) (a :: k) (b :: k) r. (Closed k, Ob s, Ob a, Ob b) => ((Ob (s ~~> a), Ob (Mod s a b)) => r) -> r Source Github #

The two Ob facts every modifier needs: the selector type s ~~> a and the Mod that consumes it. Each GlassFl instance below opens with this.

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

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

evalAt :: forall {k} (s :: k) (a :: k). (Closed k, SymMonoidal k, Ob s, Ob a) => s ~> ((s ~~> a) ~~> a) Source Github #

Evaluation at a point: s goes to the functions out of it, applied to it.

glass :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (CCC k, Ob s, Ob a, Ob b) => ((s && Mod s a b) ~> t) -> Glass s t a b Source Github #

Build a glass from its single leg. The residuals are the whole source and the "logarithm" s ~~> a, so the witness is the lens witness at s composed with the grate witness at s ~~> a.

withGlass :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CCC k, (Ob a, Ob b) => c (ExOptic (GlassFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> (((s && Mod s a b) ~> t) -> r) -> r Source Github #

Eliminate any glass-flavored optic (a lens, a grate, or a composite of both, in either encoding) to its single leg.