{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_HADDOCK not-home #-}
module Effectful.Internal.Effect
( Effect
, (:>)(..)
, (:>>)
, Subset(..)
, Type
) where
import Data.Kind
import GHC.TypeLits
type Effect = (Type -> Type) -> Type -> Type
class (e :: Effect) :> (es :: [Effect]) where
reifyIndex :: Int
reifyIndex =
[Char] -> Int
forall a. HasCallStack => [Char] -> a
error [Char]
"unimplemented"
instance TypeError
( Text "There is no handler for '" :<>: ShowType e :<>: Text "' in the context"
) => e :> '[] where
reifyIndex :: Int
reifyIndex = [Char] -> Int
forall a. HasCallStack => [Char] -> a
error [Char]
"unreachable"
instance {-# OVERLAPPING #-} e :> (e : es) where
reifyIndex :: Int
reifyIndex = Int
0
instance e :> es => e :> (x : es) where
reifyIndex :: Int
reifyIndex = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ forall (e :: Effect) (es :: [Effect]). (e :> es) => Int
reifyIndex @e @es
type family xs :>> es :: Constraint where
'[] :>> es = ()
(x : xs) :>> es = (x :> es, xs :>> es)
class Subset (xs :: [Effect]) (es :: [Effect]) where
reifyIndices :: [Int]
reifyIndices =
[Char] -> [Int]
forall a. HasCallStack => [Char] -> a
error [Char]
"unimplemented"
instance Subset '[] es where
reifyIndices :: [Int]
reifyIndices = []
instance (e :> es, Subset xs es) => Subset (e : xs) es where
reifyIndices :: [Int]
reifyIndices = forall (e :: Effect) (es :: [Effect]). (e :> es) => Int
reifyIndex @e @es Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
: forall (xs :: [Effect]) (es :: [Effect]). Subset xs es => [Int]
reifyIndices @xs @es