{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Polysemy.Several
( HList (..),
TypeMap,
Append,
runSeveral,
)
where
import Data.Kind (Type)
import Polysemy (Sem)
infixr 5 :::
type HList :: [Type] -> Type
data HList a where
HNil :: HList '[]
(:::) :: a -> HList (b :: [Type]) -> HList (a ': b)
type TypeMap :: (a -> b) -> [a] -> [b]
type family TypeMap (f :: a -> b) (xs :: [a]) where
TypeMap _ '[] = '[]
TypeMap f (x ': xs) = f x ': TypeMap f xs
type Append :: [t] -> [t] -> [t]
type family Append (a :: [t]) (b :: [t]) where
Append '[] b = b
Append (a ': as) b = a ': Append as b
runSeveral ::
(forall r' k x. k -> Sem (e k ': r') x -> Sem r' x) ->
HList t ->
Sem (Append (TypeMap e t) r) a ->
Sem r a
runSeveral :: forall (e :: * -> Effect) (t :: [*]) (r :: [Effect]) a.
(forall (r' :: [Effect]) k x. k -> Sem (e k : r') x -> Sem r' x)
-> HList t -> Sem (Append (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 (e :: * -> Effect) (t :: [*]) (r :: [Effect]) a.
(forall (r' :: [Effect]) k x. k -> Sem (e k : r') x -> Sem r' x)
-> HList t -> Sem (Append (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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall a. a -> a
id