Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Lens s t a b = forall p. Strong p => Optic p s t a b
- type Ixlens i s t a b = forall p. Strong p => IndexedOptic p i s t a b
- type Lens' s a = Lens s s a a
- type Ixlens' i s a = Ixlens i s s a a
- lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
- ixlens :: (s -> (i, a)) -> (s -> b -> t) -> Ixlens i s t a b
- lensVl :: (forall f. Functor f => (a -> f b) -> s -> f t) -> Lens s t a b
- ixlensVl :: (forall f. Functor f => (i -> a -> f b) -> s -> f t) -> Ixlens i s t a b
- matching :: (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b
- cloneLens :: ALens s t a b -> Lens s t a b
- type Colens s t a b = forall p. Costrong p => Optic p s t a b
- type Cxlens k s t a b = forall p. Costrong p => CoindexedOptic p k s t a b
- type Colens' s a = Colens s s a a
- type Cxlens' k s a = Cxlens k s s a a
- colens :: (b -> s -> a) -> (b -> t) -> Colens s t a b
- colensVl :: (forall f. Functor f => (t -> f s) -> b -> f a) -> Colens s t a b
- comatching :: ((c, s) -> a) -> (b -> (c, t)) -> Colens s t a b
- ixfirst :: Ixlens i (a, c) (b, c) a b
- cofirst :: Colens a b (a, c) (b, c)
- ixsecond :: Ixlens i (c, a) (c, b) a b
- cosecond :: Colens a b (c, a) (c, b)
- united :: Lens' a ()
- voided :: Lens' Void a
- valued :: Eq k => k -> Lens' (k -> v) v
- root :: Lens' (Tree a) a
- branches :: Lens' (Tree a) [Tree a]
- withLens :: ALens s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r
- withIxlens :: Monoid i => AIxlens i s t a b -> ((s -> (i, a)) -> (s -> b -> t) -> r) -> r
- toPastro :: ALens s t a b -> p a b -> Pastro p s t
- toTambara :: Strong p => ALens s t a b -> p a b -> Tambara p s t
- type ALens s t a b = Optic (LensRep a b) s t a b
- type ALens' s a = ALens s s a a
- type AIxlens i s t a b = IndexedOptic (IxlensRep i a b) i s t a b
- type AIxlens' i s a = AIxlens i s s a a
- data LensRep a b s t = LensRep (s -> a) (s -> b -> t)
- data IxlensRep i a b s t = IxlensRep (s -> (i, a)) (s -> b -> t)
- class Profunctor p => Strong (p :: Type -> Type -> Type) where
- class Profunctor p => Costrong (p :: Type -> Type -> Type) where
Lens & Ixlens
type Lens s t a b = forall p. Strong p => Optic p s t a b Source #
Lenses access one piece of a product.
\( \mathsf{Lens}\;S\;A = \exists C, S \cong C \times A \)
type Ixlens i s t a b = forall p. Strong p => IndexedOptic p i s t a b Source #
ixlens :: (s -> (i, a)) -> (s -> b -> t) -> Ixlens i s t a b Source #
Obtain an indexed Lens
from an indexed getter and a setter.
Compare lens
and ixtraversal
.
Caution: In order for the generated optic to be well-defined, you must ensure that the input functions constitute a legal indexed lens:
snd . sia (sbt s a) ≡ a
sbt s (snd $ sia s) ≡ s
sbt (sbt s a1) a2 ≡ sbt s a2
See Property
.
lensVl :: (forall f. Functor f => (a -> f b) -> s -> f t) -> Lens s t a b Source #
Transform a Van Laarhoven lens into a profunctor lens.
Compare grateVl
and traversalVl
.
Caution: In order for the generated optic to be well-defined, you must ensure that the input satisfies the following properties:
abst Identity ≡ Identity
fmap (abst f) . (abst g) ≡ getCompose . abst (Compose . fmap f . g)
More generally, a profunctor optic must be monoidal as a natural transformation:
o id ≡ id
o (
Procompose
p q) ≡Procompose
(o p) (o q)
ixlensVl :: (forall f. Functor f => (i -> a -> f b) -> s -> f t) -> Ixlens i s t a b Source #
Transform an indexed Van Laarhoven lens into an indexed profunctor Lens
.
An Ixlens
is a valid Lens
and a valid IxTraversal
.
Compare lensVl
& ixtraversalVl
.
Caution: In order for the generated optic to be well-defined, you must ensure that the input satisfies the following properties:
iabst (const Identity) ≡ Identity
fmap (iabst $ const f) . (iabst $ const g) ≡ getCompose . iabst (const $ Compose . fmap f . g)
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
.
matching :: (s -> (c, a)) -> ((c, b) -> t) -> Lens s t a b Source #
Obtain a Lens
from its free tensor representation.
Colens & Cxlens
type Cxlens k s t a b = forall p. Costrong p => CoindexedOptic p k s t a b Source #
colens :: (b -> s -> a) -> (b -> t) -> Colens s t a b Source #
Obtain a Colens
from a getter and setter.
colens
f g ≡ \f g ->re
(lens
f g)colens
bsia bt ≡colensVl
$
\ts b -> bsia b<$>
(ts . bt$
b)review
$colens
f g ≡ fset
.re
$re
(lens
f g) ≡ g
A Colens
is a Review
, so you can specialise types to obtain:
review
::Colens'
s a -> a -> s
Caution: In addition to the normal optic laws, the input functions must have the correct laziness annotations.
For example, this is a perfectly valid Colens
:
co1 :: Colens a b (a, c) (b, c) co1 = flip colens fst $ ~(_,y) b -> (b,y)
However removing the annotation will result in a faulty optic.
See Property
.
colensVl :: (forall f. Functor f => (t -> f s) -> b -> f a) -> Colens s t a b Source #
Transform a Van Laarhoven colens into a profunctor colens.
Compare grateVl
.
Caution: In addition to the normal optic laws, the input functions must have the correct laziness annotations.
For example, this is a perfectly valid Colens
:
co1 = colensVl $ f ~(a,b) -> (,b) $ f a
However removing the annotation will result in a faulty optic.
comatching :: ((c, s) -> a) -> (b -> (c, t)) -> Colens s t a b Source #
Obtain a Colens
from its free tensor representation.
Optics
ixfirst :: Ixlens i (a, c) (b, c) a b Source #
TODO: Document
>>>
ixlists (ix @Int traversed . ix first' . ix traversed) [("foo",1), ("bar",2)]
[(0,'f'),(1,'o'),(2,'o'),(0,'b'),(1,'a'),(2,'r')]
>>>
ixlists (ix @Int traversed . ixfirst . ix traversed) [("foo",1), ("bar",2)]
[(0,'f'),(1,'o'),(2,'o'),(0,'b'),(1,'a'),(2,'r')]
>>>
ixlists (ix @Int traversed % ix first' % ix traversed) [("foo",1), ("bar",2)]
[(0,'f'),(1,'o'),(2,'o'),(1,'b'),(2,'a'),(3,'r')]
>>>
ixlists (ix @Int traversed % ixfirst % ix traversed) [("foo",1), ("bar",2)]
[(0,'f'),(1,'o'),(2,'o'),(2,'b'),(3,'a'),(4,'r')]
There is a Unit
in everything.
>>>
"hello" ^. united
()>>>
"hello" & united .~ ()
"hello"
voided :: Lens' Void a Source #
There is everything in a Void
.
>>>
[] & fmapped . voided <>~ "Void"
[]>>>
Nothing & fmapped . voided ..~ abs
Nothing
Primitive operators
withLens :: ALens s t a b -> ((s -> a) -> (s -> b -> t) -> r) -> r Source #
Extract the two functions that characterize a Lens
.
withIxlens :: Monoid i => AIxlens i s t a b -> ((s -> (i, a)) -> (s -> b -> t) -> r) -> r Source #
Extract the two functions that characterize a Lens
.
Operators
Carriers
type AIxlens i s t a b = IndexedOptic (IxlensRep i a b) i s t a b Source #
LensRep (s -> a) (s -> b -> t) |
Instances
Representable (LensRep a b) Source # | |
Strong (LensRep a b) Source # | |
Profunctor (LensRep a b) Source # | |
Defined in Data.Profunctor.Optic.Lens dimap :: (a0 -> b0) -> (c -> d) -> LensRep a b b0 c -> LensRep a b a0 d # lmap :: (a0 -> b0) -> LensRep a b b0 c -> LensRep a b a0 c # rmap :: (b0 -> c) -> LensRep a b a0 b0 -> LensRep a b a0 c # (#.) :: Coercible c b0 => q b0 c -> LensRep a b a0 b0 -> LensRep a b a0 c # (.#) :: Coercible b0 a0 => LensRep a b b0 c -> q a0 b0 -> LensRep a b a0 c # | |
Sieve (LensRep a b) (Index a b) Source # | |
Defined in Data.Profunctor.Optic.Lens | |
type Rep (LensRep a b) Source # | |
Defined in Data.Profunctor.Optic.Lens |
data IxlensRep i a b s t Source #
IxlensRep (s -> (i, a)) (s -> b -> t) |
Instances
Strong (IxlensRep i a b) Source # | |
Profunctor (IxlensRep i a b) Source # | |
Defined in Data.Profunctor.Optic.Lens dimap :: (a0 -> b0) -> (c -> d) -> IxlensRep i a b b0 c -> IxlensRep i a b a0 d # lmap :: (a0 -> b0) -> IxlensRep i a b b0 c -> IxlensRep i a b a0 c # rmap :: (b0 -> c) -> IxlensRep i a b a0 b0 -> IxlensRep i a b a0 c # (#.) :: Coercible c b0 => q b0 c -> IxlensRep i a b a0 b0 -> IxlensRep i a b a0 c # (.#) :: Coercible b0 a0 => IxlensRep i a b b0 c -> q a0 b0 -> IxlensRep i a b a0 c # |
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-kb.is.s.u-tokyo.ac.jp/~asada/papers/arrStrMnd.pdf
Instances
class Profunctor p => Costrong (p :: Type -> Type -> Type) where #
Instances
MonadFix m => Costrong (Kleisli m) | |
Costrong p => Costrong (Coyoneda p) | |
Costrong p => Costrong (Yoneda p) | |
Costrong (Cotambara p) | |
Costrong (Copastro p) | |
Functor f => Costrong (Costar f) | |
ArrowLoop p => Costrong (WrappedArrow p) | |
Defined in Data.Profunctor.Strong unfirst :: WrappedArrow p (a, d) (b, d) -> WrappedArrow p a b # unsecond :: WrappedArrow p (d, a) (d, b) -> WrappedArrow p a b # | |
Costrong (Tagged :: Type -> Type -> Type) | |
Costrong ((->) :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Strong | |
Functor f => Costrong (Cokleisli f) | |
Costrong (GrateRep a b) Source # | |
Strong p => Costrong (Re p s t) Source # | |
(Costrong p, Costrong q) => Costrong (Product p q) | |
(Functor f, Costrong p) => Costrong (Tannen f p) | |