proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Optic.PowerGrate

Description

A power grate is a Grate whose exponent is a fixed tensor power of the focus: the witness Pow n presents s as a ** ... ** a (n times), i.e. the exponential by a finite arity, which is also the reader applicative for n readers. That fixed, finite shape is a genuine decomposition, so a power grate is also a __fixed-arity Traversal__ (PowerGrateFl <: GrateFl, KaleidoFl, MonTravFl): it zips, aggregates, folds, sets and traverses like those do.

Its distinctive power over a grate or kaleidoscope is the eliminator: powerGrateP distributes an arbitrary MonoidalProfunctor -- the Applicative/zip structure (one and **) alone -- rather than the full StrongDistributiveProfunctor a traversal needs or the traversable carrier a kaleidoscope needs. With a fixed arity, any functor carrier Costar f distributes, by unzipping f (a ** ... ** a) into f a ** ... ** f a.

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

Synopsis

Documentation

class (MonTravFl p q, GrateFl p q) => PowerGrateFl (p :: k +-> k) (q :: k +-> k) where Source Github #

The power-grate flavor: distribute any MonoidalProfunctor r through the witness pair. TravFl is a superclass: every power-grate witness is a traversal witness (instantiate r at a StrongDistributiveProfunctor, a special MonoidalProfunctor), so it folds, sets, and traverses. The extra power is distributing the non-SDP monoidal profunctors as well. KaleidoFl is a superclass too: a tensor power is an applicative functor (the reader applicative).

Methods

powerGrateP :: 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
CategoryOf k => PowerGrateFl (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

powerGrateP :: 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, HasCoproducts k, KnownNat n) => PowerGrateFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

powerGrateP :: 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 #

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

Defined in Proarrow.Optic.PowerGrate

Methods

powerGrateP :: 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 PowerGrate (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (PowerGrateFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #

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

powerGrateOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (Monoidal k, MonoidalProfunctor r, (Ob a, Ob b) => c (ExOptic (PowerGrateFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> r a b -> r s t Source Github #

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

Accepts any encoding (cf. traverseOf), including (%)-composites.

zipWithOf :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k). (Monoidal k, Ob a, (Ob a, Ob b) => c (ExOptic (KaleidoFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((a ** a) ~> b) -> (s ** s) ~> t Source Github #

Zip two sources through a Kaleidoscope (or any stronger optic, a Grate in particular, in any encoding): combine the foci pairwise. This is kaleidoscopeOf at the carrier RepCostar (Pow 2), the costar of the binary tensor power -- a binary combination (a ** a) ~> b of foci, which the optic's applicative lifts by liftA2.

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 #

Case analysis on a type-level Nat: the single method from which every tensor-power operation below is defined by recursion on n.

Methods

natCase :: (n ~ 'Z => r) -> (forall (m :: Nat). (n ~ 'S m, KnownNat m) => r) -> r Source Github #

Instances

Instances details
KnownNat 'Z Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

natCase :: ('Z ~ 'Z => r) -> (forall (m :: Nat). ('Z ~ 'S m, KnownNat m) => r) -> r Source Github #

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

Defined in Proarrow.Optic.PowerGrate

Methods

natCase :: ('S n ~ 'Z => r) -> (forall (m :: Nat). ('S n ~ 'S m, KnownNat m) => 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
(CopyDiscard k, KnownNat n) => Strong (Tensor :: k -> (k, k) -> Type) (Pow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

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

(SymMonoidal k, KnownNat n) => MonoidalProfunctor (Pow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

one :: Pow n (Unit :: k) (Unit :: k) Source Github #

(**) :: forall (x1 :: k) (x2 :: k) (y1 :: k) (y2 :: k). Pow n x1 x2 -> Pow n y1 y2 -> Pow n (x1 ** y1) (x2 ** y2) Source Github #

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

Defined in Proarrow.Optic.PowerGrate

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) => Representable (Pow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

index :: forall (a :: k) (b :: k). Pow n a b -> a ~> ((Pow n :: k -> k -> Type) % b) Source Github #

tabulate :: forall (b :: k) (a :: k). Ob b => (a ~> ((Pow n :: k -> k -> Type) % b)) -> Pow n a b Source Github #

repMap :: forall (a :: k) (b :: k). (a ~> b) -> ((Pow n :: k -> k -> Type) % a) ~> ((Pow n :: k -> k -> Type) % b) Source Github #

repUniv :: forall (a :: k). Ob a => Pow n ((Pow n :: k -> k -> Type) % a) a 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.PowerGrate

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) => FoldFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

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

(Monoidal k, KnownNat n) => Traversable (Pow n :: k -> k -> Type) Source Github #

Pow n is the representable profunctor of the tensor power Tensor n, which is the reader applicative for n readers; the instances below make it a StrongDistributiveProfunctor, hence a kaleidoscope witness. | A tensor power is a fixed-shape traversable: distribute the carrier over the n copies.

Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

traverse :: forall (p :: k +-> k). StrongDistributiveProfunctor p => ((Pow n :: k -> k -> Type) :.: p) :~> (p :.: (Pow n :: k -> k -> Type)) Source Github #

(Monoidal k, HasCoproducts k, KnownNat 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 powCopy, powZip pairs them, and powDist applies each. Everything is stated with the CopyDiscard structure that CCC now 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 && ((s ~~> a) ~~> b)) ~> t Source Github #

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

Defined in Proarrow.Optic.PowerGrate

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, HasCoproducts k, KnownNat 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 #

(CopyDiscard k, HasCoproducts k, KnownNat 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 #

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

Defined in Proarrow.Optic.PowerGrate

Methods

powerGrateP :: 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) => 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 #

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

Defined in Proarrow.Optic.PowerGrate

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) => TravFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

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 #

(CopyDiscard k, HasCoproducts k, KnownNat n) => Strong (CoprodAction :: k -> (COPROD k, k) -> Type) (Pow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

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

(SymMonoidal k, HasCoproducts k, KnownNat n) => MonoidalProfunctor (Coprod (Pow n :: k -> k -> Type) :: COPROD k -> COPROD k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

one :: Coprod (Pow n :: k -> k -> Type) (Unit :: COPROD k) (Unit :: COPROD k) Source Github #

(**) :: forall (x1 :: COPROD k) (x2 :: COPROD k) (y1 :: COPROD k) (y2 :: COPROD k). Coprod (Pow n :: k -> k -> Type) x1 x2 -> Coprod (Pow n :: k -> k -> Type) y1 y2 -> Coprod (Pow n :: k -> k -> Type) (x1 ** y1) (x2 ** y2) Source Github #

type (Pow n :: k -> k -> Type) % (a :: k) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

type (Pow n :: k -> k -> Type) % (a :: k) = Tensor n a

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.PowerGrate

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.PowerGrate

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) => FoldFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

Methods

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

(Monoidal k, HasCoproducts k, KnownNat 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 powCopy, powZip pairs them, and powDist applies each. Everything is stated with the CopyDiscard structure that CCC now 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 && ((s ~~> a) ~~> b)) ~> t Source Github #

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

Defined in Proarrow.Optic.PowerGrate

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, HasCoproducts k, KnownNat 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 #

(CopyDiscard k, HasCoproducts k, KnownNat 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 #

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

Defined in Proarrow.Optic.PowerGrate

Methods

powerGrateP :: 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) => 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 #

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

Defined in Proarrow.Optic.PowerGrate

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) => TravFl (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.PowerGrate

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 #

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

Build an n-ary power grate from a tensor-power decomposition of s and recomposition of t.