| 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)PrismRes / 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 Market carrier;
toOpLens/fromOpLens witness the equivalence with the op-lens encoding, and this module also
hosts affineTraversal, the lens-then-prism builder for affine traversals.
Synopsis
- class (AffineTravRes p q, GetterRes q p, MonTravRes p q) => PrismRes (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 (PrismRes :: (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
- data Market (a :: k) (b :: k) (s :: k) (t :: k) where
- withPrism :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (HasBinaryCoproducts k, (Ob a, Ob b) => c (Market 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 (LensRes :: (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 (AffineTravRes p q, GetterRes q p, MonTravRes p q) => PrismRes (p :: k +-> k) (q :: k +-> k) where Source Github #
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 with an honest constraint: prism witnesses only ever need binary
coproducts, so prisms stay usable in categories without products.
Instances
| CategoryOf k => PrismRes (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Prism | |
| (CopyDiscard k, HasCoproducts k, Ob t) => PrismRes (Rep (Coproduct t) :: k -> k -> Type) (Corep (Coproduct t) :: k -> k -> Type) Source Github # | |
| (PrismRes f g, PrismRes f' g') => PrismRes (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 (PrismRes :: (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 design-aligned way to
make one -- the same idiom the test suite uses.convert (l % p)
data Market (a :: k) (b :: k) (s :: k) (t :: k) where Source Github #
The eliminating carrier for prisms: a prism's two legs, as a profunctor in s/t.
Constructors
| Market :: forall {k} (a :: k) (b :: k) (t :: k) (s :: k). (Ob a, Ob b) => (b ~> t) -> (s ~> (t || a)) -> Market a b s t |
Instances
| (HasBinaryCoproducts k, Ob a, Ob b, SubFlavor w (PrismRes :: (k +-> k) -> (k +-> k) -> Constraint)) => Prostrong (w :: FLAVOR k k) (Market a b :: k -> k -> Type) Source Github # | Any flavor whose optics have prism legs has strength for the |
Defined in Proarrow.Optic.Prism | |
| (HasBinaryCoproducts k, Ob a, Ob b) => Profunctor (Market a b :: k -> k -> Type) Source Github # | |
Defined in Proarrow.Optic.Prism Methods dimap :: forall (c :: k) (a0 :: k) (b0 :: k) (d :: k). (c ~> a0) -> (b0 ~> d) -> Market a b a0 b0 -> Market a b c d Source Github # lmap :: forall (c :: k) (a0 :: k) (b0 :: k). (c ~> a0) -> Market a b a0 b0 -> Market a b c b0 Source Github # rmap :: forall (b0 :: k) (d :: k) (a0 :: k). (b0 ~> d) -> Market a b a0 b0 -> Market a b a0 d Source Github # (\\) :: forall (a0 :: k) (b0 :: k) r. ((Ob a0, Ob b0) => r) -> Market a b a0 b0 -> r Source Github # | |
withPrism :: forall {k} (c :: (k -> k -> Type) -> Constraint) (s :: k) (t :: k) (a :: k) (b :: k) r. (HasBinaryCoproducts k, (Ob a, Ob b) => c (Market a b)) => Optic c s t a b -> ((b ~> t) -> (s ~> (t || a)) -> r) -> r Source Github #
Eliminate any optic that is at least an iso and at most a prism to its two legs, in either encoding.
type OpLens (s :: k) (t :: k) (a :: k) (b :: k) = Optic (OpConstraint (Prostrong (LensRes :: (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 PrismRes prism to its legs (via Market) and
rebuilds the op-lens; fromOpLens eliminates the op-lens (via withLens on
opOptic, i.e. as a lens over OPPOSITE) and rebuilds the PrismRes 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 #