Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Equality s t a b = forall p. Optic p s t a b
- type Equality' s a = Equality s s a a
- type Iso s t a b = forall p. Profunctor p => Optic p s t a b
- type Iso' s a = Iso s s a a
- iso :: (s -> a) -> (b -> t) -> Iso s t a b
- isoVl :: (forall f g. Functor f => Functor g => (g a -> f b) -> g s -> f t) -> Iso s t a b
- imapping :: Profunctor p => AIso s t a b -> IndexedOptic p i s t a b
- kmapping :: Profunctor p => AIso s t a b -> CoindexedOptic p k s t a b
- fmapping :: Functor f => Functor g => AIso s t a b -> Iso (f s) (g t) (f a) (g b)
- contramapping :: Contravariant f => Contravariant g => AIso s t a b -> Iso (f a) (g b) (f s) (g t)
- dimapping :: Profunctor p => Profunctor q => AIso s1 t1 a1 b1 -> AIso s2 t2 a2 b2 -> Iso (p a1 s2) (q b1 t2) (p s1 a2) (q t1 b2)
- toYoneda :: Profunctor p => Iso s t a b -> p a b -> Yoneda p s t
- toCoyoneda :: Iso s t a b -> p a b -> Coyoneda p s t
- cloneIso :: AIso s t a b -> Iso s t a b
- equaled :: s ~ a => t ~ b => Iso s t a b
- coerced :: Coercible s a => Coercible t b => Iso s t a b
- wrapped :: Newtype s => Iso' s (O s)
- rewrapped :: Newtype s => Newtype t => Iso s t (O s) (O t)
- rewrapped' :: Newtype s => Newtype t => (O s -> s) -> Iso s t (O s) (O t)
- generic :: Generic a => Generic b => Iso a b (Rep a c) (Rep b c)
- generic1 :: Generic1 f => Generic1 g => Iso (f a) (g b) (Rep1 f a) (Rep1 g b)
- adjuncted :: Adjunction f u => Iso (f a -> b) (f s -> t) (a -> u b) (s -> u t)
- tabulated :: Representable f => Representable g => Iso (f a) (g b) (Rep f -> a) (Rep g -> b)
- transposed :: Functor f => Distributive g => Iso (f (g a)) (g (f a)) (g (f a)) (f (g a))
- flipped :: Iso (a -> b -> c) (d -> e -> f) (b -> a -> c) (e -> d -> f)
- curried :: Iso (a -> b -> c) (d -> e -> f) ((a, b) -> c) ((d, e) -> f)
- unzipped :: Adjunction f u => Iso (u a, u b) (u c, u d) (u (a, b)) (u (c, d))
- cozipped :: Adjunction f u => Iso (f a + f b) (f c + f d) (f (a + b)) (f (c + d))
- swapped :: Iso (a, b) (c, d) (b, a) (d, c)
- coswapped :: Iso (a + b) (c + d) (b + a) (d + c)
- associated :: Iso (a, (b, c)) (d, (e, f)) ((a, b), c) ((d, e), f)
- coassociated :: Iso (a + (b + c)) (d + (e + f)) ((a + b) + c) ((d + e) + f)
- involuted :: (s -> a) -> Iso s a a s
- added :: Group a => a -> Iso' a a
- subtracted :: Group a => a -> Iso' a a
- non :: Eq a => a -> Iso' (Maybe a) a
- anon :: a -> (a -> Bool) -> Iso' (Maybe a) a
- withIso :: AIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r
- invert :: AIso s t a b -> Iso b a t s
- reover :: AIso s t a b -> (t -> s) -> b -> a
- reixed :: Profunctor p => AIso' i j -> IndexedOptic p i s t a b -> IndexedOptic p j s t a b
- recxed :: Profunctor p => AIso' k l -> CoindexedOptic p k s t a b -> CoindexedOptic p l s t a b
- op :: (Newtype n, o ~ O n) => (o -> n) -> n -> o
- au :: Functor f => AIso s t a b -> ((b -> t) -> f s) -> f a
- aup :: Profunctor p => Functor f => AIso s t a b -> (p c a -> f b) -> p c s -> f t
- ala :: Newtype s => Newtype t => Functor f => (O s -> s) -> ((O t -> t) -> f s) -> f (O s)
- newtype Re p s t a b = Re {
- runRe :: p b a -> p t s
Types
type Iso s t a b = forall p. Profunctor p => Optic p s t a b Source #
\( \mathsf{Iso}\;S\;A = S \cong A \)
iso :: (s -> a) -> (b -> t) -> Iso s t a b Source #
Obtain an Iso
from two inverses.
o .re
o ≡id
re
o . o ≡id
view
o (review
o b) ≡ breview
o (view
o s) ≡ s
Caution: In order for the generated optic to be well-defined, you must ensure that the input functions satisfy the following properties:
sa . bt ≡ id
bt . sa ≡ id
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
.
imapping :: Profunctor p => AIso s t a b -> IndexedOptic p i s t a b Source #
Lift an Iso
into an indexed version.
kmapping :: Profunctor p => AIso s t a b -> CoindexedOptic p k s t a b Source #
Lift an Iso
into a coindexed version.
fmapping :: Functor f => Functor g => AIso s t a b -> Iso (f s) (g t) (f a) (g b) Source #
Lift an Iso
into a pair of functors.
contramapping :: Contravariant f => Contravariant g => AIso s t a b -> Iso (f a) (g b) (f s) (g t) Source #
Lift an Iso
into a pair of Contravariant
functors.
contramapping ::Contravariant
f =>Iso
s t a b ->Iso
(f a) (f b) (f s) (f t)
dimapping :: Profunctor p => Profunctor q => AIso s1 t1 a1 b1 -> AIso s2 t2 a2 b2 -> Iso (p a1 s2) (q b1 t2) (p s1 a2) (q t1 b2) Source #
Lift a pair of Iso
s into a pair of profunctors.
Optics
equaled :: s ~ a => t ~ b => Iso s t a b Source #
Obtain an Iso'
directly from type equality constraints.
>>>
:t (^. equaled)
(^. equaled) :: b -> b
coerced :: Coercible s a => Coercible t b => Iso s t a b Source #
Obtain an Iso
from data types that are representationally equal.
>>>
view coerced 'x' :: Identity Char
Identity 'x'
rewrapped :: Newtype s => Newtype t => Iso s t (O s) (O t) Source #
Work between newtype wrappers.
>>>
Const "hello" & rewrapped ..~ Prelude.length & getConst
5
rewrapped' :: Newtype s => Newtype t => (O s -> s) -> Iso s t (O s) (O t) Source #
Variant of rewrapped
that ignores its argument.
generic :: Generic a => Generic b => Iso a b (Rep a c) (Rep b c) Source #
Obtain an Iso
from a Generic
representation.
>>>
view (generic . re generic) "hello" :: String
"hello"
generic1 :: Generic1 f => Generic1 g => Iso (f a) (g b) (Rep1 f a) (Rep1 g b) Source #
Obtain an Iso
from a Generic1
representation.
adjuncted :: Adjunction f u => Iso (f a -> b) (f s -> t) (a -> u b) (s -> u t) Source #
Obtain an Iso
from a functor and its adjoint.
Useful for converting between lens-like optics and grate-like optics:
over
adjuncted
::Adjunction
f u => ((a -> u b) -> s -> u t) -> (f a -> b) -> f s -> t
tabulated :: Representable f => Representable g => Iso (f a) (g b) (Rep f -> a) (Rep g -> b) Source #
Obtain an Iso
from a functor and its function representation.
transposed :: Functor f => Distributive g => Iso (f (g a)) (g (f a)) (g (f a)) (f (g a)) Source #
TODO: Document
flipped :: Iso (a -> b -> c) (d -> e -> f) (b -> a -> c) (e -> d -> f) Source #
Flip two arguments of a function.
>>>
(view flipped (,)) 1 2
(2,1)
curried :: Iso (a -> b -> c) (d -> e -> f) ((a, b) -> c) ((d, e) -> f) Source #
Curry a function.
>>>
(fst ^. invert curried) 3 4
3
unzipped :: Adjunction f u => Iso (u a, u b) (u c, u d) (u (a, b)) (u (c, d)) Source #
A right adjoint admits an intrinsic notion of zipping.
cozipped :: Adjunction f u => Iso (f a + f b) (f c + f d) (f (a + b)) (f (c + d)) Source #
A left adjoint must be inhabited by exactly one element.
associated :: Iso (a, (b, c)) (d, (e, f)) ((a, b), c) ((d, e), f) Source #
Iso
defined by left-association of nested tuples.
coassociated :: Iso (a + (b + c)) (d + (e + f)) ((a + b) + c) ((d + e) + f) Source #
Iso
defined by left-association of nested tuples.
subtracted :: Group a => a -> Iso' a a Source #
The group isomorphism defined by an element's inverse action.
subtracted
n =re
(added
n)
Primitive operators
withIso :: AIso s t a b -> ((s -> a) -> (b -> t) -> r) -> r Source #
Extract the two functions that characterize an Iso
.
Operators
reixed :: Profunctor p => AIso' i j -> IndexedOptic p i s t a b -> IndexedOptic p j s t a b Source #
Remap the indices of an indexed optic.
recxed :: Profunctor p => AIso' k l -> CoindexedOptic p k s t a b -> CoindexedOptic p l s t a b Source #
Remap the indices of a coindexed optic.
op :: (Newtype n, o ~ O n) => (o -> n) -> n -> o #
This function serves two purposes:
- Giving you the unpack of a newtype without you needing to remember the name.
- Showing that the first parameter is completely ignored on the value level, meaning the only reason you pass in the constructor is to provide type information. Typeclasses sure are neat.
>>>
op Identity (Identity 3)
3
au :: Functor f => AIso s t a b -> ((b -> t) -> f s) -> f a Source #
Based on ala from Conor McBride's work on Epigram.
This version is generalized to accept any Iso
, not just a newtype
.
>>>
au (rewrapped' Sum) foldMap [1,2,3,4]
10
You may want to think of this combinator as having the following, simpler type:
au :: AnIso s t a b -> ((b -> t) -> e -> s) -> e -> a
aup :: Profunctor p => Functor f => AIso s t a b -> (p c a -> f b) -> p c s -> f t Source #
Variant of au
for profunctors.
>>>
:t flip aup runStar
flip aup runStar :: Functor f => AIso s t a (f a) -> Star f c s -> c -> t
ala :: Newtype s => Newtype t => Functor f => (O s -> s) -> ((O t -> t) -> f s) -> f (O s) Source #
This combinator is based on ala
from Conor McBride's work on Epigram.
As with rewrapped'
, the user supplied function for the newtype is ignored.
>>>
ala Sum foldMap [1,2,3,4]
10
>>>
ala All foldMap [True,True]
True
>>>
ala All foldMap [True,False]
False
>>>
ala Any foldMap [False,False]
False
>>>
ala Any foldMap [True,False]
True
>>>
ala Product foldMap [1,2,3,4]
24
ala :: Newtype s => Newtype t => (O s -> s) -> ((O t -> t) -> e -> s) -> e -> O s
Auxilliary Types
The Re
type and its instances witness the symmetry between the parameters of a Profunctor
.
Instances
(Profunctor p, forall x. Contravariant (p x)) => Bifunctor (Re p s t) Source # | |
Cochoice p => Choice (Re p s t) Source # | |
Choice p => Cochoice (Re p s t) Source # | |
Costrong p => Strong (Re p s t) Source # | |
Strong p => Costrong (Re p s t) Source # | |
Profunctor p => Profunctor (Re p s t) Source # | |
Defined in Data.Profunctor.Optic.Types | |
Bifunctor p => Contravariant (Re p s t a) Source # | |