| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Proarrow.Optic.Prism
Description
The prism: the optic for the coproduct, with legs
Prism s t a b = (b ~> t, s ~> (t || a))
witnessed by /RepCorep( (Coproduct t)PrismFl / matchingP). A prism reviews
and matches, sitting below Review,
AffineTraversal and
MonoidalTraversal in the lattice. Build with prism,
eliminate to the two legs with withPrism via the generic ExOptic carrier.
toOpLens/fromOpLens witness the equivalence with the op-lens encoding. This module also
hosts affineTraversal, the lens-then-prism builder for affine traversals.
Synopsis
- class (AffineTravFl p q, GetterFl q p, MonTravFl p q) => PrismFl (p :: k +-> k) (q :: k +-> k) where
- matchingP :: forall (s :: k) (a :: k) (b :: k) (t :: k). HasBinaryCoproducts k => p s a -> q b t -> s ~> (t || a)
- type Prism (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (PrismFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b
- type Prism' (s :: k) (a :: k) = Prism s s a a
- prism :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (CopyDiscard k, HasCoproducts k, Ob a) => (b ~> t) -> (s ~> (t || a)) -> Prism s t a b
- affineTraversal :: forall {k} (s :: k) (t :: k) (x :: k) (y :: k) (a :: k) (b :: k). CategoryOf k => Lens s t x y -> Prism x y a b -> AffineTraversal s t a b
- withPrism :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (HasBinaryCoproducts k, (Ob a, Ob b) => c (ExOptic (PrismFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((b ~> t) -> (s ~> (t || a)) -> r) -> r
- type OpLens (s :: k) (t :: k) (a :: k) (b :: k) = Optic (OpConstraint (Prostrong (LensFl :: (OPPOSITE k +-> OPPOSITE k) -> (OPPOSITE k +-> OPPOSITE k) -> Constraint))) s t a b
- toOpLens :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (HasCoproducts k, Ob a, Ob b) => Prism s t a b -> OpLens s t a b
- fromOpLens :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (CopyDiscard k, HasCoproducts k, Ob a) => OpLens s t a b -> Prism s t a b
Documentation
class (AffineTravFl p q, GetterFl q p, MonTravFl p q) => PrismFl (p :: k +-> k) (q :: k +-> k) where Source Github #
The prism flavor. The superclass says a reversed prism views its build leg
(GetterFl q pgetP on the swapped pair): is a getter.re prism
Methods
matchingP :: forall (s :: k) (a :: k) (b :: k) (t :: k). HasBinaryCoproducts k => p s a -> q b t -> s ~> (t || a) Source Github #
Like affineMatch, but asking only for binary coproducts. Prism witnesses never need more,
so prisms stay usable in categories without products.
Instances
| CategoryOf k => PrismFl (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Prism | |
| (CopyDiscard k, HasCoproducts k, Ob t) => PrismFl (Rep (Coproduct t) :: k -> k -> Type) (Corep (Coproduct t) :: k -> k -> Type) Source Github # | |
| (PrismFl f g, PrismFl f' g') => PrismFl (f :.: f' :: i -> i -> Type) (g' :.: g :: i -> i -> Type) Source Github # | |
Defined in Proarrow.Optic.Prism | |
type Prism (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (PrismFl :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #
prism :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (CopyDiscard k, HasCoproducts k, Ob a) => (b ~> t) -> (s ~> (t || a)) -> Prism s t a b Source Github #
affineTraversal :: forall {k} (s :: k) (t :: k) (x :: k) (y :: k) (a :: k) (b :: k). CategoryOf k => Lens s t x y -> Prism x y a b -> AffineTraversal s t a b Source Github #
Build an AffineTraversal by composing a Lens with a Prism: focus a field with the lens,
then match a case of that field with the prism. There is no from-legs builder for a bare affine
traversal (its witness only ever arises by composition), so this is the way to make one. It is
.convert (l % p)
withPrism :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (HasBinaryCoproducts k, (Ob a, Ob b) => c (ExOptic (PrismFl :: (k +-> k) -> (k +-> k) -> Constraint) a b)) => Optic c s t a b -> ((b ~> t) -> (s ~> (t || a)) -> r) -> r Source Github #
type OpLens (s :: k) (t :: k) (a :: k) (b :: k) = Optic (OpConstraint (Prostrong (LensFl :: (OPPOSITE k +-> OPPOSITE k) -> (OPPOSITE k +-> OPPOSITE k) -> Constraint))) s t a b Source Github #
A Prism and its op-lens encoding (Prism, a Lens
over the opposite category) carry the same data, the two legs (b ,
so they are equivalent. ~> t, s ~> t || a)toOpLens eliminates a PrismFl prism to its legs (via withPrism) and
rebuilds the op-lens; fromOpLens eliminates the op-lens (via withLens on
opOptic, i.e. as a lens over OPPOSITE) and rebuilds the PrismFl prism.
The op-lens encoding of a prism: a Lens over the opposite category.
toOpLens :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (HasCoproducts k, Ob a, Ob b) => Prism s t a b -> OpLens s t a b Source Github #
fromOpLens :: forall {k} (s :: k) (t :: k) (a :: k) (b :: k). (CopyDiscard k, HasCoproducts k, Ob a) => OpLens s t a b -> Prism s t a b Source Github #