| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Profunctor.Optic.Affine
Synopsis
- type Affine s t a b = forall p. (Choice p, Strong p) => Optic p s t a b
- type Affine' s a = Affine s s a a
- type Ixaffine i s t a b = forall p. (Choice p, Strong p) => IndexedOptic p i s t a b
- type Ixaffine' i s a = Ixaffine i s s a a
- affine :: (s -> t + a) -> (s -> b -> t) -> Affine s t a b
- affine' :: (s -> Maybe a) -> (s -> a -> s) -> Affine' s a
- iaffine :: (s -> t + (i, a)) -> (s -> b -> t) -> Ixaffine i s t a b
- iaffine' :: (s -> Maybe (i, a)) -> (s -> a -> s) -> Ixaffine' i s a
- affineVl :: (forall f. Functor f => (forall c. c -> f c) -> (a -> f b) -> s -> f t) -> Affine s t a b
- iaffineVl :: (forall f. Functor f => (forall c. c -> f c) -> (i -> a -> f b) -> s -> f t) -> Ixaffine i s t a b
- nulled :: Affine' s a
- selected :: (a -> Bool) -> Affine' (a, b) b
- withAffine :: AAffine s t a b -> ((s -> t + a) -> (s -> b -> t) -> r) -> r
- matches :: AAffine s t a b -> s -> t + a
- class Profunctor p => Strong (p :: Type -> Type -> Type) where
- class Profunctor p => Choice (p :: Type -> Type -> Type) where
Affine & Ixaffine
type Affine s t a b = forall p. (Choice p, Strong p) => Optic p s t a b Source #
A Affine processes 0 or more parts of the whole, with no interactions.
\( \mathsf{Affine}\;S\;A = \exists C, D, S \cong D + C \times A \)
affine :: (s -> t + a) -> (s -> b -> t) -> Affine s t a b Source #
Create a Affine from match and constructor functions.
Caution: In order for the Affine to be well-defined,
you must ensure that the input functions satisfy the following
properties:
sta (sbt a s) ≡ either (Left . const a) Right (sta s)
either id (sbt s) (sta s) ≡ s
sbt (sbt s a1) a2 ≡ sbt s a2
More generally, a profunctor optic must be monoidal as a natural transformation:
o id ≡ id
o (
Procomposep q) ≡Procompose(o p) (o q)
See Property.
affine' :: (s -> Maybe a) -> (s -> a -> s) -> Affine' s a Source #
Obtain a Affine' from match and constructor functions.
affineVl :: (forall f. Functor f => (forall c. c -> f c) -> (a -> f b) -> s -> f t) -> Affine s t a b Source #
iaffineVl :: (forall f. Functor f => (forall c. c -> f c) -> (i -> a -> f b) -> s -> f t) -> Ixaffine i s t a b Source #
Optics
Primitive operators
withAffine :: AAffine s t a b -> ((s -> t + a) -> (s -> b -> t) -> r) -> r Source #
TODO: Document
Operators
matches :: AAffine s t a b -> s -> t + a Source #
Test whether the optic matches or not.
>>>matches just (Just 2)Right 2
>>>matches just (Nothing :: Maybe Int) :: Either (Maybe Bool) IntLeft Nothing
Classes
class Profunctor p => Strong (p :: Type -> Type -> Type) where #
Generalizing Star of a strong Functor
Note: Every Functor in Haskell is strong with respect to (,).
This describes profunctor strength with respect to the product structure of Hask.
Methods
Instances
| Monad m => Strong (Kleisli m) | |
| Strong (Pastro p) | |
| Strong p => Strong (Coyoneda p) | |
| Strong p => Strong (Yoneda p) | |
| Strong p => Strong (Closure p) | |
| Profunctor p => Strong (Tambara p) | |
| Functor m => Strong (Star m) | |
| Arrow p => Strong (WrappedArrow p) | |
Defined in Data.Profunctor.Strong Methods first' :: WrappedArrow p a b -> WrappedArrow p (a, c) (b, c) # second' :: WrappedArrow p a b -> WrappedArrow p (c, a) (c, b) # | |
| Strong (Forget r) | |
| Strong (Conjoin j) Source # | |
| Strong (OptionRep r) Source # | |
| Strong ((->) :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Strong | |
| Strong (AffineRep a b) Source # | |
| Strong (LensRep a b) Source # | |
| Contravariant f => Strong (Clown f :: Type -> Type -> Type) | |
| Costrong p => Strong (Re p s t) Source # | |
| Strong (IxlensRep i a b) Source # | |
| (Strong p, Strong q) => Strong (Sum p q) | |
| (Strong p, Strong q) => Strong (Product p q) | |
| (Functor f, Strong p) => Strong (Tannen f p) | |
class Profunctor p => Choice (p :: Type -> Type -> Type) where #
The generalization of Costar of Functor that is strong with respect
to Either.
Note: This is also a notion of strength, except with regards to another monoidal structure that we can choose to equip Hask with: the cocartesian coproduct.
Methods
left' :: p a b -> p (Either a c) (Either b c) #
Laws:
left'≡dimapswapE swapE.right'where swapE ::Eithera b ->Eitherb a swapE =eitherRightLeftrmapLeft≡lmapLeft.left'lmap(rightf).left'≡rmap(rightf).left'left'.left'≡dimapassocE unassocE.left'where assocE ::Either(Eithera b) c ->Eithera (Eitherb c) assocE (Left(Lefta)) =Lefta assocE (Left(Rightb)) =Right(Leftb) assocE (Rightc) =Right(Rightc) unassocE ::Eithera (Eitherb c) ->Either(Eithera b) c unassocE (Lefta) =Left(Lefta) unassocE (Right(Leftb)) =Left(Rightb) unassocE (Right(Rightc)) =Rightc
right' :: p a b -> p (Either c a) (Either c b) #
Laws:
right'≡dimapswapE swapE.left'where swapE ::Eithera b ->Eitherb a swapE =eitherRightLeftrmapRight≡lmapRight.right'lmap(leftf).right'≡rmap(leftf).right'right'.right'≡dimapunassocE assocE.right'where assocE ::Either(Eithera b) c ->Eithera (Eitherb c) assocE (Left(Lefta)) =Lefta assocE (Left(Rightb)) =Right(Leftb) assocE (Rightc) =Right(Rightc) unassocE ::Eithera (Eitherb c) ->Either(Eithera b) c unassocE (Lefta) =Left(Lefta) unassocE (Right(Leftb)) =Left(Rightb) unassocE (Right(Rightc)) =Rightc