Safe Haskell | None |
---|---|
Language | Haskell2010 |
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 (
Procompose
p 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) Int
Left 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.
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 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.
left' :: p a b -> p (Either a c) (Either b c) #
Laws:
left'
≡dimap
swapE swapE.
right'
where swapE ::Either
a b ->Either
b a swapE =either
Right
Left
rmap
Left
≡lmap
Left
.
left'
lmap
(right
f).
left'
≡rmap
(right
f).
left'
left'
.
left'
≡dimap
assocE unassocE.
left'
where assocE ::Either
(Either
a b) c ->Either
a (Either
b c) assocE (Left
(Left
a)) =Left
a assocE (Left
(Right
b)) =Right
(Left
b) assocE (Right
c) =Right
(Right
c) unassocE ::Either
a (Either
b c) ->Either
(Either
a b) c unassocE (Left
a) =Left
(Left
a) unassocE (Right
(Left
b)) =Left
(Right
b) unassocE (Right
(Right
c)) =Right
c
right' :: p a b -> p (Either c a) (Either c b) #
Laws:
right'
≡dimap
swapE swapE.
left'
where swapE ::Either
a b ->Either
b a swapE =either
Right
Left
rmap
Right
≡lmap
Right
.
right'
lmap
(left
f).
right'
≡rmap
(left
f).
right'
right'
.
right'
≡dimap
unassocE assocE.
right'
where assocE ::Either
(Either
a b) c ->Either
a (Either
b c) assocE (Left
(Left
a)) =Left
a assocE (Left
(Right
b)) =Right
(Left
b) assocE (Right
c) =Right
(Right
c) unassocE ::Either
a (Either
b c) ->Either
(Either
a b) c unassocE (Left
a) =Left
(Left
a) unassocE (Right
(Left
b)) =Left
(Right
b) unassocE (Right
(Right
c)) =Right
c