proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.Kaleidoscope

Description

A kaleidoscope is the optic that distributes an arbitrary MonoidalProfunctor -- the Applicative/zip structure (one and **) -- rather than the full StrongDistributiveProfunctor a Traversal needs. Where a traversal decomposes a whole into its foci, a kaleidoscope also aggregates: it can combine the foci with ** (and one for the empty case), not just replace them.

The witnesses here (Two, Pow n) present s as a fixed tensor power of the focus (s ~> a ** ... ** a), which is a genuine decomposition -- so this kaleidoscope is really a fixed-arity Traversal (KaleidoRes <: TravRes, so it folds and sets like any traversal). Its distinctive power is that kaleidoP distributes an arbitrary MonoidalProfunctor, including the non-StrongDistributiveProfunctor ones (e.g. Costar f) a traversal can't touch -- that is where the aggregation lives.

Crucially the aggregation is stated over an abstract MonoidalProfunctor r, not the Hask-specific Costar f = f a -> b: kaleidoscopeOf works at any monoidal profunctor carrier (the hom (~>) gives over; an applicative Star f combines the foci through f).

Two witness families are provided: Two (the ergonomic binary case, s ~> a ** a) and the general Pow n (the n-fold tensor power s ~> Tensor n a, for any Peano Nat arity), alongside Id (unary) and composition. Two is Pow at arity two up to the right unitor.

Synopsis

Documentation

class (MonTravRes p q, GrateRes p q) => KaleidoRes (p :: k +-> k) (q :: k +-> k) where Source Github #

The kaleidoscope flavor: distribute any MonoidalProfunctor r through the witness pair. TravRes is a superclass: every kaleidoscope witness is a traversal witness (instantiate r at a StrongDistributiveProfunctor, a special MonoidalProfunctor), so a kaleidoscope folds, sets, and traverses. The extra power is distributing the non-SDP monoidal profunctors as well.

Methods

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

Instances

Instances details
CopyDiscard k => KaleidoRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). MonoidalProfunctor r => Two s a -> CoTwo b t -> r a b -> r s t Source Github #

CategoryOf k => KaleidoRes (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). MonoidalProfunctor r => Id s a -> Id b t -> r a b -> r s t Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

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

(KaleidoRes f g, KaleidoRes f' g') => KaleidoRes (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). MonoidalProfunctor 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 (KaleidoRes :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #

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

data Two (s :: k) (a :: k) where Source Github #

The binary aggregation witness: s presents two foci via the tensor.

Constructors

Two :: forall {k} (a :: k) (s :: k). Ob a => (s ~> (a ** a)) -> Two s a 

Instances

Instances details
Monoidal k => Profunctor (Two :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

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

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

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

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

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

unit :: forall (a :: k). Ob a => ((CoTwo :: k -> k -> Type) :.: (Two :: k -> k -> Type)) a a Source Github #

counit :: ((Two :: k -> k -> Type) :.: (CoTwo :: k -> k -> Type)) :~> ((~>) :: CAT k) Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => Two s a -> (a ~> m) -> s ~> m Source Github #

CopyDiscard k => GrateRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

zipWithP :: forall (s :: k) (a :: k) (b :: k) (t :: k). (Closed k, SymMonoidal k) => Two s a -> CoTwo b t -> forall (x :: k). Ob x => ((x ~~> a) ~> b) -> (x ~~> s) ~> t Source Github #

CopyDiscard k => KaleidoRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). MonoidalProfunctor r => Two s a -> CoTwo b t -> r a b -> r s t 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 => MonTravRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

monTravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). StrongDistributiveProfunctor r => Two s a -> CoTwo b t -> r a b -> r s t Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

travP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => Two s a -> CoTwo b t -> r a b -> r s t Source Github #

data CoTwo (b :: k) (t :: k) where Source Github #

The dual of Two: t is rebuilt from two foci via the tensor.

Constructors

CoTwo :: forall {k} (b :: k) (t :: k). Ob b => ((b ** b) ~> t) -> CoTwo b t 

Instances

Instances details
Monoidal k => Profunctor (CoTwo :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

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

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

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

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

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

unit :: forall (a :: k). Ob a => ((CoTwo :: k -> k -> Type) :.: (Two :: k -> k -> Type)) a a Source Github #

counit :: ((Two :: k -> k -> Type) :.: (CoTwo :: k -> k -> Type)) :~> ((~>) :: CAT k) Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => Two s a -> (a ~> m) -> s ~> m Source Github #

CopyDiscard k => GrateRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

zipWithP :: forall (s :: k) (a :: k) (b :: k) (t :: k). (Closed k, SymMonoidal k) => Two s a -> CoTwo b t -> forall (x :: k). Ob x => ((x ~~> a) ~> b) -> (x ~~> s) ~> t Source Github #

CopyDiscard k => KaleidoRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). MonoidalProfunctor r => Two s a -> CoTwo b t -> r a b -> r s t 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 => MonTravRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

monTravP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). StrongDistributiveProfunctor r => Two s a -> CoTwo b t -> r a b -> r s t Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

travP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => Two s a -> CoTwo b t -> r a b -> r s t Source Github #

kaleidoscope :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (CopyDiscard k, Ob a, Ob b) => (s ~> (a ** a)) -> ((b ** b) ~> t) -> Kaleidoscope s t a b Source Github #

Build a binary kaleidoscope from a tensor decomposition of s and recomposition of t.

kaleidoscopeOf :: forall {k} (w :: FLAVOR k k) (s :: k) (t :: k) (a :: k) (b :: k) r. (Monoidal k, MonoidalProfunctor r, SubFlavor w (KaleidoRes :: (k +-> k) -> (k +-> k) -> Constraint)) => Optic (Prostrong w) s t a b -> r a b -> r s t Source Github #

Distribute any MonoidalProfunctor through a kaleidoscope (or any stronger optic). At the hom (~>) this is over; at an applicative Star f the foci are combined through f.

n-ary aggregation

data Nat Source Github #

A Peano natural, the arity of a Pow witness.

Constructors

Z 
S Nat 

type family Tensor (n :: Nat) (a :: k) :: k where ... Source Github #

The n-fold tensor power of a: a ** a ** ... ** a (n times, terminated by Unit).

Equations

Tensor 'Z (a :: k) = Unit :: k 
Tensor ('S n) (a :: k) = a ** Tensor n a 

class KnownNat (n :: Nat) where Source Github #

Distribute a MonoidalProfunctor over the n-fold tensor power, by combining n copies of the carrier value with one (at Z) and ** (at S) -- the profunctor-general heart of the n-ary kaleidoscope.

Methods

powDist :: forall {k1} {k2} r (a :: k2) (b :: k1). MonoidalProfunctor r => r a b -> r (Tensor n a) (Tensor n b) Source Github #

powFold :: forall {k} (m :: k). Monoid m => Tensor n m ~> m Source Github #

Collapse the n-fold tensor power of a monoid via mappend/mempty.

splitPow :: forall k (x :: k) (a :: k). (Closed k, CopyDiscard k, Ob x, Ob a) => (x ~~> Tensor n a) ~> Tensor n (x ~~> a) Source Github #

Distribute the internal hom over the tensor power: split x ~~> aⁿ into (x ~~> a)ⁿ using CopyDiscard projections. The n-fold form of the Two split -- this is what makes an n-ary kaleidoscope a Grate.

withObTensor :: forall k (a :: k) r. (Monoidal k, Ob a) => (Ob (Tensor n a) => r) -> r Source Github #

Tensor n a is an object whenever a is.

Instances

Instances details
KnownNat 'Z Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

powDist :: forall {k1} {k2} r (a :: k2) (b :: k1). MonoidalProfunctor r => r a b -> r (Tensor 'Z a) (Tensor 'Z b) Source Github #

powFold :: forall {k} (m :: k). Monoid m => Tensor 'Z m ~> m Source Github #

splitPow :: forall k (x :: k) (a :: k). (Closed k, CopyDiscard k, Ob x, Ob a) => (x ~~> Tensor 'Z a) ~> Tensor 'Z (x ~~> a) Source Github #

withObTensor :: forall k (a :: k) r. (Monoidal k, Ob a) => (Ob (Tensor 'Z a) => r) -> r Source Github #

KnownNat n => KnownNat ('S n) Source Github # 
Instance details

Defined in Proarrow.Optic.Kaleidoscope

Methods

powDist :: forall {k1} {k2} r (a :: k2) (b :: k1). MonoidalProfunctor r => r a b -> r (Tensor ('S n) a) (Tensor ('S n) b) Source Github #

powFold :: forall {k} (m :: k). Monoid m => Tensor ('S n) m ~> m Source Github #

splitPow :: forall k (x :: k) (a :: k). (Closed k, CopyDiscard k, Ob x, Ob a) => (x ~~> Tensor ('S n) a) ~> Tensor ('S n) (x ~~> a) Source Github #

withObTensor :: forall k (a :: k) r. (Monoidal k, Ob a) => (Ob (Tensor ('S n) a) => r) -> r Source Github #

data Pow (n :: Nat) (s :: k) (a :: k) where Source Github #

The arity-n aggregation witness: s presents n foci via the tensor power.

Constructors

Pow :: forall (n :: Nat) {k} (s :: k) (a :: k). Ob a => (s ~> Tensor n a) -> Pow n s a 

Instances

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

dimap :: forall (c :: k) (a :: k) (b :: k) (d :: k). (c ~> a) -> (b ~> d) -> Pow n a b -> Pow n c d Source Github #

lmap :: forall (c :: k) (a :: k) (b :: k). (c ~> a) -> Pow n a b -> Pow n c b Source Github #

rmap :: forall (b :: k) (d :: k) (a :: k). (b ~> d) -> Pow n a b -> Pow n a d Source Github #

(\\) :: forall (a :: k) (b :: k) r. ((Ob a, Ob b) => r) -> Pow n a b -> r Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

unit :: forall (a :: k). Ob a => ((CoPow n :: k -> k -> Type) :.: (Pow n :: k -> k -> Type)) a a Source Github #

counit :: ((Pow n :: k -> k -> Type) :.: (CoPow n :: k -> k -> Type)) :~> ((~>) :: CAT k) Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => Pow n s a -> (a ~> m) -> s ~> m Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

zipWithP :: forall (s :: k) (a :: k) (b :: k) (t :: k). (Closed k, SymMonoidal k) => Pow n s a -> CoPow n b t -> forall (x :: k). Ob x => ((x ~~> a) ~> b) -> (x ~~> s) ~> t Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). MonoidalProfunctor r => Pow n s a -> CoPow n b t -> r a b -> r 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 #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

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

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

travP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => Pow n s a -> CoPow n b t -> r a b -> r s t Source Github #

data CoPow (n :: Nat) (b :: k) (t :: k) where Source Github #

The dual of Pow: t is rebuilt from n foci.

Constructors

CoPow :: forall (n :: Nat) {k} (b :: k) (t :: k). Ob b => (Tensor n b ~> t) -> CoPow n b t 

Instances

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

dimap :: forall (c :: k) (a :: k) (b :: k) (d :: k). (c ~> a) -> (b ~> d) -> CoPow n a b -> CoPow n c d Source Github #

lmap :: forall (c :: k) (a :: k) (b :: k). (c ~> a) -> CoPow n a b -> CoPow n c b Source Github #

rmap :: forall (b :: k) (d :: k) (a :: k). (b ~> d) -> CoPow n a b -> CoPow n a d Source Github #

(\\) :: forall (a :: k) (b :: k) r. ((Ob a, Ob b) => r) -> CoPow n a b -> r Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

unit :: forall (a :: k). Ob a => ((CoPow n :: k -> k -> Type) :.: (Pow n :: k -> k -> Type)) a a Source Github #

counit :: ((Pow n :: k -> k -> Type) :.: (CoPow n :: k -> k -> Type)) :~> ((~>) :: CAT k) Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

foldMapP :: forall (m :: k) (s :: k) (a :: k). Monoid m => Pow n s a -> (a ~> m) -> s ~> m Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

zipWithP :: forall (s :: k) (a :: k) (b :: k) (t :: k). (Closed k, SymMonoidal k) => Pow n s a -> CoPow n b t -> forall (x :: k). Ob x => ((x ~~> a) ~> b) -> (x ~~> s) ~> t Source Github #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

kaleidoP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). MonoidalProfunctor r => Pow n s a -> CoPow n b t -> r a b -> r 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 #

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

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

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

Defined in Proarrow.Optic.Kaleidoscope

Methods

travP :: forall r (s :: k) (a :: k) (b :: k) (t :: k). (StrongDistributiveProfunctor r, Strong (ProdAction :: k -> (PROD k, k) -> Type) r) => Pow n s a -> CoPow n b t -> r a b -> r s t Source Github #

kaleidoscopeN :: forall {k} (n :: Nat) (s :: k) (t :: k) (a :: k) (b :: k). (CopyDiscard k, KnownNat n, Ob a, Ob b) => (s ~> Tensor n a) -> (Tensor n b ~> t) -> Kaleidoscope s t a b Source Github #

Build an n-ary kaleidoscope from a tensor-power decomposition of s and recomposition of t. kaleidoscope is the arity-two case.