-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A basic framework for effect systems based on effects represented by GADTs. -- -- This library provides core definitions of data-effects. @package data-effects-core @version 0.2.0.0 -- | This module re-exports the HFunctor type class and related -- definitions from the compdata package. For more details, -- please refer to the compdata documentation. module Data.Effect.HFunctor -- | This class represents higher-order functors (Johann, Ghani, POPL '08) -- which are endofunctors on the category of endofunctors. class HFunctor (h :: Type -> Type -> Type -> Type) -- | A higher-order functor f also maps a natural transformation -- g :-> h to a natural transformation f g :-> f -- h hfmap :: forall (f :: Type -> Type) (g :: Type -> Type). HFunctor h => (f :-> g) -> h f :-> h g class RemA (s :: Type -> Type -> Type -> Type) (s' :: Type -> Type -> Type -> Type) | s -> s' remA :: forall (a :: Type -> Type). RemA s s' => s a :-> s' a -- | This class defines how to distribute an annotation over a sum of -- signatures. class DistAnn (s :: Type -> Type -> Type -> Type) p (s' :: Type -> Type -> Type -> Type) | s' -> s, s' -> p -- | This function injects an annotation over a signature. injectA :: forall (a :: Type -> Type). DistAnn s p s' => p -> s a :-> s' a projectA :: forall (a :: Type -> Type). DistAnn s p s' => s' a :-> (s a :&: p) -- | This data type adds a constant product to a signature. Alternatively, -- this could have also been defined as -- --
-- data (f :&: a) (g :: Type -> Type) e = f g e :&: a e ---- -- This is too general, however, for example for productHHom. data ( (f :: Type -> Type -> k -> Type) :&: a ) (g :: Type -> Type) (e :: k) (:&:) :: f g e -> a -> (:&:) (f :: (Type -> Type) -> k -> Type) a (g :: Type -> Type) (e :: k) infixr 7 :&: infixr 7 :&: type (f :: Type -> Type -> Type -> Type) :=: (g :: Type -> Type -> Type -> Type) = (f :<: g, g :<: f) infixl 5 :=: -- | A constraint f :<: g expresses that the signature -- f is subsumed by g, i.e. f can be used to -- construct elements in g. type (f :: Type -> Type -> Type -> Type) :<: (g :: Type -> Type -> Type -> Type) = Subsume ComprEmb Elem f g f g infixl 5 :<: class Subsume (e :: Emb) (f :: Type -> Type -> Type -> Type) (g :: Type -> Type -> Type -> Type) inj' :: forall (a :: Type -> Type). Subsume e f g => Proxy e -> f a :-> g a prj' :: forall (a :: Type -> Type). Subsume e f g => Proxy e -> NatM Maybe (g a) (f a) type family Elem (f :: Type -> Type -> Type -> Type) (g :: Type -> Type -> Type -> Type) :: Emb -- | Data type defining coproducts. data ( (f :: Type -> Type -> k -> Type) :+: (g :: Type -> Type -> k -> Type) ) (h :: Type -> Type) (e :: k) Inl :: f h e -> (:+:) (f :: (Type -> Type) -> k -> Type) (g :: (Type -> Type) -> k -> Type) (h :: Type -> Type) (e :: k) Inr :: g h e -> (:+:) (f :: (Type -> Type) -> k -> Type) (g :: (Type -> Type) -> k -> Type) (h :: Type -> Type) (e :: k) infixr 6 :+: -- | Utility function to case on a higher-order functor sum, without -- exposing the internal representation of sums. caseH :: forall {k} f (a :: Type -> Type) (b :: k) c g. (f a b -> c) -> (g a b -> c) -> (f :+: g) a b -> c inj :: forall (f :: (Type -> Type) -> Type -> Type) (g :: (Type -> Type) -> Type -> Type) (a :: Type -> Type). f :<: g => f a :-> g a proj :: forall (f :: (Type -> Type) -> Type -> Type) (g :: (Type -> Type) -> Type -> Type) (a :: Type -> Type). f :<: g => NatM Maybe (g a) (f a) spl :: forall (f :: (Type -> Type) -> Type -> Type) (f1 :: (Type -> Type) -> Type -> Type) (f2 :: (Type -> Type) -> Type -> Type) (a :: Type -> Type) (b :: Type -> Type). f :=: (f1 :+: f2) => (f1 a :-> b) -> (f2 a :-> b) -> f a :-> b module Data.Effect -- | The kind of first-order effects. type EffectF = Type -> Type -- | The kind of higher-order effects. type EffectH = Type -> Type -> Type -> Type -- | Lift first-order effects to higher-order effects. -- -- Come from heft-lang/POPL2023/haskell/src/Elab.hs. newtype LiftFOE (ins :: EffectF) (f :: Type -> Type) a LiftFOE :: ins a -> LiftFOE (ins :: EffectF) (f :: Type -> Type) a [unliftFOE] :: LiftFOE (ins :: EffectF) (f :: Type -> Type) a -> ins a -- | A first-order effect with no operations. data Nop a -- | A higher-order effect with no operations. type LNop = LiftFOE Nop instance Data.Foldable.Foldable ins => Data.Foldable.Foldable (Data.Effect.LiftFOE ins f) instance GHC.Base.Functor ins => GHC.Base.Functor (Data.Effect.LiftFOE ins f) instance Data.Comp.Multi.HFunctor.HFunctor (Data.Effect.LiftFOE ins) instance Data.Traversable.Traversable ins => Data.Traversable.Traversable (Data.Effect.LiftFOE ins f) module Control.Effect -- | A type class that represents the ability to send an first-order effect -- ins to carrier f. class SendFOE (ins :: EffectF) (f :: Type -> Type) -- | Send an instruction ins to carrier f. sendFOE :: SendFOE ins f => ins a -> f a -- | The operator version of SendFOE. type (<:) = SendFOE infix 2 <: -- | A type class that represents the ability to send a higher-order effect -- sig to carrier f. class SendHOE (sig :: EffectH) (f :: Type -> Type) -- | Send a higher-order effect sig to carrier f. sendHOE :: SendHOE sig f => sig f a -> f a -- | The operator version of SendHOE. type (<<:) = SendHOE infix 2 <<: -- | A natural transformation. type (f :: Type -> Type) ~> (g :: Type -> Type) = forall x. () => f x -> g x infixr 2 ~> instance Control.Effect.SendFOE ins f => Control.Effect.SendHOE (Data.Effect.LiftFOE ins) f module Control.Effect.Key class SendFOEBy (key :: k) (ins :: EffectF) (f :: Type -> Type) | key f -> ins sendFOEBy :: SendFOEBy key ins f => ins a -> f a class SendHOEBy (key :: k) (sig :: EffectH) (f :: Type -> Type) | key f -> sig sendHOEBy :: SendHOEBy key sig f => sig f a -> f a -- | A wrapper data type to represent sending an effect to the carrier -- f with the specified key. newtype ByKey (key :: k) (f :: Type -> Type) a ByKey :: f a -> ByKey (key :: k) (f :: Type -> Type) a [runByKey] :: ByKey (key :: k) (f :: Type -> Type) a -> f a -- | Send all effects within the scope, keyed, to carrier f. key :: forall {k} (key :: k) f a. ByKey key f a -> f a instance forall k (key :: k) (f :: * -> *). GHC.Base.Alternative f => GHC.Base.Alternative (Control.Effect.Key.ByKey key f) instance forall k (key :: k) (f :: * -> *). GHC.Base.Applicative f => GHC.Base.Applicative (Control.Effect.Key.ByKey key f) instance forall k (key :: k) (f :: * -> *). GHC.Base.Functor f => GHC.Base.Functor (Control.Effect.Key.ByKey key f) instance forall k (key :: k) (f :: * -> *). GHC.Base.Monad f => GHC.Base.Monad (Control.Effect.Key.ByKey key f) instance forall e k (key :: k) (f :: * -> *). Control.Monad.Error.Class.MonadError e f => Control.Monad.Error.Class.MonadError e (Control.Effect.Key.ByKey key f) instance forall k (key :: k) (f :: * -> *). Control.Monad.Fail.MonadFail f => Control.Monad.Fail.MonadFail (Control.Effect.Key.ByKey key f) instance forall k (key :: k) (f :: * -> *). Control.Monad.Fix.MonadFix f => Control.Monad.Fix.MonadFix (Control.Effect.Key.ByKey key f) instance forall k (key :: k) (f :: * -> *). Control.Monad.IO.Class.MonadIO f => Control.Monad.IO.Class.MonadIO (Control.Effect.Key.ByKey key f) instance forall k (key :: k) (f :: * -> *). GHC.Base.MonadPlus f => GHC.Base.MonadPlus (Control.Effect.Key.ByKey key f) instance forall r w s k (key :: k) (f :: * -> *). (Control.Monad.Reader.Class.MonadReader r f, Control.Monad.Writer.Class.MonadWriter w f, Control.Monad.State.Class.MonadState s f) => Control.Monad.RWS.Class.MonadRWS r w s (Control.Effect.Key.ByKey key f) instance forall r k (key :: k) (f :: * -> *). Control.Monad.Reader.Class.MonadReader r f => Control.Monad.Reader.Class.MonadReader r (Control.Effect.Key.ByKey key f) instance forall s k (key :: k) (f :: * -> *). Control.Monad.State.Class.MonadState s f => Control.Monad.State.Class.MonadState s (Control.Effect.Key.ByKey key f) instance forall w k (key :: k) (f :: * -> *). Control.Monad.Writer.Class.MonadWriter w f => Control.Monad.Writer.Class.MonadWriter w (Control.Effect.Key.ByKey key f) instance forall k (key :: k) (ins :: Data.Effect.EffectF) (f :: * -> *). Control.Effect.Key.SendFOEBy key ins f => Control.Effect.SendFOE ins (Control.Effect.Key.ByKey key f) instance forall k (key :: k) (sig :: Data.Effect.EffectH) (f :: * -> *). (Control.Effect.Key.SendHOEBy key sig f, Data.Comp.Multi.HFunctor.HFunctor sig) => Control.Effect.SendHOE sig (Control.Effect.Key.ByKey key f) module Data.Effect.HFunctor.HCont -- | This represents that the effect ff is finally interpreted as -- the base carrier b. newtype HCont (ff :: Type -> Type -> Type -> Type) (b :: Type -> Type) (f :: Type -> Type) a HCont :: ((f ~> b) -> ff b a) -> HCont (ff :: (Type -> Type) -> Type -> Type) (b :: Type -> Type) (f :: Type -> Type) a [unHCont] :: HCont (ff :: (Type -> Type) -> Type -> Type) (b :: Type -> Type) (f :: Type -> Type) a -> (f ~> b) -> ff b a instance GHC.Base.Functor (ff b) => GHC.Base.Functor (Data.Effect.HFunctor.HCont.HCont ff b f) instance Data.Comp.Multi.HFunctor.HFunctor (Data.Effect.HFunctor.HCont.HCont ff g) module Data.Effect.Key -- | Keyed first-order effect. newtype Key (key :: k) (ins :: EffectF) a Key :: ins a -> Key (key :: k) (ins :: EffectF) a [unKey] :: Key (key :: k) (ins :: EffectF) a -> ins a -- | Keyed first-order effect. type (#>) = Key :: k -> EffectF -> Type -> Type infixr 7 #> -- | Keyed first-order effect. pattern K :: forall {k} key ins a. ins a -> Key key ins a -- | Keyed higher-order effect. newtype KeyH (key :: k) (sig :: EffectH) (f :: Type -> Type) a KeyH :: sig f a -> KeyH (key :: k) (sig :: EffectH) (f :: Type -> Type) a [unKeyH] :: KeyH (key :: k) (sig :: EffectH) (f :: Type -> Type) a -> sig f a -- | Keyed higher-order effect. type (##>) = KeyH :: k -> EffectH -> Type -> Type -> Type -> Type infixr 7 ##> -- | Keyed higher-order effect. pattern KH :: forall {k} key sig f a. sig f a -> KeyH key sig f a instance forall k (key :: k) (ins :: Data.Effect.EffectF). Data.Foldable.Foldable ins => Data.Foldable.Foldable (Data.Effect.Key.Key key ins) instance forall k (key :: k) (sig :: Data.Effect.EffectH) (f :: * -> *). Data.Foldable.Foldable (sig f) => Data.Foldable.Foldable (Data.Effect.Key.KeyH key sig f) instance forall k (key :: k) (ins :: Data.Effect.EffectF). GHC.Base.Functor ins => GHC.Base.Functor (Data.Effect.Key.Key key ins) instance forall k (key :: k) (sig :: Data.Effect.EffectH) (f :: * -> *). GHC.Base.Functor (sig f) => GHC.Base.Functor (Data.Effect.Key.KeyH key sig f) instance forall k (key :: k) (sig :: Data.Effect.EffectH). Data.Comp.Multi.HFunctor.HFunctor sig => Data.Comp.Multi.HFunctor.HFunctor (Data.Effect.Key.KeyH key sig) instance forall k (key :: k) (ins :: Data.Effect.EffectF). Data.Traversable.Traversable ins => Data.Traversable.Traversable (Data.Effect.Key.Key key ins) instance forall k (key :: k) (sig :: Data.Effect.EffectH) (f :: * -> *). Data.Traversable.Traversable (sig f) => Data.Traversable.Traversable (Data.Effect.Key.KeyH key sig f) module Data.Effect.Tag -- | Tagged first-order effect. newtype Tag (ins :: EffectF) (tag :: k) a Tag :: ins a -> Tag (ins :: EffectF) (tag :: k) a [unTag] :: Tag (ins :: EffectF) (tag :: k) a -> ins a -- | Tagged first-order effect. type (#) = Tag :: EffectF -> k -> Type -> Type infixl 8 # -- | Tagged first-order effect. pattern T :: forall {k} tag ins a. ins a -> Tag ins tag a -- | Tagged higher-order effect. newtype TagH (sig :: EffectH) (tag :: k) (f :: Type -> Type) a TagH :: sig f a -> TagH (sig :: EffectH) (tag :: k) (f :: Type -> Type) a [unTagH] :: TagH (sig :: EffectH) (tag :: k) (f :: Type -> Type) a -> sig f a -- | Tagged higher-order effect. type (##) = TagH :: EffectH -> k -> Type -> Type -> Type -> Type infixl 8 ## -- | Tagged higher-order effect. pattern TH :: forall {k} tag sig f a. sig f a -> TagH sig tag f a instance forall (ins :: Data.Effect.EffectF) k (tag :: k). Data.Foldable.Foldable ins => Data.Foldable.Foldable (Data.Effect.Tag.Tag ins tag) instance forall (sig :: Data.Effect.EffectH) k (tag :: k) (f :: * -> *). Data.Foldable.Foldable (sig f) => Data.Foldable.Foldable (Data.Effect.Tag.TagH sig tag f) instance forall (ins :: Data.Effect.EffectF) k (tag :: k). GHC.Base.Functor ins => GHC.Base.Functor (Data.Effect.Tag.Tag ins tag) instance forall (sig :: Data.Effect.EffectH) k (tag :: k) (f :: * -> *). GHC.Base.Functor (sig f) => GHC.Base.Functor (Data.Effect.Tag.TagH sig tag f) instance forall (sig :: Data.Effect.EffectH) k (tag :: k). Data.Comp.Multi.HFunctor.HFunctor sig => Data.Comp.Multi.HFunctor.HFunctor (Data.Effect.Tag.TagH sig tag) instance forall (ins :: Data.Effect.EffectF) k (tag :: k). Data.Traversable.Traversable ins => Data.Traversable.Traversable (Data.Effect.Tag.Tag ins tag) instance forall (sig :: Data.Effect.EffectH) k (tag :: k) (f :: * -> *). Data.Traversable.Traversable (sig f) => Data.Traversable.Traversable (Data.Effect.Tag.TagH sig tag f) module Control.Effect.Tag -- | A wrapper data type to represent sending an effect to the carrier -- f with the specified tag. newtype ViaTag (tag :: k) (f :: Type -> Type) a ViaTag :: f a -> ViaTag (tag :: k) (f :: Type -> Type) a [runViaTag] :: ViaTag (tag :: k) (f :: Type -> Type) a -> f a -- | Send all effects within the scope, tagged, to carrier f. tag :: forall {k} (tag :: k) f a. ViaTag tag f a -> f a instance forall k (tag :: k) (f :: * -> *). GHC.Base.Alternative f => GHC.Base.Alternative (Control.Effect.Tag.ViaTag tag f) instance forall k (tag :: k) (f :: * -> *). GHC.Base.Applicative f => GHC.Base.Applicative (Control.Effect.Tag.ViaTag tag f) instance forall k (tag :: k) (f :: * -> *). GHC.Base.Functor f => GHC.Base.Functor (Control.Effect.Tag.ViaTag tag f) instance forall e k (tag :: k) (f :: * -> *). Control.Monad.Error.Class.MonadError e f => Control.Monad.Error.Class.MonadError e (Control.Effect.Tag.ViaTag tag f) instance forall k (tag :: k) (f :: * -> *). Control.Monad.Fail.MonadFail f => Control.Monad.Fail.MonadFail (Control.Effect.Tag.ViaTag tag f) instance forall k (tag :: k) (f :: * -> *). Control.Monad.Fix.MonadFix f => Control.Monad.Fix.MonadFix (Control.Effect.Tag.ViaTag tag f) instance forall k (tag :: k) (f :: * -> *). Control.Monad.IO.Class.MonadIO f => Control.Monad.IO.Class.MonadIO (Control.Effect.Tag.ViaTag tag f) instance forall k (tag :: k) (f :: * -> *). GHC.Base.MonadPlus f => GHC.Base.MonadPlus (Control.Effect.Tag.ViaTag tag f) instance forall r w s k (tag :: k) (f :: * -> *). (Control.Monad.Reader.Class.MonadReader r f, Control.Monad.Writer.Class.MonadWriter w f, Control.Monad.State.Class.MonadState s f) => Control.Monad.RWS.Class.MonadRWS r w s (Control.Effect.Tag.ViaTag tag f) instance forall r k (tag :: k) (f :: * -> *). Control.Monad.Reader.Class.MonadReader r f => Control.Monad.Reader.Class.MonadReader r (Control.Effect.Tag.ViaTag tag f) instance forall s k (tag :: k) (f :: * -> *). Control.Monad.State.Class.MonadState s f => Control.Monad.State.Class.MonadState s (Control.Effect.Tag.ViaTag tag f) instance forall k (tag :: k) (f :: * -> *). GHC.Base.Monad f => GHC.Base.Monad (Control.Effect.Tag.ViaTag tag f) instance forall w k (tag :: k) (f :: * -> *). Control.Monad.Writer.Class.MonadWriter w f => Control.Monad.Writer.Class.MonadWriter w (Control.Effect.Tag.ViaTag tag f) instance forall k1 k2 (key :: k1) (ins :: Data.Effect.EffectF) (tag :: k2) (f :: * -> *). Control.Effect.Key.SendFOEBy key (ins Data.Effect.Tag.# tag) f => Control.Effect.Key.SendFOEBy key ins (Control.Effect.Tag.ViaTag tag f) instance forall k (ins :: Data.Effect.EffectF) (tag :: k) (f :: * -> *). Control.Effect.SendFOE (ins Data.Effect.Tag.# tag) f => Control.Effect.SendFOE ins (Control.Effect.Tag.ViaTag tag f) instance forall k1 k2 (key :: k1) (sig :: Data.Effect.EffectH) (tag :: k2) (f :: * -> *). (Control.Effect.Key.SendHOEBy key (sig Data.Effect.Tag.## tag) f, Data.Comp.Multi.HFunctor.HFunctor sig) => Control.Effect.Key.SendHOEBy key sig (Control.Effect.Tag.ViaTag tag f) instance forall k (sig :: Data.Effect.EffectH) (tag :: k) (f :: * -> *). (Control.Effect.SendHOE (sig Data.Effect.Tag.## tag) f, Data.Comp.Multi.HFunctor.HFunctor sig) => Control.Effect.SendHOE sig (Control.Effect.Tag.ViaTag tag f)