{-# LANGUAGE RankNTypes #-}
module Control.Algebra.Handler
( Handler
, (~<~)
) where
import Data.Functor.Compose
type Handler ctx m n = forall x . ctx (m x) -> n (ctx x)
(~<~) :: (Functor n, Functor ctx1) => Handler ctx1 m n -> Handler ctx2 l m -> Handler (Compose ctx1 ctx2) l n
Handler ctx1 m n
hdl1 ~<~ :: forall (n :: * -> *) (ctx1 :: * -> *) (m :: * -> *)
(ctx2 :: * -> *) (l :: * -> *).
(Functor n, Functor ctx1) =>
Handler ctx1 m n
-> Handler ctx2 l m -> Handler (Compose ctx1 ctx2) l n
~<~ Handler ctx2 l m
hdl2 = (ctx1 (ctx2 x) -> Compose ctx1 ctx2 x)
-> n (ctx1 (ctx2 x)) -> n (Compose ctx1 ctx2 x)
forall a b. (a -> b) -> n a -> n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ctx1 (ctx2 x) -> Compose ctx1 ctx2 x
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (n (ctx1 (ctx2 x)) -> n (Compose ctx1 ctx2 x))
-> (Compose ctx1 ctx2 (l x) -> n (ctx1 (ctx2 x)))
-> Compose ctx1 ctx2 (l x)
-> n (Compose ctx1 ctx2 x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ctx1 (m (ctx2 x)) -> n (ctx1 (ctx2 x))
Handler ctx1 m n
hdl1 (ctx1 (m (ctx2 x)) -> n (ctx1 (ctx2 x)))
-> (Compose ctx1 ctx2 (l x) -> ctx1 (m (ctx2 x)))
-> Compose ctx1 ctx2 (l x)
-> n (ctx1 (ctx2 x))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ctx2 (l x) -> m (ctx2 x))
-> ctx1 (ctx2 (l x)) -> ctx1 (m (ctx2 x))
forall a b. (a -> b) -> ctx1 a -> ctx1 b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ctx2 (l x) -> m (ctx2 x)
Handler ctx2 l m
hdl2 (ctx1 (ctx2 (l x)) -> ctx1 (m (ctx2 x)))
-> (Compose ctx1 ctx2 (l x) -> ctx1 (ctx2 (l x)))
-> Compose ctx1 ctx2 (l x)
-> ctx1 (m (ctx2 x))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose ctx1 ctx2 (l x) -> ctx1 (ctx2 (l x))
forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose
{-# INLINE (~<~) #-}
infixr 1 ~<~