| Copyright | (c) Justin Le 2019 |
|---|---|
| License | BSD3 |
| Maintainer | [email protected] |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Control.Natural.IsoF
Description
Types describing isomorphisms between two functors, and functions to manipulate them.
Synopsis
- type (~>) (f :: k -> Type) (g :: k -> Type) = forall (x :: k). f x -> g x
- type (<~>) f g = forall p a. Profunctor p => p (g a) (g a) -> p (f a) (f a)
- isoF :: (f ~> g) -> (g ~> f) -> f <~> g
- coercedF :: forall f g. (forall x. Coercible (f x) (g x), forall x. Coercible (g x) (f x)) => f <~> g
- viewF :: (f <~> g) -> f ~> g
- reviewF :: (f <~> g) -> g ~> f
- overF :: (f <~> g) -> (g ~> g) -> f ~> f
- fromF :: forall (f :: Type -> Type) (g :: Type -> Type). (f <~> g) -> g <~> f
Documentation
type (~>) (f :: k -> Type) (g :: k -> Type) = forall (x :: k). f x -> g x infixr 0 #
A natural transformation from f to g.
type (<~>) f g = forall p a. Profunctor p => p (g a) (g a) -> p (f a) (f a) infixr 0 Source #
The type of an isomorphism between two functors. f means that
<~> gf and g are isomorphic to each other.
We can effectively use an f <~> g with:
viewF:: (f <~> g) -> f a -> g areviewF:: (f <~> g) -> g a -> a a
Use viewF to extract the "f to g" function, and reviewF to
extract the "g to f" function. Reviewing and viewing the same value
(or vice versa) leaves the value unchanged.
One nice thing is that we can compose isomorphisms using . from
Prelude:
(.) :: f <~> g
-> g <~> h
-> f <~> h
Another nice thing about this representation is that we have the
"identity" isomorphism by using id from Prelude.
id:: f<~>g
As a convention, most isomorphisms have form "X-ing", where the forwards function is "ing". For example, we have:
splittingSF::Monoidalt =>SFt a<~>t f (MFt f)splitSF:: Monoidal t => SF t a~>t f (MF t f)
isoF :: (f ~> g) -> (g ~> f) -> f <~> g Source #
Create an f by providing both legs of the isomorphism (the
<~> gf a -> g a and the g a -> f a.
coercedF :: forall f g. (forall x. Coercible (f x) (g x), forall x. Coercible (g x) (f x)) => f <~> g Source #
An isomorphism between two functors that are coercible/have the same internal representation. Useful for newtype wrappers.