on fbc5b30 help sign in
35 lines 1.1 kB history raw
1{-# LANGUAGE AllowAmbiguousTypes #-}
2{-# LANGUAGE UndecidableInstances #-}
3{-# OPTIONS_HADDOCK not-home #-}
4-- | Type-safe indexing for 'Effectful.Internal.Monad.Env'.
5--
6-- This module is intended for internal use only, and may change without warning
7-- in subsequent releases.
8module Effectful.Internal.Effect
9 ( Effect
10 , (:>)(..)
11 , IdE(..)
12 ) where
14import Data.Kind
16type Effect = (Type -> Type) -> Type -> Type
18-- | Adapter for statically dispatched effects.
19newtype IdE (e :: Effect) where
20 IdE :: (forall m r. e m r) -> IdE e
22class (e :: Effect) :> (es :: [Effect]) where
23 -- | Get the position of @e@ in @es@.
24 --
25 -- /Note:/ GHC is kind enough to cache these values as they're top level CAFs,
26 -- so the lookup is amortized @O(1)@ without any language level tricks.
27 reifyIndex :: Int
28 reifyIndex = -- Don't show "minimal complete definition" in haddock.
29 error "unimplemented"
31instance {-# OVERLAPPING #-} e :> (e : es) where
32 reifyIndex = 0
34instance e :> es => e :> (x : es) where
35 reifyIndex = 1 + reifyIndex @e @es