profunctor-optics-0.0.1: An optics library compatible with the typeclasses in 'profunctors'.

Safe HaskellNone
LanguageHaskell2010

Data.Profunctor.Optic.Affine

Contents

Synopsis

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 \)

type Affine' s a = Affine s s a a Source #

type Ixaffine i s t a b = forall p. (Choice p, Strong p) => IndexedOptic p i s t a b Source #

type Ixaffine' i s a = Ixaffine i s s a a Source #

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:

See Property.

affine' :: (s -> Maybe a) -> (s -> a -> s) -> Affine' s a Source #

Obtain a Affine' from match and constructor functions.

iaffine :: (s -> t + (i, a)) -> (s -> b -> t) -> Ixaffine i s t a b Source #

TODO: Document

iaffine' :: (s -> Maybe (i, a)) -> (s -> a -> s) -> Ixaffine' i s a Source #

TODO: Document

affineVl :: (forall f. Functor f => (forall c. c -> f c) -> (a -> f b) -> s -> f t) -> Affine s t a b Source #

Transform a Van Laarhoven Affine into a profunctor Affine.

iaffineVl :: (forall f. Functor f => (forall c. c -> f c) -> (i -> a -> f b) -> s -> f t) -> Ixaffine i s t a b Source #

Transform an indexed Van Laarhoven Affine into an indexed profunctor Affine.

Optics

nulled :: Affine' s a Source #

TODO: Document

selected :: (a -> Bool) -> Affine' (a, b) b Source #

TODO: Document

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.

http://www.riec.tohoku.ac.jp/~asada/papers/arrStrMnd.pdf

Minimal complete definition

first' | second'

Methods

first' :: p a b -> p (a, c) (b, c) #

Laws:

first'dimap swap swap . second'
lmap fstrmap fst . first'
lmap (second' f) . first'rmap (second' f) . first'
first' . first'dimap assoc unassoc . first' where
  assoc ((a,b),c) = (a,(b,c))
  unassoc (a,(b,c)) = ((a,b),c)

second' :: p a b -> p (c, a) (c, b) #

Laws:

second'dimap swap swap . first'
lmap sndrmap snd . second'
lmap (first' f) . second'rmap (first' f) . second'
second' . second'dimap unassoc assoc . second' where
  assoc ((a,b),c) = (a,(b,c))
  unassoc (a,(b,c)) = ((a,b),c)
Instances
Monad m => Strong (Kleisli m) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Kleisli m a b -> Kleisli m (a, c) (b, c) #

second' :: Kleisli m a b -> Kleisli m (c, a) (c, b) #

Strong (Pastro p) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Pastro p a b -> Pastro p (a, c) (b, c) #

second' :: Pastro p a b -> Pastro p (c, a) (c, b) #

Strong p => Strong (Coyoneda p) 
Instance details

Defined in Data.Profunctor.Yoneda

Methods

first' :: Coyoneda p a b -> Coyoneda p (a, c) (b, c) #

second' :: Coyoneda p a b -> Coyoneda p (c, a) (c, b) #

Strong p => Strong (Yoneda p) 
Instance details

Defined in Data.Profunctor.Yoneda

Methods

first' :: Yoneda p a b -> Yoneda p (a, c) (b, c) #

second' :: Yoneda p a b -> Yoneda p (c, a) (c, b) #

Strong p => Strong (Closure p) 
Instance details

Defined in Data.Profunctor.Closed

Methods

first' :: Closure p a b -> Closure p (a, c) (b, c) #

second' :: Closure p a b -> Closure p (c, a) (c, b) #

Profunctor p => Strong (Tambara p) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Tambara p a b -> Tambara p (a, c) (b, c) #

second' :: Tambara p a b -> Tambara p (c, a) (c, b) #

Functor m => Strong (Star m) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Star m a b -> Star m (a, c) (b, c) #

second' :: Star m a b -> Star m (c, a) (c, b) #

Arrow p => Strong (WrappedArrow p)

Arrow is Strong Category

Instance details

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) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Forget r a b -> Forget r (a, c) (b, c) #

second' :: Forget r a b -> Forget r (c, a) (c, b) #

Strong (Conjoin j) Source # 
Instance details

Defined in Data.Profunctor.Optic.Index

Methods

first' :: Conjoin j a b -> Conjoin j (a, c) (b, c) #

second' :: Conjoin j a b -> Conjoin j (c, a) (c, b) #

Strong (OptionRep r) Source # 
Instance details

Defined in Data.Profunctor.Optic.Carrier

Methods

first' :: OptionRep r a b -> OptionRep r (a, c) (b, c) #

second' :: OptionRep r a b -> OptionRep r (c, a) (c, b) #

Strong ((->) :: Type -> Type -> Type) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: (a -> b) -> (a, c) -> (b, c) #

second' :: (a -> b) -> (c, a) -> (c, b) #

Strong (AffineRep a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Carrier

Methods

first' :: AffineRep a b a0 b0 -> AffineRep a b (a0, c) (b0, c) #

second' :: AffineRep a b a0 b0 -> AffineRep a b (c, a0) (c, b0) #

Strong (LensRep a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Carrier

Methods

first' :: LensRep a b a0 b0 -> LensRep a b (a0, c) (b0, c) #

second' :: LensRep a b a0 b0 -> LensRep a b (c, a0) (c, b0) #

Contravariant f => Strong (Clown f :: Type -> Type -> Type) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Clown f a b -> Clown f (a, c) (b, c) #

second' :: Clown f a b -> Clown f (c, a) (c, b) #

Costrong p => Strong (Re p s t) Source # 
Instance details

Defined in Data.Profunctor.Optic.Types

Methods

first' :: Re p s t a b -> Re p s t (a, c) (b, c) #

second' :: Re p s t a b -> Re p s t (c, a) (c, b) #

Strong (IxlensRep i a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Carrier

Methods

first' :: IxlensRep i a b a0 b0 -> IxlensRep i a b (a0, c) (b0, c) #

second' :: IxlensRep i a b a0 b0 -> IxlensRep i a b (c, a0) (c, b0) #

(Strong p, Strong q) => Strong (Sum p q) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Sum p q a b -> Sum p q (a, c) (b, c) #

second' :: Sum p q a b -> Sum p q (c, a) (c, b) #

(Strong p, Strong q) => Strong (Product p q) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Product p q a b -> Product p q (a, c) (b, c) #

second' :: Product p q a b -> Product p q (c, a) (c, b) #

(Functor f, Strong p) => Strong (Tannen f p) 
Instance details

Defined in Data.Profunctor.Strong

Methods

first' :: Tannen f p a b -> Tannen f p (a, c) (b, c) #

second' :: Tannen f p a b -> Tannen f p (c, a) (c, b) #

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.

Minimal complete definition

left' | right'

Methods

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 Leftlmap 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 Rightlmap 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
Instances
Monad m => Choice (Kleisli m) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Kleisli m a b -> Kleisli m (Either a c) (Either b c) #

right' :: Kleisli m a b -> Kleisli m (Either c a) (Either c b) #

Choice (PastroSum p) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: PastroSum p a b -> PastroSum p (Either a c) (Either b c) #

right' :: PastroSum p a b -> PastroSum p (Either c a) (Either c b) #

Choice p => Choice (Coyoneda p) 
Instance details

Defined in Data.Profunctor.Yoneda

Methods

left' :: Coyoneda p a b -> Coyoneda p (Either a c) (Either b c) #

right' :: Coyoneda p a b -> Coyoneda p (Either c a) (Either c b) #

Choice p => Choice (Yoneda p) 
Instance details

Defined in Data.Profunctor.Yoneda

Methods

left' :: Yoneda p a b -> Yoneda p (Either a c) (Either b c) #

right' :: Yoneda p a b -> Yoneda p (Either c a) (Either c b) #

Profunctor p => Choice (TambaraSum p) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: TambaraSum p a b -> TambaraSum p (Either a c) (Either b c) #

right' :: TambaraSum p a b -> TambaraSum p (Either c a) (Either c b) #

Choice p => Choice (Tambara p) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Tambara p a b -> Tambara p (Either a c) (Either b c) #

right' :: Tambara p a b -> Tambara p (Either c a) (Either c b) #

Applicative f => Choice (Star f) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Star f a b -> Star f (Either a c) (Either b c) #

right' :: Star f a b -> Star f (Either c a) (Either c b) #

Coapplicative f => Choice (Costar f) Source # 
Instance details

Defined in Data.Profunctor.Optic.Types

Methods

left' :: Costar f a b -> Costar f (Either a c) (Either b c) #

right' :: Costar f a b -> Costar f (Either c a) (Either c b) #

ArrowChoice p => Choice (WrappedArrow p) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: WrappedArrow p a b -> WrappedArrow p (Either a c) (Either b c) #

right' :: WrappedArrow p a b -> WrappedArrow p (Either c a) (Either c b) #

Monoid r => Choice (Forget r) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Forget r a b -> Forget r (Either a c) (Either b c) #

right' :: Forget r a b -> Forget r (Either c a) (Either c b) #

Choice (Tagged :: Type -> Type -> Type) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Tagged a b -> Tagged (Either a c) (Either b c) #

right' :: Tagged a b -> Tagged (Either c a) (Either c b) #

Choice (Conjoin j) Source # 
Instance details

Defined in Data.Profunctor.Optic.Index

Methods

left' :: Conjoin j a b -> Conjoin j (Either a c) (Either b c) #

right' :: Conjoin j a b -> Conjoin j (Either c a) (Either c b) #

Choice (OptionRep r) Source # 
Instance details

Defined in Data.Profunctor.Optic.Carrier

Methods

left' :: OptionRep r a b -> OptionRep r (Either a c) (Either b c) #

right' :: OptionRep r a b -> OptionRep r (Either c a) (Either c b) #

Choice ((->) :: Type -> Type -> Type) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: (a -> b) -> Either a c -> Either b c #

right' :: (a -> b) -> Either c a -> Either c b #

Comonad w => Choice (Cokleisli w)

extract approximates costrength

Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Cokleisli w a b -> Cokleisli w (Either a c) (Either b c) #

right' :: Cokleisli w a b -> Cokleisli w (Either c a) (Either c b) #

Choice (GrismRep a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Carrier

Methods

left' :: GrismRep a b a0 b0 -> GrismRep a b (Either a0 c) (Either b0 c) #

right' :: GrismRep a b a0 b0 -> GrismRep a b (Either c a0) (Either c b0) #

Choice (AffineRep a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Carrier

Methods

left' :: AffineRep a b a0 b0 -> AffineRep a b (Either a0 c) (Either b0 c) #

right' :: AffineRep a b a0 b0 -> AffineRep a b (Either c a0) (Either c b0) #

Choice (PrismRep a b) Source # 
Instance details

Defined in Data.Profunctor.Optic.Carrier

Methods

left' :: PrismRep a b a0 b0 -> PrismRep a b (Either a0 c) (Either b0 c) #

right' :: PrismRep a b a0 b0 -> PrismRep a b (Either c a0) (Either c b0) #

Functor f => Choice (Joker f :: Type -> Type -> Type) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Joker f a b -> Joker f (Either a c) (Either b c) #

right' :: Joker f a b -> Joker f (Either c a) (Either c b) #

Cochoice p => Choice (Re p s t) Source # 
Instance details

Defined in Data.Profunctor.Optic.Types

Methods

left' :: Re p s t a b -> Re p s t (Either a c) (Either b c) #

right' :: Re p s t a b -> Re p s t (Either c a) (Either c b) #

(Choice p, Choice q) => Choice (Sum p q) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Sum p q a b -> Sum p q (Either a c) (Either b c) #

right' :: Sum p q a b -> Sum p q (Either c a) (Either c b) #

(Choice p, Choice q) => Choice (Product p q) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Product p q a b -> Product p q (Either a c) (Either b c) #

right' :: Product p q a b -> Product p q (Either c a) (Either c b) #

(Functor f, Choice p) => Choice (Tannen f p) 
Instance details

Defined in Data.Profunctor.Choice

Methods

left' :: Tannen f p a b -> Tannen f p (Either a c) (Either b c) #

right' :: Tannen f p a b -> Tannen f p (Either c a) (Either c b) #