Safe Haskell | None |
---|---|
Language | Haskell2010 |
Control.Carrier.Interpret
Contents
Description
Provides an InterpretC
carrier capable of interpreting an arbitrary effect using a passed-in higher order function to interpret that effect. This is suitable for prototyping new effects quickly.
Synopsis
- runInterpret :: (forall ctx n x. Functor ctx => Handler ctx n m -> eff n x -> ctx () -> m (ctx x)) -> (forall s. Reifies s (Interpreter eff m) => InterpretC s eff m a) -> m a
- runInterpretState :: (forall ctx n x. Functor ctx => Handler ctx n (StateC s m) -> eff n x -> s -> ctx () -> m (s, ctx x)) -> s -> (forall t. Reifies t (Interpreter eff (StateC s m)) => InterpretC t eff (StateC s m) a) -> m (s, a)
- newtype InterpretC s (sig :: (Type -> Type) -> Type -> Type) m a = InterpretC (m a)
- class Reifies s a | s -> a
- data Interpreter sig m
- class Monad m => Algebra sig m | m -> sig
- type Has eff sig m = (Members eff sig, Algebra sig m)
- run :: Identity a -> a
Interpret carrier
runInterpret :: (forall ctx n x. Functor ctx => Handler ctx n m -> eff n x -> ctx () -> m (ctx x)) -> (forall s. Reifies s (Interpreter eff m) => InterpretC s eff m a) -> m a Source #
Interpret an effect using a higher-order function.
Note that due to the higher-rank type, you have to use either $
or explicit application when applying this interpreter. That is, you will need to write runInterpret f (runInterpret g myPrgram)
or runInterpret f $ runInterpret g $ myProgram
. If you try and write runInterpret f . runInterpret g
, you will unfortunately get a rather scary type error!
Since: 1.0.0.0
runInterpretState :: (forall ctx n x. Functor ctx => Handler ctx n (StateC s m) -> eff n x -> s -> ctx () -> m (s, ctx x)) -> s -> (forall t. Reifies t (Interpreter eff (StateC s m)) => InterpretC t eff (StateC s m) a) -> m (s, a) Source #
Interpret an effect using a higher-order function with some state variable.
Since: 1.0.0.0
newtype InterpretC s (sig :: (Type -> Type) -> Type -> Type) m a Source #
Since: 1.0.0.0
Constructors
InterpretC (m a) |
Instances
MonadTrans (InterpretC s sig) Source # | |
Defined in Control.Carrier.Interpret Methods lift :: Monad m => m a -> InterpretC s sig m a # | |
(Reifies s (Interpreter eff m), Algebra sig m) => Algebra (eff :+: sig) (InterpretC s eff m) Source # | |
Defined in Control.Carrier.Interpret Methods alg :: Functor ctx => Handler ctx n (InterpretC s eff m) -> (eff :+: sig) n a -> ctx () -> InterpretC s eff m (ctx a) Source # | |
Monad m => Monad (InterpretC s sig m) Source # | |
Defined in Control.Carrier.Interpret Methods (>>=) :: InterpretC s sig m a -> (a -> InterpretC s sig m b) -> InterpretC s sig m b # (>>) :: InterpretC s sig m a -> InterpretC s sig m b -> InterpretC s sig m b # return :: a -> InterpretC s sig m a # fail :: String -> InterpretC s sig m a # | |
Functor m => Functor (InterpretC s sig m) Source # | |
Defined in Control.Carrier.Interpret Methods fmap :: (a -> b) -> InterpretC s sig m a -> InterpretC s sig m b # (<$) :: a -> InterpretC s sig m b -> InterpretC s sig m a # | |
MonadFix m => MonadFix (InterpretC s sig m) Source # | |
Defined in Control.Carrier.Interpret Methods mfix :: (a -> InterpretC s sig m a) -> InterpretC s sig m a # | |
MonadFail m => MonadFail (InterpretC s sig m) Source # | |
Defined in Control.Carrier.Interpret Methods fail :: String -> InterpretC s sig m a # | |
Applicative m => Applicative (InterpretC s sig m) Source # | |
Defined in Control.Carrier.Interpret Methods pure :: a -> InterpretC s sig m a # (<*>) :: InterpretC s sig m (a -> b) -> InterpretC s sig m a -> InterpretC s sig m b # liftA2 :: (a -> b -> c) -> InterpretC s sig m a -> InterpretC s sig m b -> InterpretC s sig m c # (*>) :: InterpretC s sig m a -> InterpretC s sig m b -> InterpretC s sig m b # (<*) :: InterpretC s sig m a -> InterpretC s sig m b -> InterpretC s sig m a # | |
MonadIO m => MonadIO (InterpretC s sig m) Source # | |
Defined in Control.Carrier.Interpret Methods liftIO :: IO a -> InterpretC s sig m a # | |
Alternative m => Alternative (InterpretC s sig m) Source # | |
Defined in Control.Carrier.Interpret Methods empty :: InterpretC s sig m a # (<|>) :: InterpretC s sig m a -> InterpretC s sig m a -> InterpretC s sig m a # some :: InterpretC s sig m a -> InterpretC s sig m [a] # many :: InterpretC s sig m a -> InterpretC s sig m [a] # | |
MonadPlus m => MonadPlus (InterpretC s sig m) Source # | |
Defined in Control.Carrier.Interpret Methods mzero :: InterpretC s sig m a # mplus :: InterpretC s sig m a -> InterpretC s sig m a -> InterpretC s sig m a # |
data Interpreter sig m Source #
An Interpreter
is a function that interprets effects described by sig
into the carrier monad m
.
Re-exports
class Monad m => Algebra sig m | m -> sig Source #
The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the alg
method.
Since: 1.0.0.0
Minimal complete definition
Instances
Algebra Choose NonEmpty Source # | |
Algebra Empty Maybe Source # | |
Algebra NonDet [] Source # | |
Algebra sig m => Algebra sig (Alt m) Source # | This instance permits effectful actions to be lifted into the a <|> b <|> c <|> d is equivalent to getAlt (mconcat [a, b, c, d]) Since: 1.0.1.0 |
Algebra sig m => Algebra sig (Ap m) Source # | This instance permits effectful actions to be lifted into the mappend <$> act1 <*> (mappend <$> act2 <*> act3) is equivalent to getAp (act1 <> act2 <> act3) Since: 1.0.1.0 |
Algebra sig m => Algebra sig (IdentityT m) Source # | |
Algebra (Lift IO) IO Source # | |
Algebra (Lift Identity) Identity Source # | |
Monad m => Algebra (Lift m) (LiftC m) Source # | |
Algebra (Error e) (Either e) Source # | |
Monoid w => Algebra (Writer w) ((,) w) Source # | |
Algebra (Reader r) ((->) r :: Type -> Type) Source # | |
Algebra sig m => Algebra (Choose :+: sig) (ChooseC m) Source # | |
Algebra sig m => Algebra (Empty :+: sig) (MaybeT m) Source # | |
Algebra sig m => Algebra (Empty :+: sig) (EmptyC m) Source # | |
Algebra sig m => Algebra (Empty :+: sig) (EmptyC m) Source # | |
Algebra sig m => Algebra (NonDet :+: sig) (NonDetC m) Source # | |
(MonadIO m, Algebra sig m) => Algebra (Trace :+: sig) (TraceC m) Source # | |
Algebra sig m => Algebra (Trace :+: sig) (TraceC m) Source # | |
Algebra sig m => Algebra (Trace :+: sig) (TraceC m) Source # | |
Algebra sig m => Algebra (Fail :+: sig) (FailC m) Source # | |
Algebra sig m => Algebra (Fresh :+: sig) (FreshC m) Source # | |
Algebra sig m => Algebra (Fresh :+: sig) (FreshC m) Source # | |
Algebra sig m => Algebra (Cut :+: (NonDet :+: sig)) (CutC m) Source # | |
Algebra sig m => Algebra (Cull :+: (NonDet :+: sig)) (CullC m) Source # | |
Algebra sig m => Algebra (Reader r :+: sig) (ReaderC r m) Source # | |
Algebra sig m => Algebra (State s :+: sig) (StateT s m) Source # | |
Algebra sig m => Algebra (State s :+: sig) (StateT s m) Source # | |
Algebra sig m => Algebra (State s :+: sig) (StateC s m) Source # | |
Algebra sig m => Algebra (State s :+: sig) (StateC s m) Source # | |
Algebra sig m => Algebra (State s :+: sig) (StateC s m) Source # | |
Algebra sig m => Algebra (Throw e :+: sig) (ThrowC e m) Source # | |
Algebra sig m => Algebra (Error e :+: sig) (ExceptT e m) Source # | |
Algebra sig m => Algebra (Error e :+: sig) (ErrorC e m) Source # | |
Algebra sig m => Algebra (Error e :+: sig) (ErrorC e m) Source # | |
(Algebra sig m, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Source # | |
(Algebra sig m, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Source # | |
(Monoid w, Algebra sig m) => Algebra (Writer w :+: sig) (WriterC w m) Source # | |
(Algebra sig m, Monoid w) => Algebra (Writer w :+: sig) (WriterC w m) Source # | |
(Reifies s (Interpreter eff m), Algebra sig m) => Algebra (eff :+: sig) (InterpretC s eff m) Source # | |
Defined in Control.Carrier.Interpret Methods alg :: Functor ctx => Handler ctx n (InterpretC s eff m) -> (eff :+: sig) n a -> ctx () -> InterpretC s eff m (ctx a) Source # | |
Algebra sig m => Algebra (Reader r :+: sig) (ReaderT r m) Source # | |
(LabelledMember label sub sig, Algebra sig m) => Algebra (sub :+: sig) (UnderLabel label sub m) Source # | |
Defined in Control.Effect.Labelled Methods alg :: Functor ctx => Handler ctx n (UnderLabel label sub m) -> (sub :+: sig) n a -> ctx () -> UnderLabel label sub m (ctx a) Source # | |
(Algebra sig m, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # | |
(Algebra sig m, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Source # | |
Algebra (eff :+: sig) (sub m) => Algebra (Labelled label eff :+: sig) (Labelled label sub m) Source # | |
type Has eff sig m = (Members eff sig, Algebra sig m) Source #
m
is a carrier for sig
containing eff
.
Note that if eff
is a sum, it will be decomposed into multiple Member
constraints. While this technically allows one to combine multiple unrelated effects into a single Has
constraint, doing so has two significant drawbacks:
- Due to a problem with recursive type families, this can lead to significantly slower compiles.
- It defeats
ghc
’s warnings for redundant constraints, and thus can lead to a proliferation of redundant constraints as code is changed.
Since: 1.0.0.0