| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Proarrow.Optic.Kaleidoscope
Contents
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 (, so it
folds and sets like any traversal). Its distinctive power is that KaleidoRes <: TravReskaleidoP 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 , not the
Hask-specific MonoidalProfunctor rCostar f = f a -> b: kaleidoscopeOf works at any monoidal profunctor carrier
(the hom ( gives ~>)over; an applicative combines the
foci through Star ff).
Two witness families are provided: (the ergonomic binary case, Twos ~> a ** a) and the
general (the Pow nn-fold tensor power s ~> , for any Peano Tensor n aNat arity),
alongside Id (unary) and composition. is Two at arity two up to the right
unitor.Pow
Synopsis
- class (MonTravRes p q, GrateRes p q) => KaleidoRes (p :: k +-> k) (q :: k +-> k) where
- 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
- type Kaleidoscope (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (KaleidoRes :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Kaleidoscope' (s :: k) (a :: k) = Kaleidoscope s s a a
- data Two (s :: k) (a :: k) where
- data CoTwo (b :: k) (t :: k) where
- 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
- 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
- data Nat
- type family Tensor (n :: Nat) (a :: k) :: k where ...
- class KnownNat (n :: Nat) where
- powDist :: forall {k1} {k2} r (a :: k2) (b :: k1). MonoidalProfunctor r => r a b -> r (Tensor n a) (Tensor n b)
- powFold :: forall {k} (m :: k). Monoid m => Tensor n m ~> m
- splitPow :: forall k (x :: k) (a :: k). (Closed k, CopyDiscard k, Ob x, Ob a) => (x ~~> Tensor n a) ~> Tensor n (x ~~> a)
- withObTensor :: forall k (a :: k) r. (Monoidal k, Ob a) => (Ob (Tensor n a) => r) -> r
- data Pow (n :: Nat) (s :: k) (a :: k) where
- data CoPow (n :: Nat) (b :: k) (t :: k) where
- 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
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
| CopyDiscard k => KaleidoRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| CategoryOf k => KaleidoRes (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| (CopyDiscard k, KnownNat n) => KaleidoRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| (KaleidoRes f g, KaleidoRes f' g') => KaleidoRes (f :.: f' :: i -> i -> Type) (g' :.: g :: i -> i -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
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.
Instances
| Monoidal k => Profunctor (Two :: k -> k -> Type) Source Github # | |
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 # | |
| Monoidal k => FoldRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
| CopyDiscard k => GrateRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
| CopyDiscard k => KaleidoRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| Monoidal k => SetterRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
| Monoidal k => MonTravRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| Monoidal k => TravRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
data CoTwo (b :: k) (t :: k) where Source Github #
The dual of Two: t is rebuilt from two foci via the tensor.
Instances
| Monoidal k => Profunctor (CoTwo :: k -> k -> Type) Source Github # | |
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 # | |
| Monoidal k => FoldRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
| CopyDiscard k => GrateRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
| CopyDiscard k => KaleidoRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| Monoidal k => SetterRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
| Monoidal k => MonTravRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| Monoidal k => TravRes (Two :: k -> k -> Type) (CoTwo :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
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 the foci are
combined through Star ff.
n-ary aggregation
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).
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 #
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
| KnownNat 'Z Source Github # | |
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 # | |
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.
Instances
| (Monoidal k, KnownNat n) => Profunctor (Pow n :: k -> k -> Type) Source Github # | |
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 # | |
| (Monoidal k, KnownNat n) => FoldRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
| (CopyDiscard k, KnownNat n) => GrateRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
| (CopyDiscard k, KnownNat n) => KaleidoRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| (Monoidal k, KnownNat n) => SetterRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
| (Monoidal k, KnownNat n) => MonTravRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| (Monoidal k, KnownNat n) => TravRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
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
| (Monoidal k, KnownNat n) => Profunctor (CoPow n :: k -> k -> Type) Source Github # | |
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 # | |
| (Monoidal k, KnownNat n) => FoldRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
| (CopyDiscard k, KnownNat n) => GrateRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
| (CopyDiscard k, KnownNat n) => KaleidoRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| (Monoidal k, KnownNat n) => SetterRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
| (Monoidal k, KnownNat n) => MonTravRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
| (Monoidal k, KnownNat n) => TravRes (Pow n :: k -> k -> Type) (CoPow n :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Kaleidoscope | |
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. is the arity-two case.kaleidoscope