io-effects-0.1.0: Taming the IO monad

Safe HaskellNone
LanguageHaskell2010

IO.Effects.Internal

Synopsis

Documentation

class (forall x y a. Coercible (e (Program x) a) (e (Program y) a)) => Effect e Source #

Instances
(forall (x :: [(Type -> Type) -> Type -> Type]) (y :: [(Type -> Type) -> Type -> Type]) a. Coercible (e (Program x) a) (e (Program y) a)) => Effect e Source # 
Instance details

Defined in IO.Effects.Internal

Methods

coerceEffect :: e (Program x) a -> e (Program y) a

newtype Program (es :: [(* -> *) -> * -> *]) a Source #

The Program monad is where you will type your effectful programs. The parameter es is an effect list - the list of all possible effects that your program has access to.

When writing computations in the Program monad, you should keep es polymorphic and add constraints using the Member type class. For example, prefer:

myApp :: Member HTTP es => Program es a

over

myApp :: Program ( HTTP : es ) a

as the former is much more composable.

Constructors

Program 

Fields

  • programToIO :: IO a

    Any Program can be reduced at any time to IO, at which point all in scope handlers will be used to provide interpretations to the effects in es.

Instances
Monad (Program es) Source # 
Instance details

Defined in IO.Effects.Internal

Methods

(>>=) :: Program es a -> (a -> Program es b) -> Program es b #

(>>) :: Program es a -> Program es b -> Program es b #

return :: a -> Program es a #

fail :: String -> Program es a #

Functor (Program es) Source # 
Instance details

Defined in IO.Effects.Internal

Methods

fmap :: (a -> b) -> Program es a -> Program es b #

(<$) :: a -> Program es b -> Program es a #

Applicative (Program es) Source # 
Instance details

Defined in IO.Effects.Internal

Methods

pure :: a -> Program es a #

(<*>) :: Program es (a -> b) -> Program es a -> Program es b #

liftA2 :: (a -> b -> c) -> Program es a -> Program es b -> Program es c #

(*>) :: Program es a -> Program es b -> Program es b #

(<*) :: Program es a -> Program es b -> Program es a #

Member (Lift IO :: (Type -> Type) -> Type -> Type) es => MonadIO (Program es) Source # 
Instance details

Defined in IO.Effects.Lift

Methods

liftIO :: IO a -> Program es a #

class Member e es where Source #

The Member e es constraint witnesses that the effect e can be found in the effect list es.

Methods

send :: e (Program es) a -> Program es a Source #

Send a single effect method call into a Program.

Instances
(Effect e, Member e es) => Member e (f ': es) Source # 
Instance details

Defined in IO.Effects.Internal

Methods

send :: e (Program (f ': es)) a -> Program (f ': es) a Source #

(Effect e, HandlerInScope s e es) => Member e (Handled e s ': es) Source # 
Instance details

Defined in IO.Effects.Internal

Methods

send :: e (Program (Handled e s ': es)) a -> Program (Handled e s ': es) a Source #

type ProgramWithHandler e es a = forall s. HandlerInScope s e es => Program (Handled e s ': es) a Source #

A ProgramWithHandler e es computation similar to a normal Program ( e : es) computation, but with the added information that an effect handler for e is in scope.

You will typically not write programs with this type, but you will use it whenever you provide an interpretation using interpret.

interpret Source #

Arguments

:: Effect e 
=> (forall x. e (Program es) x -> Program es x)

This function pattern matches on the effect signature e, and interprets each individual effect method into a program with access to the effects in the effect list es.

-> ProgramWithHandler e es a

The program to supply this interpretation to.

-> Program es a 

You provide an interpretation of an individual effect using interpret.

data Handled e s m a Source #

A Handled effect has the same capabilities as the effect e, but this provides evidence to GHC that an effect handler for this effect is in scope.

Instances
(Effect e, HandlerInScope s e es) => Member e (Handled e s ': es) Source # 
Instance details

Defined in IO.Effects.Internal

Methods

send :: e (Program (Handled e s ': es)) a -> Program (Handled e s ': es) a Source #

class HandlerInScope s e es | s -> e es Source #

Minimal complete definition

reflect