| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Profunctor.Optic.Grate
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
- 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
- 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
- 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)
- 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
- zipsWith0 :: AGrate s t a b -> b -> t
- zipsWith2 :: AGrate s t a b -> (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 #
\( \mathsf{Grate}\;S\;A = \exists I, S \cong I \to A \)
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 Grates, 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 (
Procomposep 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.
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 $ zipsWith2 endomorphed (+) (Endo (*3)) (Endo (*4))14
continuedT :: Grate a (ContT r m a) (m r) (m r) 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
zipsWith0 :: AGrate s t a b -> b -> t Source #
Set all fields to the given value.
This is essentially a restricted variant of review.
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.
Methods
Instances
class Profunctor p => Costrong (p :: Type -> Type -> Type) where #
Methods
Instances
| MonadFix m => Costrong (Kleisli m) | |
| Costrong p => Costrong (Yoneda p) | |
| Costrong p => Costrong (Coyoneda p) | |
| Costrong (Cotambara p) | |
| Costrong (Copastro p) | |
| Functor f => Costrong (Costar f) | |
| ArrowLoop p => Costrong (WrappedArrow p) | |
Defined in Data.Profunctor.Strong Methods 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) | |