{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_HADDOCK not-home #-}
module Effectful.Internal.Effect
( Effect
, (:>)(..)
, (:>>)
, Subset(..)
, KnownSubset
, KnownPrefix(..)
, IsUnknownSuffixOf
, type (++)
, KnownEffects(..)
, 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]
"reifyIndex"
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)
{-# DEPRECATED (:>>) "Usage of (:>>) slows down GHC too much. See https://github.com/haskell-effectful/effectful/issues/52#issuecomment-1269155485 for more information." #-}
class KnownPrefix es => Subset (subEs :: [Effect]) (es :: [Effect]) where
subsetFullyKnown :: Bool
subsetFullyKnown =
[Char] -> Bool
forall a. HasCallStack => [Char] -> a
error [Char]
"subsetFullyKnown"
reifyIndices :: [Int]
reifyIndices =
[Char] -> [Int]
forall a. HasCallStack => [Char] -> a
error [Char]
"reifyIndices"
instance {-# INCOHERENT #-}
( KnownPrefix es
, subEs `IsUnknownSuffixOf` es
) => Subset subEs es where
subsetFullyKnown :: Bool
subsetFullyKnown = Bool
False
reifyIndices :: [Int]
reifyIndices = []
instance KnownPrefix es => Subset '[] es where
subsetFullyKnown :: Bool
subsetFullyKnown = Bool
True
reifyIndices :: [Int]
reifyIndices = []
instance (e :> es, Subset subEs es) => Subset (e : subEs) es where
subsetFullyKnown :: Bool
subsetFullyKnown = forall (subEs :: [Effect]) (es :: [Effect]).
Subset subEs es =>
Bool
subsetFullyKnown @subEs @es
reifyIndices :: [Int]
reifyIndices = forall (e :: Effect) (es :: [Effect]). (e :> es) => Int
reifyIndex @e @es Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
: forall (subEs :: [Effect]) (es :: [Effect]).
Subset subEs es =>
[Int]
reifyIndices @subEs @es
class Subset subEs es => KnownSubset (subEs :: [Effect]) (es :: [Effect])
instance KnownSubset '[] es
instance (e :> es, KnownSubset subEs es) => KnownSubset (e : subEs) es
class KnownPrefix (es :: [Effect]) where
prefixLength :: Int
instance KnownPrefix es => KnownPrefix (e : es) where
prefixLength :: Int
prefixLength = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ forall (es :: [Effect]). KnownPrefix es => Int
prefixLength @es
instance {-# INCOHERENT #-} KnownPrefix es where
prefixLength :: Int
prefixLength = Int
0
class (subEs :: [Effect]) `IsUnknownSuffixOf` (es :: [Effect])
instance {-# INCOHERENT #-} subEs ~ es => subEs `IsUnknownSuffixOf` es
instance subEs `IsUnknownSuffixOf` es => subEs `IsUnknownSuffixOf` (e : es)
type family (xs :: [Effect]) ++ (ys :: [Effect]) :: [Effect] where
'[] ++ ys = ys
(x : xs) ++ ys = x : xs ++ ys
infixr 5 ++
class KnownEffects (es :: [Effect]) where
knownEffectsLength :: Int
knownEffectsLength =
[Char] -> Int
forall a. HasCallStack => [Char] -> a
error [Char]
"knownEffectsLength"
instance KnownEffects es => KnownEffects (e : es) where
knownEffectsLength :: Int
knownEffectsLength = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ forall (es :: [Effect]). KnownEffects es => Int
knownEffectsLength @es
instance KnownEffects '[] where
knownEffectsLength :: Int
knownEffectsLength = Int
0