{-# LANGUAGE TemplateHaskell #-}
module Polysemy.Several
(
HList(..)
, TypeMap
, TypeConcat
, runSeveral
) where
import Polysemy
import Data.Kind
infixr 5 :::
data HList a where
HNil :: HList '[]
(:::) :: a -> HList (b :: [Type]) -> HList (a ': b)
type family TypeMap (f :: a -> b) (xs :: [a]) where
TypeMap _ '[] = '[]
TypeMap f (x ': xs) = f x ': TypeMap f xs
type family TypeConcat (a :: [t]) (b :: [t]) where
TypeConcat '[] b = b
TypeConcat (a ': as) b = a ': TypeConcat as b
runSeveral
:: (forall r' k x. k -> Sem (e k ': r') x -> Sem r' x)
-> HList t
-> Sem (TypeConcat (TypeMap e t) r) a
-> Sem r a
runSeveral :: (forall (r' :: [Effect]) k x. k -> Sem (e k : r') x -> Sem r' x)
-> HList t -> Sem (TypeConcat (TypeMap e t) r) a -> Sem r a
runSeveral forall (r' :: [Effect]) k x. k -> Sem (e k : r') x -> Sem r' x
f (a
a ::: HList b
as) = (forall (r' :: [Effect]) k x. k -> Sem (e k : r') x -> Sem r' x)
-> HList b -> Sem (TypeConcat (TypeMap e b) r) a -> Sem r a
forall (e :: * -> Effect) (t :: [*]) (r :: [Effect]) a.
(forall (r' :: [Effect]) k x. k -> Sem (e k : r') x -> Sem r' x)
-> HList t -> Sem (TypeConcat (TypeMap e t) r) a -> Sem r a
runSeveral forall (r' :: [Effect]) k x. k -> Sem (e k : r') x -> Sem r' x
f HList b
as (Sem (TypeConcat (TypeMap e b) r) a -> Sem r a)
-> (Sem (e a : TypeConcat (TypeMap e b) r) a
-> Sem (TypeConcat (TypeMap e b) r) a)
-> Sem (e a : TypeConcat (TypeMap e b) r) a
-> Sem r a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a
-> Sem (e a : TypeConcat (TypeMap e b) r) a
-> Sem (TypeConcat (TypeMap e b) r) a
forall (r' :: [Effect]) k x. k -> Sem (e k : r') x -> Sem r' x
f a
a
runSeveral forall (r' :: [Effect]) k x. k -> Sem (e k : r') x -> Sem r' x
_ HList t
HNil = Sem (TypeConcat (TypeMap e t) r) a -> Sem r a
forall a. a -> a
id