Safe Haskell | Safe-Inferred |
---|
A proxy morphism is a natural transformation:
morph :: forall r . p a' a b' b m r -> q a' a b' b n r
... that defines a functor between five categories:
- Functor between Kleisli categories:
morph p1 >=> morph p2 = morph (p1 >=> p2) morph return = return
- Functor between
Proxy
composition categories:
morph p1 >-> morph p2 = morph (p1 >-> p2) morph idT = idT
morph p1 >~> morph p2 = morph (p1 >~> p2) morph coidT = coidT
- Functor between
ListT
Kleisli categories:
morph p1 \>\ morph p2 = morph (p2 \>\ p2) morph request = request
morph p1 />/ morph p2 = morph (p2 />/ p2) morph respond = respond
Examples of proxy morphisms include:
-
liftP
(fromProxyTrans
) -
squashP
(See below) -
(See below) ifhoistP
ff
is a proxy morphism -
(f . g)
, iff
andg
are both proxy morphisms -
id
Proxy morphisms commonly arise when manipulating existing proxy transformer
code for compatibility purposes. The PFUnctor
, ProxyTrans
, and PMonad
classes define standard ways to change proxy transformer stacks:
Functors over Proxies
A functor in the category of proxies, using hoistP
as the analog of
fmap
:
hoistP f . hoistP g = hoistP (f . g) hoistP id = id
Monads over Proxies
class (PFunctor t, ProxyTrans t) => PMonad t whereSource
A monad in the category of monads, using liftP
from ProxyTrans
as the
analog of return
and embedP
as the analog of (=<<
):
embedP liftP = id embedP f (liftP p) = f p embed g (embed f t) = embed (\p -> embed g (f p)) t