Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class Profunctor p => Closed (p :: Type -> Type -> Type) where
- closed :: p a b -> p (x -> a) (x -> b)
- 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
- type AGrate s t a b = Optic (GrateRep a b) s t a b
- type AGrate' s a = AGrate s s a a
- grate :: (((s -> a) -> b) -> t) -> Grate s t a b
- cxgrate :: (((s -> a) -> k -> b) -> t) -> Cxgrate k s t a b
- grateVl :: (forall f. Functor f => (f a -> b) -> f s -> t) -> Grate s t a b
- cxgrateVl :: (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
- newtype GrateRep a b s t = GrateRep {
- unGrateRep :: ((s -> a) -> b) -> t
- withGrate :: AGrate s t a b -> ((((s -> a) -> b) -> t) -> r) -> r
- constOf :: AGrate s t a b -> b -> t
- zipWithOf :: AGrate s t a b -> (a -> a -> b) -> s -> s -> t
- zipWith3Of :: AGrate s t a b -> (a -> a -> a -> b) -> s -> s -> s -> t
- zipWith4Of :: AGrate s t a b -> (a -> a -> a -> a -> b) -> s -> s -> s -> s -> t
- zipWithFOf :: Functor f => AGrate s t a b -> (f a -> b) -> f s -> t
- cxclosed :: Cxgrate k (c -> a) (c -> b) a b
- cxfirst :: Cxgrate k a b (a, c) (b, c)
- cxsecond :: Cxgrate k a b (c, a) (c, b)
- distributed :: Distributive f => Grate (f a) (f b) a b
- connected :: Conn s a -> Grate' s a
- forwarded :: Distributive m => MonadReader r m => Grate (m a) (m b) a b
- continued :: Grate a (Cont r a) r r
- unlifted :: MonadUnliftIO m => Grate (m a) (m b) (IO a) (IO b)
- toEnvironment :: Closed p => AGrate s t a b -> p a b -> Environment p s t
- toClosure :: Closed p => AGrate s t a b -> p a b -> Closure p s t
Types
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
(Distributive f, Monad f) => Closed (Kleisli f) | |
Defined in Data.Profunctor.Closed | |
Closed (Environment p) | |
Defined in Data.Profunctor.Closed closed :: Environment p a b -> Environment p (x -> a) (x -> b) # | |
Closed p => Closed (Coyoneda p) | |
Defined in Data.Profunctor.Yoneda | |
Closed p => Closed (Yoneda p) | |
Defined in Data.Profunctor.Yoneda | |
Profunctor p => Closed (Closure p) | |
Defined in Data.Profunctor.Closed | |
Distributive f => Closed (Star f) | |
Defined in Data.Profunctor.Closed | |
Functor f => Closed (Costar f) | |
Defined in Data.Profunctor.Closed | |
Closed (Tagged :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Closed | |
Closed ((->) :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Closed | |
Functor f => Closed (Cokleisli f) | |
Defined in Data.Profunctor.Closed | |
Closed (GrateRep a b) Source # | |
Defined in Data.Profunctor.Optic.Grate | |
(Closed p, Closed q) => Closed (Product p q) | |
Defined in Data.Profunctor.Closed | |
(Functor f, Closed p) => Closed (Tannen f p) | |
Defined in Data.Profunctor.Closed |
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 #
Constructors
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 fixed 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 -> h (k . sabt)) ≡ sabt (k -> h ($ 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 vlens
& cotraversalVl
.
cxgrateVl :: (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
Carriers
newtype GrateRep a b s t Source #
GrateRep | |
|
Instances
Corepresentable (GrateRep a b) Source # | |
Closed (GrateRep a b) Source # | |
Defined in Data.Profunctor.Optic.Grate | |
Costrong (GrateRep a b) Source # | |
Profunctor (GrateRep a b) Source # | |
Defined in Data.Profunctor.Optic.Grate dimap :: (a0 -> b0) -> (c -> d) -> GrateRep a b b0 c -> GrateRep a b a0 d # lmap :: (a0 -> b0) -> GrateRep a b b0 c -> GrateRep a b a0 c # rmap :: (b0 -> c) -> GrateRep a b a0 b0 -> GrateRep a b a0 c # (#.) :: Coercible c b0 => q b0 c -> GrateRep a b a0 b0 -> GrateRep a b a0 c # (.#) :: Coercible b0 a0 => GrateRep a b b0 c -> q a0 b0 -> GrateRep a b a0 c # | |
Cosieve (GrateRep a b) (Coindex a b) Source # | |
Defined in Data.Profunctor.Optic.Grate | |
type Corep (GrateRep a b) Source # | |
Defined in Data.Profunctor.Optic.Grate |
Primitive operators
withGrate :: AGrate s t a b -> ((((s -> a) -> b) -> t) -> r) -> r Source #
Extract the function that characterizes a Lens
.
zipWith3Of :: AGrate s t a b -> (a -> a -> a -> b) -> s -> s -> s -> t Source #
Zip over a Grate
with 3 arguments.
zipWith4Of :: AGrate s t a b -> (a -> a -> a -> a -> b) -> s -> s -> s -> s -> t Source #
Zip over a Grate
with 4 arguments.
zipWithFOf :: Functor f => AGrate s t a b -> (f a -> b) -> f s -> t Source #
Transform a profunctor grate into a Van Laarhoven grate.
This is a more restricted version of corepnOf
Optics
distributed :: Distributive f => Grate (f a) (f b) a b Source #
Access the contents of a distributive functor.
connected :: Conn s a -> Grate' s a Source #
Lift a Galois connection into a Grate
.
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.
>>>
zipWithOf (connected i08i16) (+) 126 1
127>>>
zipWithOf (connected i08i16) (+) 126 2
127
forwarded :: Distributive m => MonadReader r m => Grate (m a) (m b) a b Source #
Lift an action into a MonadReader
.
Operators
toEnvironment :: Closed p => AGrate s t a b -> p a b -> Environment p s t Source #
Use a Grate
to construct an Environment
.