Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Effect
Description
The user-facing API of our effect system
Synopsis
- type Effect = (Type -> Type) -> Type -> Type
- class EffectInject (op :: Effect) (ops :: [Effect]) | ops -> op
- type AST ops = Fixpoint Freer (JoinedEffects ops)
- class InterpretEffect m op where
- interpretEffect :: (forall b. AST ops b -> m b) -> op (AST ops) a -> m a
- class InterpretEffects m ops
- interpretAST :: (Monad m, InterpretEffects m ops) => AST ops a -> m a
- class InterpretEffectStateful (t :: Type -> Type) m op where
- interpretEffectStateful :: (forall b y. t y -> AST ops b -> m (b, t y)) -> t x -> op (AST ops) a -> m (a, t x)
- class InterpretEffectsStateful t m ops
- interpretASTStateful :: (Monad m, InterpretEffectsStateful t m ops) => t x -> AST ops a -> m (a, t x)
Effect types
class EffectInject (op :: Effect) (ops :: [Effect]) | ops -> op Source #
Is a given type of effects an element of a list of effect types?
In writing "reification" instances, a useful idiom is something like
instance EffectInject (MonadWriterEffect w) ops => MonadWriter (AST ops)
which will define "writer-like syntax" for all lists of effects that
contain 'WriterEffect w'. This idiom is also the reason for the functional
dependency in the class: ops
must contain enough information to determine
op
.
Users of the library should't write instances of this type, as they're
generated automatically. Also, "reification" instances like the one above
aren't written by hand, usually. Macros like makeEffect
do this.
Minimal complete definition
Instances
EffectInject op (op ': ops) Source # | |
Defined in Effect.Internal Methods effectInject :: forall (m :: Type -> Type) a. op m a -> JoinedEffects (op ': ops) m a Source # | |
EffectInject x ops => EffectInject x (y ': ops) Source # | |
Defined in Effect.Internal Methods effectInject :: forall (m :: Type -> Type) a. x m a -> JoinedEffects (y ': ops) m a Source # |
Abstract syntax trees
type AST ops = Fixpoint Freer (JoinedEffects ops) Source #
An abstract syntax tree which may use Effect
s of types ops
Interpreting abstract syntax trees
class InterpretEffect m op where Source #
Write an instance of this class to define the "standard" interpretation of an effect type into a suitable domain.
If you want to use the function interpretAST
, this class has to be
implemented for all effect types you're using in your AST
. In the normal
case, you won't do this by hand, but generate the instance (and others)
using a macro like makeEffect
.
Compared to logics like Logic.Ltl, this is a low-level class; in the standard applications of these logics, you'll never have to directly interact with this class.
Methods
interpretEffect :: (forall b. AST ops b -> m b) -> op (AST ops) a -> m a Source #
Given a function that describes how to interpret AST
s and an effect,
return the interpretation of the effect.
Instances
class InterpretEffects m ops Source #
The constraint that all effects ops
are interpretable (in the sense of
InterpretEffect
) into m
.
You should never have to manually write an instance of this class, it should always be inferred.
Minimal complete definition
Instances
InterpretEffects m ('[] :: [(Type -> Type) -> Type -> Type]) Source # | |
Defined in Effect.Internal Methods interpretEffects :: ConstraintList (InterpretEffect m) '[] Source # | |
(InterpretEffect m op, InterpretEffects m ops) => InterpretEffects m (op ': ops) Source # | |
Defined in Effect.Internal Methods interpretEffects :: ConstraintList (InterpretEffect m) (op ': ops) Source # |
interpretAST :: (Monad m, InterpretEffects m ops) => AST ops a -> m a Source #
If all effect types in ops
have an InterpretEffect m
instance, this
function will interpret the AST
into m
.
Interpreting abstract syntax trees, statefully
class InterpretEffectStateful (t :: Type -> Type) m op where Source #
Write an instance of this class to define the "statefully modified"
interpretation of an effect type into a suitable domain. The intuition is
that you interpret effects of type ops
into the domain m
, while also
passing a state of type t x
from step to step. This state will control how
effects are actually implemented in m
.
If you want to use the function interpretASTStateful
, this class has to be
implemented for all effect types in the AST
you're using.
Compared to logics like Logic.Ltl, this is a low-level class; in the standard applications of these logics, you'll never have to directly interact with this class.
Methods
interpretEffectStateful :: (forall b y. t y -> AST ops b -> m (b, t y)) -> t x -> op (AST ops) a -> m (a, t x) Source #
Given a function that describes how to interpret AST
s statefully, a
current "interpretation state", and an effect, return the stateful
interpretation of the effect.
Instances
MonadFail m => InterpretEffectStateful x m MonadFailEffect Source # | A "passthough" instance for |
Defined in Effect.Fail.Passthrough Methods interpretEffectStateful :: forall (ops :: [Effect]) x0 a. (forall b y. x y -> AST ops b -> m (b, x y)) -> x x0 -> MonadFailEffect (AST ops) a -> m (a, x x0) Source # | |
MonadIO m => InterpretEffectStateful x m MonadIOEffect Source # | A "passthough" instance for |
Defined in Effect.IO.Passthrough Methods interpretEffectStateful :: forall (ops :: [Effect]) x0 a. (forall b y. x y -> AST ops b -> m (b, x y)) -> x x0 -> MonadIOEffect (AST ops) a -> m (a, x x0) Source # | |
MonadError e m => InterpretEffectStateful x m (MonadErrorEffect e) Source # | A "passthough" instance for |
Defined in Effect.Error.Passthrough Methods interpretEffectStateful :: forall (ops :: [Effect]) x0 a. (forall b y. x y -> AST ops b -> m (b, x y)) -> x x0 -> MonadErrorEffect e (AST ops) a -> m (a, x x0) Source # | |
MonadWriter e m => InterpretEffectStateful x m (MonadWriterEffect e) Source # | A "passthough" instance for |
Defined in Effect.Writer.Passthrough Methods interpretEffectStateful :: forall (ops :: [Effect]) x0 a. (forall b y. x y -> AST ops b -> m (b, x y)) -> x x0 -> MonadWriterEffect e (AST ops) a -> m (a, x x0) Source # | |
(MonadPlus m, InterpretEffect m op, InterpretNextBind t m op) => InterpretEffectStateful (NextBind t) m op Source # | |
class InterpretEffectsStateful t m ops Source #
The constraint that all effects ops
are statefully interpretable with a
state of type t
into m
(in the sense of InterpretEffectStateful
).
You should never have to manually write an instance of this class, it should always be inferred.
Minimal complete definition
Instances
InterpretEffectsStateful t m ('[] :: [(Type -> Type) -> Type -> Type]) Source # | |
Defined in Effect.Internal Methods interpretEffectsStateful :: ConstraintList (InterpretEffectStateful t m) '[] Source # | |
(InterpretEffectStateful t m op, InterpretEffectsStateful t m ops) => InterpretEffectsStateful t m (op ': ops) Source # | |
Defined in Effect.Internal Methods interpretEffectsStateful :: ConstraintList (InterpretEffectStateful t m) (op ': ops) Source # |
interpretASTStateful :: (Monad m, InterpretEffectsStateful t m ops) => t x -> AST ops a -> m (a, t x) Source #
If all effect types in ops
have an InterpretEffectStateful t m
instance, this function will interpret the AST
, starting at a given
initial "interpretation state" of type t x
for some x
.