proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.Setter

Description

The setter: the weakest write-side optic, applying a morphism to every focus (SetterFl / overP). 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, via the generic ExOptic carrier, with set, (%~) and (.~) as shorthands.

This module also hosts the SetterFl instance of the tensor-action witness pair Rep/Corep (ActionAt Tensor a), shared by Proarrow.Optic.MonoidalTraversal and Proarrow.Optic.Tracer.

Synopsis

Documentation

class (Profunctor p, Profunctor q) => SetterFl (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.

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 => SetterFl (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, not Traversable, which is 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 => SetterFl (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 => SetterFl (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 => SetterFl (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, SNatI n) => SetterFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

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 #

Corepresentable t => SetterFl (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 #

(SetterFl p1 q1, SetterFl p2 q2, Monoidal k) => SetterFl (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 #

(SetterFl p1 q1, SetterFl p2 q2, HasBinaryCoproducts k) => SetterFl (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 #

(TracedMonoidal k, Ob m) => SetterFl (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) Source Github #

The tracer witness: the tensor-action pair read the other way round, Corep (ActionAt Tensor m) on the left and Rep (ActionAt Tensor m) on the right. Its overP is the trace of m ** s ~> a ~> b ~> m ** t over m, so it needs the category to be TracedMonoidal.

Instance details

Defined in Proarrow.Optic.Tracer

Methods

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

(Monoidal k, Ob a) => SetterFl (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) a) :: k -> k -> Type) (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) a) :: k -> k -> Type) Source Github #

The tensor-action witness pair Rep/Corep (ActionAt Tensor a): the focus x sits inside a ** x with the residual a carried on the left (legs s ~> a ** x and a ** x ~> t). It is a setter witness by mapping under the tensor, and the tensor-strength generator for the free traversal profunctor (see Proarrow.Optic.MonoidalTraversal); read the other way round it is the tracer witness (see Proarrow.Optic.Tracer).

Instance details

Defined in Proarrow.Optic.Setter

Methods

overP :: forall (s :: k) (a0 :: k) (b :: k) (t :: k). Rep (ActionAt (Tensor :: k -> (k, k) -> Type) a) s a0 -> Corep (ActionAt (Tensor :: k -> (k, k) -> Type) a) b t -> (a0 ~> b) -> s ~> t Source Github #

(Closed k, Ob m) => SetterFl (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) => SetterFl (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) => SetterFl (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 #

(SetterFl f g, SetterFl f' g') => SetterFl (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 (SetterFl :: (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 -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (CategoryOf k, (Ob a, Ob b) => c (ExOptic (SetterFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => 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: run it at its witness pair (ExOptic SetterFl, via withLegs) and apply overP.

(%~) :: forall (c :: (Type -> Type -> Type) -> Constraint) a b s t. c (ExOptic (SetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => 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 -> Type) -> Constraint) a b s t. c (ExOptic (SetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => 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 -> Type) -> Constraint) a b s t. c (ExOptic (SetterFl :: (Type +-> Type) -> (Type +-> Type) -> Constraint) a b) => 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.