fused-effects-0.4.0.0: A fast, flexible, fused effect system.

Safe HaskellNone
LanguageHaskell2010

Control.Effect.Interpret

Synopsis

Documentation

runInterpret :: (forall x. eff m (m x) -> m x) -> InterpretC eff m a -> m a Source #

Interpret an effect using a higher-order function.

This involves a great deal less boilerplate than defining a custom Carrier instance, at the expense of somewhat less performance. It’s a reasonable starting point for new interpretations, and if more performance or flexibility is required, it’s straightforward to “graduate” by replacing the relevant runInterpret handlers with specialized Carrier instances for the effects.

At time of writing, a simple passthrough use of runInterpret to handle a State effect is about five times slower than using StateC directly.

run (runInterpret (\ op -> case op of { Get k -> k a ; Put _ k -> k }) get) == a

newtype InterpretC eff m a Source #

Constructors

InterpretC 

Fields

Instances
MonadTrans (InterpretC eff) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

lift :: Monad m => m a -> InterpretC eff m a #

Monad m => Monad (InterpretC eff m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

(>>=) :: InterpretC eff m a -> (a -> InterpretC eff m b) -> InterpretC eff m b #

(>>) :: InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b #

return :: a -> InterpretC eff m a #

fail :: String -> InterpretC eff m a #

Functor m => Functor (InterpretC eff m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

fmap :: (a -> b) -> InterpretC eff m a -> InterpretC eff m b #

(<$) :: a -> InterpretC eff m b -> InterpretC eff m a #

MonadFail m => MonadFail (InterpretC eff m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

fail :: String -> InterpretC eff m a #

Applicative m => Applicative (InterpretC eff m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

pure :: a -> InterpretC eff m a #

(<*>) :: InterpretC eff m (a -> b) -> InterpretC eff m a -> InterpretC eff m b #

liftA2 :: (a -> b -> c) -> InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m c #

(*>) :: InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m b #

(<*) :: InterpretC eff m a -> InterpretC eff m b -> InterpretC eff m a #

MonadIO m => MonadIO (InterpretC eff m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

liftIO :: IO a -> InterpretC eff m a #

Alternative m => Alternative (InterpretC eff m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

empty :: InterpretC eff m a #

(<|>) :: InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a #

some :: InterpretC eff m a -> InterpretC eff m [a] #

many :: InterpretC eff m a -> InterpretC eff m [a] #

(Alternative m, Monad m) => MonadPlus (InterpretC eff m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

mzero :: InterpretC eff m a #

mplus :: InterpretC eff m a -> InterpretC eff m a -> InterpretC eff m a #

(HFunctor eff, Carrier sig m) => Carrier (eff :+: sig) (InterpretC eff m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

eff :: (eff :+: sig) (InterpretC eff m) (InterpretC eff m a) -> InterpretC eff m a Source #

runInterpretState :: (forall x. s -> eff (StateC s m) (StateC s m x) -> m (s, x)) -> s -> InterpretStateC eff s m a -> m (s, a) Source #

Interpret an effect using a higher-order function with some state variable.

This involves a great deal less boilerplate than defining a custom Carrier instance, at the expense of somewhat less performance. It’s a reasonable starting point for new interpretations, and if more performance or flexibility is required, it’s straightforward to “graduate” by replacing the relevant runInterpretState handlers with specialized Carrier instances for the effects.

At time of writing, a simple use of runInterpretState to handle a State effect is about four times slower than using StateC directly.

run (runInterpretState (\ s op -> case op of { Get k -> runState s (k s) ; Put s' k -> runState s' k }) a get) == a

newtype InterpretStateC eff s m a Source #

Constructors

InterpretStateC 

Fields

Instances
MonadTrans (InterpretStateC eff s) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

lift :: Monad m => m a -> InterpretStateC eff s m a #

(HFunctor eff, Carrier sig m, Effect sig) => Carrier (eff :+: sig) (InterpretStateC eff s m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

eff :: (eff :+: sig) (InterpretStateC eff s m) (InterpretStateC eff s m a) -> InterpretStateC eff s m a Source #

Monad m => Monad (InterpretStateC eff s m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

(>>=) :: InterpretStateC eff s m a -> (a -> InterpretStateC eff s m b) -> InterpretStateC eff s m b #

(>>) :: InterpretStateC eff s m a -> InterpretStateC eff s m b -> InterpretStateC eff s m b #

return :: a -> InterpretStateC eff s m a #

fail :: String -> InterpretStateC eff s m a #

Functor m => Functor (InterpretStateC eff s m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

fmap :: (a -> b) -> InterpretStateC eff s m a -> InterpretStateC eff s m b #

(<$) :: a -> InterpretStateC eff s m b -> InterpretStateC eff s m a #

MonadFail m => MonadFail (InterpretStateC eff s m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

fail :: String -> InterpretStateC eff s m a #

Monad m => Applicative (InterpretStateC eff s m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

pure :: a -> InterpretStateC eff s m a #

(<*>) :: InterpretStateC eff s m (a -> b) -> InterpretStateC eff s m a -> InterpretStateC eff s m b #

liftA2 :: (a -> b -> c) -> InterpretStateC eff s m a -> InterpretStateC eff s m b -> InterpretStateC eff s m c #

(*>) :: InterpretStateC eff s m a -> InterpretStateC eff s m b -> InterpretStateC eff s m b #

(<*) :: InterpretStateC eff s m a -> InterpretStateC eff s m b -> InterpretStateC eff s m a #

MonadIO m => MonadIO (InterpretStateC eff s m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

liftIO :: IO a -> InterpretStateC eff s m a #

(Alternative m, Monad m) => Alternative (InterpretStateC eff s m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

empty :: InterpretStateC eff s m a #

(<|>) :: InterpretStateC eff s m a -> InterpretStateC eff s m a -> InterpretStateC eff s m a #

some :: InterpretStateC eff s m a -> InterpretStateC eff s m [a] #

many :: InterpretStateC eff s m a -> InterpretStateC eff s m [a] #

(Alternative m, Monad m) => MonadPlus (InterpretStateC eff s m) Source # 
Instance details

Defined in Control.Effect.Interpret

Methods

mzero :: InterpretStateC eff s m a #

mplus :: InterpretStateC eff s m a -> InterpretStateC eff s m a -> InterpretStateC eff s m a #