proarrow
Safe HaskellNone
LanguageGHC2024

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 Rep/Corep (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

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

Instances details
CategoryOf k => PrismRes (Id :: k -> k -> Type) (Id :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Prism

Methods

matchingP :: forall (s :: k) (a :: k) (b :: k) (t :: k). HasBinaryCoproducts k => Id s a -> Id b t -> s ~> (t || a) Source Github #

(CopyDiscard k, HasCoproducts k, Ob t) => PrismRes (Rep (Coproduct t) :: k -> k -> Type) (Corep (Coproduct t) :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Optic.Prism

Methods

matchingP :: forall (s :: k) (a :: k) (b :: k) (t0 :: k). HasBinaryCoproducts k => Rep (Coproduct t) s a -> Corep (Coproduct t) b t0 -> s ~> (t0 || a) Source Github #

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

Defined in Proarrow.Optic.Prism

Methods

matchingP :: forall (s :: i) (a :: i) (b :: i) (t :: i). HasBinaryCoproducts i => (f :.: f') s a -> (g' :.: g) b t -> s ~> (t || a) Source Github #

type Prism (s :: k) (t :: k) (a :: k) (b :: k) = Optic (Prostrong (PrismRes :: (k +-> k) -> (k +-> k) -> Constraint)) s t a b Source Github #

type Prism' (s :: k) (a :: k) = Prism s s a a 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 convert (l % p) idiom the test suite uses.

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

Instances details
(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 Market carrier.

Instance details

Defined in Proarrow.Optic.Prism

Methods

proact :: forall (f :: k +-> k) (g :: k +-> k). (w f g, Profunctor f, Profunctor g) => ((f :.: Market a b) :.: g) :~> Market a b Source Github #

(HasBinaryCoproducts k, Ob a, Ob b) => Profunctor (Market a b :: k -> k -> Type) Source Github # 
Instance details

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 ~> t, s ~> t || a) -- so they are equivalent. 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 #