Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Grate s t a b = forall p. Closed p => Optic p s t a b
- type Grate' s a = Grate s s a a
- type Cxgrate k s t a b = forall p. Closed p => CoindexedOptic p k s t a b
- type Cxgrate' k s a = Cxgrate k s s a a
- grate :: (((s -> a) -> b) -> t) -> Grate s t a b
- grateVl :: (forall f. Functor f => (f a -> b) -> f s -> t) -> Grate s t a b
- kgrateVl :: (forall f. Functor f => (k -> f a -> b) -> f s -> t) -> Cxgrate k s t a b
- inverting :: (s -> a) -> (b -> t) -> Grate s t a b
- cloneGrate :: AGrate s t a b -> Grate s t a b
- represented :: Representable f => Grate (f a) (f b) a b
- distributed :: Distributive f => Grate (f a) (f b) a b
- endomorphed :: Grate' (Endo a) a
- connected :: Conn s a -> Grate' s a
- continued :: Grate a (Cont r a) r r
- continuedT :: Grate a (ContT r m a) (m r) (m r)
- calledCC :: MonadCont m => Grate a (m a) (m b) (m a)
- unlifted :: MonadUnliftIO m => Grate (m a) (m b) (IO a) (IO b)
- kclosed :: Cxgrate k (c -> a) (c -> b) a b
- kfirst :: Cxgrate k a b (a, c) (b, c)
- ksecond :: Cxgrate k a b (c, a) (c, b)
- coindexed :: Representable f => (Additive - Monoid) (Rep f) => Cxgrate (Rep f) (f a) (f b) a b
- withGrate :: AGrate s t a b -> ((((s -> a) -> b) -> t) -> r) -> r
- withGrateVl :: Functor f => AGrate s t a b -> (f a -> b) -> f s -> t
- coview :: AGrate s t a b -> b -> t
- zipsWith :: AGrate s t a b -> (a -> a -> b) -> s -> s -> t
- kzipsWith :: (Additive - Monoid) k => ACxgrate k s t a b -> (k -> a -> a -> b) -> s -> s -> t
- zipsWith3 :: AGrate s t a b -> (a -> a -> a -> b) -> s -> s -> s -> t
- zipsWith4 :: AGrate s t a b -> (a -> a -> a -> a -> b) -> s -> s -> s -> s -> t
- toClosure :: Closed p => AGrate s t a b -> p a b -> Closure p s t
- toEnvironment :: Closed p => AGrate s t a b -> p a b -> Environment p s t
- class Profunctor p => Closed (p :: Type -> Type -> Type) where
- closed :: p a b -> p (x -> a) (x -> b)
- class Profunctor p => Costrong (p :: Type -> Type -> Type) where
Grate & Cxgrate
type Grate s t a b = forall p. Closed p => Optic p s t a b Source #
Grates access the codomain of a function.
\( \mathsf{Grate}\;S\;A = \exists I, S \cong I \to A \)
type Cxgrate k s t a b = forall p. Closed p => CoindexedOptic p k s t a b Source #
grate :: (((s -> a) -> b) -> t) -> Grate s t a b Source #
Obtain a Grate
from a nested continuation.
The resulting optic is the corepresentable counterpart to Lens
,
and sits between Iso
and Setter
.
A Grate
lets you lift a profunctor through any representable
functor (aka Naperian container). In the special case where the
indexing type is finitary (e.g. Bool
) then the tabulated type is
isomorphic to a fied length vector (e.g. 'V2 a').
The identity container is representable, and representable functors are closed under composition.
See https://www.cs.ox.ac.uk/jeremy.gibbons/publications/proyo.pdf
section 4.6 for more background on Grate
s, and compare to the
lens-family version.
Caution: In order for the generated optic to be well-defined, you must ensure that the input function satisfies the following properties:
sabt ($ s) ≡ s
sabt (k -> f (k . sabt)) ≡ sabt (k -> f ($ k))
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
.
grateVl :: (forall f. Functor f => (f a -> b) -> f s -> t) -> Grate s t a b Source #
Transform a Van Laarhoven grate into a profunctor grate.
Compare lensVl
& cotraversalVl
.
Caution: In order for the generated family to be well-defined, you must ensure that the traversal1 law holds for the input function:
abst runIdentity ≡ runIdentity
abst f . fmap (abst g) ≡ abst (f . fmap g . getCompose) . Compose
See Property
.
kgrateVl :: (forall f. Functor f => (k -> f a -> b) -> f s -> t) -> Cxgrate k s t a b Source #
TODO: Document
inverting :: (s -> a) -> (b -> t) -> Grate s t a b Source #
Construct a Grate
from a pair of inverses.
cloneGrate :: AGrate s t a b -> Grate s t a b Source #
TODO: Document
Optics
represented :: Representable f => Grate (f a) (f b) a b Source #
Obtain a Grate
from a Representable
functor.
distributed :: Distributive f => Grate (f a) (f b) a b Source #
Obtain a Grate
from a distributive functor.
endomorphed :: Grate' (Endo a) a Source #
Obtain a Grate
from an endomorphism.
>>>
flip appEndo 2 $ zipsWith endomorphed (+) (Endo (*3)) (Endo (*4))
14
connected :: Conn s a -> Grate' s a Source #
Obtain a Grate
from a Galois connection.
Useful for giving precise semantics to numerical computations.
This is an example of a Grate
that would not be a legal Iso
,
as Galois connections are not in general inverses.
>>>
zipsWith (connected i08i16) (+) 126 1
127>>>
zipsWith (connected i08i16) (+) 126 2
127
continuedT :: Grate a (ContT r m a) (m r) (m r) Source #
Indexed optics
coindexed :: Representable f => (Additive - Monoid) (Rep f) => Cxgrate (Rep f) (f a) (f b) a b Source #
Primitive operators
withGrate :: AGrate s t a b -> ((((s -> a) -> b) -> t) -> r) -> r Source #
Extract the function that characterizes a Grate
.
withGrateVl :: Functor f => AGrate s t a b -> (f a -> b) -> f s -> t Source #
Operators
coview :: AGrate s t a b -> b -> t Source #
Set all fields to the given value.
This is essentially a restricted variant of review
.
kzipsWith :: (Additive - Monoid) k => ACxgrate k s t a b -> (k -> a -> a -> b) -> s -> s -> t Source #
zipsWith3 :: AGrate s t a b -> (a -> a -> a -> b) -> s -> s -> s -> t Source #
Zip over a Grate
with 3 arguments.
zipsWith4 :: AGrate s t a b -> (a -> a -> a -> a -> b) -> s -> s -> s -> s -> t Source #
Zip over a Grate
with 4 arguments.
toEnvironment :: Closed p => AGrate s t a b -> p a b -> Environment p s t Source #
Use a Grate
to construct an Environment
.
Classes
class Profunctor p => Closed (p :: Type -> Type -> Type) where #
A strong profunctor allows the monoidal structure to pass through.
A closed profunctor allows the closed structure to pass through.
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 (Conjoin j) Source # | |
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 (Sum p q) | |
(Costrong p, Costrong q) => Costrong (Product p q) | |
(Functor f, Costrong p) => Costrong (Tannen f p) | |