proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.Kaleidoscope

Description

The cotraversal and the kaleidoscope: two flavors with the same witnesses (the representable StrongDistributiveProfunctors, i.e. applicative functors rendered as profunctors, with their RepCostars) that differ in what they can be eliminated through.

Both mirror MonTravFl. All three rest on the square t :.: p ~> p :.: t between a functor t and a StrongDistributiveProfunctor p (in Type, sequenceA :: t (f a) -> f (t a)). A monoidal traversal takes t as the witness and quantifies over p; the optics here take p as the witness and quantify over t.

  • A Cotraversal passes through every Cotraversable carrier: the square for arbitrary p. This holds for shapes with a list of contents (Cotraversable (RepCostar t) for a traversable representable t, Id, products, sums, and in Type Costar (Prelude t) for a Prelude Traversable t, the Aggregating module of the literature).
  • A Kaleidoscope passes through every Kaleidoscopic carrier: the square for representable p only. This is the kaleidoscope of Clarke et al. (Profunctor optics: a categorical update), ∫^{F applicative} C(S, F A) × C(F B, T). It admits every applicative, including ones with no list of contents such as the reader (->) r, which are not Cotraversable.

Every Cotraversable carrier is Kaleidoscopic (cotravAct), so KaleidoFl <: CotravFl: the kaleidoscope is the stronger flavor. Both sit below SetterFl only, since one can over through an applicative but not fold out of one. PowerGrateFl (the reader applicative) and the tensor-action pair for a monoid residual (the writer applicative) are subflavors of KaleidoFl, which is how an algebraic lens for the list monad composes with a kaleidoscope (ClassifyFl).

Synopsis

The cotraversal

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

The cotraversal flavor: pass any Cotraversable carrier through the witness pair. The mirror of MonTravFl, with witness and carrier swapped.

Minimal complete definition

Nothing

Methods

cotravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Cotraversable r => p s a -> q b t -> r a b -> r s t Source Github #

default cotravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). (KaleidoFl p q, Cotraversable r) => p s a -> q b t -> r a b -> r s t Source Github #

Instances

Instances details
(Representable p, StrongDistributiveProfunctor p) => CotravFl (p :: k +-> k) (RepCostar p :: k -> k -> Type) Source Github #

The generating witnesses: any representable StrongDistributiveProfunctor (any applicative functor) with its RepCostar. The legs are s ~> p % a and p % b ~> t.

Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

cotravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Cotraversable r => p s a -> RepCostar p b t -> r a b -> r s t Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

cotravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Cotraversable r => Id s a -> Id b t -> r a b -> r s t Source Github #

(CopyDiscard k, HasCoproducts k, SNatI n) => CotravFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

cotravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Cotraversable r => Pow n s a -> CoPow n b t -> r a b -> r s t Source Github #

(SymMonoidal k, HasCoproducts k, Monoid m) => CotravFl (Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) (Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) :: k -> k -> Type) Source Github #

The tensor-action pair for a monoid residual: m ** - is the writer applicative.

Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

cotravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Cotraversable r => Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) s a -> Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) b t -> r a b -> r s t Source Github #

(Closed k, SymMonoidal k, HasCoproducts k, CocommutativeComonoid m) => CotravFl (Rep (Exp m) :: k -> k -> Type) (Corep (Exp m) :: k -> k -> Type) Source Github #

The exponential pair for a comonoid exponent: m ~~> - is the reader applicative. So every Grate is a kaleidoscope.

Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

cotravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Cotraversable r => Rep (Exp m) s a -> Corep (Exp m) b t -> r a b -> r s t Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

cotravP :: forall r (s :: i) (a :: i) (b :: i) (t :: i). Cotraversable r => (f :.: f') s a -> (g' :.: g) b t -> r a b -> r s t Source Github #

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

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

cotraversal :: forall {k} (p :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Representable p, StrongDistributiveProfunctor p, Ob a, Ob b) => (s ~> (p % a)) -> ((p % b) ~> t) -> Cotraversal s t a b Source Github #

Build a cotraversal from its legs through an applicative functor, given as a representable StrongDistributiveProfunctor p.

cotraverseOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CategoryOf k, Cotraversable r, (Ob a, Ob b) => c (ExOptic (CotravFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t Source Github #

Pass a Cotraversable carrier through a cotraversal (or any stronger optic, in any encoding, (%)-composites included).

The kaleidoscope

class CotravFl p q => KaleidoFl (p :: k +-> k) (q :: k +-> k) where Source Github #

The kaleidoscope flavor: act on any Kaleidoscopic carrier through the witness pair.

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Kaleidoscopic r => p s a -> q b t -> r a b -> r s t Source Github #

Instances

Instances details
(Representable p, StrongDistributiveProfunctor p) => KaleidoFl (p :: k +-> k) (RepCostar p :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Kaleidoscopic r => p s a -> RepCostar p b t -> r a b -> r s t Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Kaleidoscopic r => Id s a -> Id b t -> r a b -> r s t Source Github #

(CopyDiscard k, HasCoproducts k, SNatI n) => KaleidoFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Kaleidoscopic r => Pow n s a -> CoPow n b t -> r a b -> r s t Source Github #

(SymMonoidal k, HasCoproducts k, Monoid m) => KaleidoFl (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.Kaleidoscope

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Kaleidoscopic r => Rep (ActionAt (Tensor :: k -> (k, k) -> Type) m) s a -> Corep (ActionAt (Tensor :: k -> (k, k) -> Type) m) b t -> r a b -> r s t Source Github #

(Closed k, SymMonoidal k, HasCoproducts k, CocommutativeComonoid m) => KaleidoFl (Rep (Exp m) :: k -> k -> Type) (Corep (Exp m) :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). Kaleidoscopic r => Rep (Exp m) s a -> Corep (Exp m) b t -> r a b -> r s t Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoP :: forall r (s :: i) (a :: i) (b :: i) (t :: i). Kaleidoscopic r => (f :.: f') s a -> (g' :.: g) b t -> r a b -> r s t Source Github #

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

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

kaleidoscope :: forall {k} (p :: k +-> k) (s :: k) (t :: k) (a :: k) (b :: k). (Representable p, StrongDistributiveProfunctor p, Ob a, Ob b) => (s ~> (p % a)) -> ((p % b) ~> t) -> Kaleidoscope s t a b Source Github #

Build a kaleidoscope from the same legs.

kaleidoscopeOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (CategoryOf k, Kaleidoscopic r, (Ob a, Ob b) => c (ExOptic (KaleidoFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t Source Github #

Act on a Kaleidoscopic carrier through a kaleidoscope (or any stronger optic, in any encoding, (%)-composites included). At Costar [] this is the literature's aggregation operator >-: from [a] -> b to [s] -> t.

Carriers

class Profunctor r => Kaleidoscopic (r :: k +-> k) where Source Github #

The carriers of the kaleidoscope: profunctors that every representable StrongDistributiveProfunctor p (i.e. every applicative functor p % -) acts on by application. Where a traversal's carriers are the applicatives themselves, a kaleidoscope's carriers are the things applicatives can be sequenced through. These are every Cotraversable profunctor (cotravAct), and in Type also Costar t for any Traversable t (Costar [] directly, and Costar (Prelude t) for a t that has no Functor instance of its own).

Methods

kaleidoAct :: forall (p :: k +-> k) (a :: k) (b :: k). (Representable p, StrongDistributiveProfunctor p) => r a b -> r (p % a) (p % b) Source Github #

Instances

Instances details
Traversable t => Kaleidoscopic (Costar (Prelude t) :: Type -> Type -> Type) Source Github #

Costar (Prelude t) for a traversable t: sequence the applicative through t, then aggregate. This carrier is not Cotraversable, see the module header.

Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoAct :: forall (p :: Type +-> Type) a b. (Representable p, StrongDistributiveProfunctor p) => Costar (Prelude t) a b -> Costar (Prelude t) (p % a) (p % b) Source Github #

Kaleidoscopic (Costar []) Source Github #

The same for [], which is a Functor in its own right, so the literature's aggregating carrier can be written as a plain [a] -> b.

Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoAct :: forall (p :: Type +-> Type) a b. (Representable p, StrongDistributiveProfunctor p) => Costar [] a b -> Costar [] (p % a) (p % b) Source Github #

Cotraversable r => Kaleidoscopic (CotravAs r :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoAct :: forall (p :: k +-> k) (a :: k) (b :: k). (Representable p, StrongDistributiveProfunctor p) => CotravAs r a b -> CotravAs r (p % a) (p % b) Source Github #

(Traversable t, Representable t) => Kaleidoscopic (RepCostar t :: k -> k -> Type) Source Github #

The general carrier: the RepCostar of a traversable representable functor.

Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoAct :: forall (p :: k +-> k) (a :: k) (b :: k). (Representable p, StrongDistributiveProfunctor p) => RepCostar t a b -> RepCostar t (p % a) (p % b) Source Github #

cotravAct :: forall {k} (p :: k +-> k) r (a :: k) (b :: k). (Cotraversable r, Representable p, StrongDistributiveProfunctor p) => r a b -> r (p % a) (p % b) Source Github #

kaleidoAct for any Cotraversable carrier: let the witness through.

newtype CotravAs (r :: k -> k1 -> Type) (a :: k) (b :: k1) Source Github #

A Cotraversable carrier, tagged as the Kaleidoscopic carrier it also is. With it every kaleidoscope witness is a cotraversal witness (the default cotravP).

Constructors

CotravAs 

Fields

Instances

Instances details
Profunctor r => Profunctor (CotravAs r :: k -> j -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

dimap :: forall (c :: k) (a :: k) (b :: j) (d :: j). (c ~> a) -> (b ~> d) -> CotravAs r a b -> CotravAs r c d Source Github #

lmap :: forall (c :: k) (a :: k) (b :: j). (c ~> a) -> CotravAs r a b -> CotravAs r c b Source Github #

rmap :: forall (b :: j) (d :: j) (a :: k). (b ~> d) -> CotravAs r a b -> CotravAs r a d Source Github #

(\\) :: forall (a :: k) (b :: j) r0. ((Ob a, Ob b) => r0) -> CotravAs r a b -> r0 Source Github #

Cotraversable r => Kaleidoscopic (CotravAs r :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoAct :: forall (p :: k +-> k) (a :: k) (b :: k). (Representable p, StrongDistributiveProfunctor p) => CotravAs r a b -> CotravAs r (p % a) (p % b) Source Github #

newtype WrapRep (p :: j +-> Type) (x :: j) Source Github #

The applicative functor a representable StrongDistributiveProfunctor on Type represents: pure is one and liftA2 is **.

Constructors

WrapRep 

Fields

Instances

Instances details
(Representable p, StrongDistributiveProfunctor p) => Applicative (WrapRep p) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

pure :: a -> WrapRep p a Github #

(<*>) :: WrapRep p (a -> b) -> WrapRep p a -> WrapRep p b Github #

liftA2 :: (a -> b -> c) -> WrapRep p a -> WrapRep p b -> WrapRep p c Github #

(*>) :: WrapRep p a -> WrapRep p b -> WrapRep p b Github #

(<*) :: WrapRep p a -> WrapRep p b -> WrapRep p a Github #

Representable p => Functor (WrapRep p) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

fmap :: (a -> b) -> WrapRep p a -> WrapRep p b Github #

(<$) :: a -> WrapRep p b -> WrapRep p a Github #

Orphan instances

(Closed k, SymMonoidal k, Ob m) => Strong (Tensor :: k -> (k, k) -> Type) (Rep (Exp m) :: k -> k -> Type) Source Github # 
Instance details

Methods

act :: forall (a :: k) (x :: k) (y :: k). Ob a => Rep (Exp m) x y -> Rep (Exp m) (Act (Tensor :: k -> (k, k) -> Type) a x) (Act (Tensor :: k -> (k, k) -> Type) a y) Source Github #

(Closed k, SymMonoidal k, CocommutativeComonoid m) => MonoidalProfunctor (Rep (Exp m) :: k -> k -> Type) Source Github #

The exponential by a comonoid, m ~~> -, is an applicative functor (the reader applicative): pure discards the argument with the counit and * duplicates it with the comultiplication. Rendered on Rep (Exp m) (legs a ~> (m ~~> b)) this is a StrongDistributiveProfunctor, so a Grate is a Kaleidoscope.

Instance details

Methods

one :: Rep (Exp m) (Unit :: k) (Unit :: k) Source Github #

(**) :: forall (x1 :: k) (x2 :: k) (y1 :: k) (y2 :: k). Rep (Exp m) x1 x2 -> Rep (Exp m) y1 y2 -> Rep (Exp m) (x1 ** y1) (x2 ** y2) Source Github #

(Closed k, SymMonoidal k, HasCoproducts k, CocommutativeComonoid m) => Traversing (Rep (Exp m) :: k -> k -> Type) Source Github # 
Instance details

Methods

traverseP :: forall (t :: k +-> k). (Traversable t, Representable t) => (t :.: Rep (Exp m)) :~> (Rep (Exp m) :.: t) Source Github #

(Closed k, HasCoproducts k, Comonoid m) => Strong (CoprodAction :: k -> (COPROD k, k) -> Type) (Rep (Exp m) :: k -> k -> Type) Source Github # 
Instance details

Methods

act :: forall (a :: COPROD k) (x :: k) (y :: k). Ob a => Rep (Exp m) x y -> Rep (Exp m) (Act (CoprodAction :: k -> (COPROD k, k) -> Type) a x) (Act (CoprodAction :: k -> (COPROD k, k) -> Type) a y) Source Github #

(Closed k, HasCoproducts k, Ob m) => MonoidalProfunctor (Coprod (Rep (Exp m)) :: COPROD k -> COPROD k -> Type) Source Github # 
Instance details

Methods

one :: Coprod (Rep (Exp m)) (Unit :: COPROD k) (Unit :: COPROD k) Source Github #

(**) :: forall (x1 :: COPROD k) (x2 :: COPROD k) (y1 :: COPROD k) (y2 :: COPROD k). Coprod (Rep (Exp m)) x1 x2 -> Coprod (Rep (Exp m)) y1 y2 -> Coprod (Rep (Exp m)) (x1 ** y1) (x2 ** y2) Source Github #