proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.Setter

Description

The setter: the weakest write-side optic, applying a morphism to every focus (SetterRes / overP, whose Proadjunction superclass certifies the witness pair is a genuine adjoint pair, i.e. the optic is lawful). It sits at the write-only top of the subtyping lattice alongside Fold, so it has no builder of its own (convert a stronger optic); its canonical eliminator is over -- with set, (%~) and (.~) as shorthands -- via the hom carrier Id.

Synopsis

Documentation

class Proadjunction p q => SetterRes (p :: k +-> k) (q :: k +-> k) where Source Github #

A setter can only apply a pure function to the a's it can see -- it can neither view nor fold them. A traversal is both a setter and a fold.

| The Proadjunction superclass certifies that a setter's witness pair is a genuine adjoint pair -- the residual is an actual functor whose unit/counit round-trip -- i.e. the optic is lawful.

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t :: k). p s a -> q b t -> (a ~> b) -> s ~> t Source Github #

Instances

Instances details
Representable t => SetterRes (t :: k +-> k) (RepCostar t :: k -> k -> Type) Source Github #

Every representable residual is a setter: map the focus through the residual functor with repMap. This needs only Representable t -- no Traversable -- which is exactly why Setter sits at the top of the lattice: functoriality of the residual is all over ever uses. Richer optics (Lens, Traversal, ...) are this witness plus extra algebra on t.

Instance details

Defined in Proarrow.Optic.Setter

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t0 :: k). t s a -> RepCostar t b t0 -> (a ~> b) -> s ~> t0 Source Github #

Monoidal k => SetterRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t :: k). Two s a -> CoTwo b t -> (a ~> b) -> s ~> t Source Github #

Monoidal k => SetterRes (UnitW :: k -> k -> Type) (CoUnitW :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Traversal

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t :: k). UnitW s a -> CoUnitW b t -> (a ~> b) -> s ~> t Source Github #

HasInitialObject k => SetterRes (ZeroW :: k -> k -> Type) (CoZeroW :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Traversal

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t :: k). ZeroW s a -> CoZeroW b t -> (a ~> b) -> s ~> t Source Github #

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

Defined in Proarrow.Optic.Setter

Methods

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

(Monoidal k, KnownNat n) => SetterRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t :: k). Pow n s a -> CoPow n b t -> (a ~> b) -> s ~> t Source Github #

Comonoid m => SetterRes (LensW m :: k -> k -> Type) (CoLensW m :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.MonoidalLens

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t :: k). LensW m s a -> CoLensW m b t -> (a ~> b) -> s ~> t 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 #

Corepresentable t => SetterRes (CorepStar t :: k -> k -> Type) (t :: k +-> k) Source Github #

Dually, every corepresentable residual is a setter: map with corepMap. Needs only Corepresentable t, not Cotraversable.

Instance details

Defined in Proarrow.Optic.Setter

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t0 :: k). CorepStar t s a -> t b t0 -> (a ~> b) -> s ~> t0 Source Github #

(SetterRes p1 q1, SetterRes p2 q2, Monoidal k) => SetterRes (Beside p1 p2 :: k -> k -> Type) (CoBeside q1 q2 :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Traversal

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t :: k). Beside p1 p2 s a -> CoBeside q1 q2 b t -> (a ~> b) -> s ~> t Source Github #

(SetterRes p1 q1, SetterRes p2 q2, HasBinaryCoproducts k) => SetterRes (BesideSum p1 p2 :: k -> k -> Type) (CoBesideSum q1 q2 :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Traversal

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t :: k). BesideSum p1 p2 s a -> CoBesideSum q1 q2 b t -> (a ~> b) -> s ~> t Source Github #

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

The grate witness is a setter witness: map under the exponential. The Closed structure this needs rides in the instance context, not in overP's own (weaker) constraint.

Instance details

Defined in Proarrow.Optic.Setter

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t :: k). Rep (Exp m) s a -> Corep (Exp m) b t -> (a ~> b) -> s ~> t Source Github #

(HasCoproducts k, Ob t) => SetterRes (Rep (Coproduct t) :: k -> k -> Type) (Corep (Coproduct t) :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Setter

Methods

overP :: forall (s :: k) (a :: k) (b :: k) (t0 :: k). Rep (Coproduct t) s a -> Corep (Coproduct t) b t0 -> (a ~> b) -> s ~> t0 Source Github #

(HasBinaryProducts k, Ob s) => SetterRes (Rep (Product s) :: k -> k -> Type) (Corep (Product s) :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Setter

Methods

overP :: forall (s0 :: k) (a :: k) (b :: k) (t :: k). Rep (Product s) s0 a -> Corep (Product s) b t -> (a ~> b) -> s0 ~> t Source Github #

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

Defined in Proarrow.Optic.Setter

Methods

overP :: forall (s :: i) (a :: i) (b :: i) (t :: i). (f :.: f') s a -> (g' :.: g) b t -> (a ~> b) -> s ~> t Source Github #

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

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

over :: forall {k} (c :: (k +-> k) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). c (Id :: k -> k -> Type) => Optic c s t a b -> (a ~> b) -> s ~> t Source Github #

Map over any optic that can act as a setter, in either encoding: a Prostrong-flavored optic needs SubFlavor w SetterRes (discharged by the bridge instance above), a profunctor-class-flavored optic needs its class to hold for Id.

(%~) :: forall (c :: (Type +-> Type) -> Constraint) s t a b. c (Id :: Type -> Type -> Type) => Optic c s t a b -> (a -> b) -> s -> t infixl 8 Source Github #

Apply a function through a concrete, Type-level Setter.

(.~) :: forall (c :: (Type +-> Type) -> Constraint) s t a b. c (Id :: Type -> Type -> Type) => Optic c s t a b -> b -> s -> t infixl 8 Source Github #

Replace the focus/foci of a concrete, Type-level Setter with a constant value.

set :: forall (c :: (Type +-> Type) -> Constraint) s t a b. c (Id :: Type -> Type -> Type) => Optic c s t a b -> b -> s -> t Source Github #

Named version of (.~).

mupdate :: Monad m => Setter ('KL s :: KLEISLI (Star (Prelude m))) ('KL t :: KLEISLI (Star (Prelude m))) ('KL a :: KLEISLI (Star (Prelude m))) ('KL b :: KLEISLI (Star (Prelude m))) -> b -> s -> m t Source Github #

Monadically replace the focus/foci of a Setter in the Kleisli category of m with a constant value, ignoring the old contents entirely.

Orphan instances

(CategoryOf k, SubFlavor w (SetterRes :: (k +-> k) -> (k +-> k) -> Constraint)) => Prostrong (w :: FLAVOR k k) (Id :: k -> k -> Type) Source Github #

Any flavor whose optics can set has strength for the hom carrier Id.

Instance details

Methods

proact :: forall (f :: k +-> k) (g :: k +-> k). (w f g, Profunctor f, Profunctor g) => ((f :.: (Id :: k -> k -> Type)) :.: g) :~> (Id :: k -> k -> Type) Source Github #