eveff-1.0.0.0: Efficient effect handlers based on evidence translation.
Copyright(c) 2020 Microsoft Research; Daan Leijen; Ningning Xie
LicenseMIT
Maintainerxnning@hku.hk; daan@microsoft.com
StabilityExperimental
Safe HaskellNone
LanguageHaskell2010

Control.Ev.Ctl

Description

Primitive module that implements type safe multi-prompt control. Used by the Control.Ev.Eff module to implement effect handlers.

Synopsis

Markers

data Marker a Source #

An abstract prompt marker

Instances

Instances details
Eq (Marker a) Source # 
Instance details

Defined in Control.Ev.Ctl

Methods

(==) :: Marker a -> Marker a -> Bool #

(/=) :: Marker a -> Marker a -> Bool #

Show (Marker a) Source # 
Instance details

Defined in Control.Ev.Ctl

Methods

showsPrec :: Int -> Marker a -> ShowS #

show :: Marker a -> String #

showList :: [Marker a] -> ShowS #

markerEq :: Marker a -> Marker b -> Bool Source #

Compare two markers of different types for equality

Control monad

data Ctl a Source #

The Multi Prompt control monad, with existentials ans and b: where ans is the answer type, i.e. the type of the handler/prompt context, and b the result type of the operation.

Constructors

Pure !a

Pure results (only exported for use in the Control.Ev.Eff module)

Instances

Instances details
Monad Ctl Source # 
Instance details

Defined in Control.Ev.Ctl

Methods

(>>=) :: Ctl a -> (a -> Ctl b) -> Ctl b #

(>>) :: Ctl a -> Ctl b -> Ctl b #

return :: a -> Ctl a #

Functor Ctl Source # 
Instance details

Defined in Control.Ev.Ctl

Methods

fmap :: (a -> b) -> Ctl a -> Ctl b #

(<$) :: a -> Ctl b -> Ctl a #

Applicative Ctl Source # 
Instance details

Defined in Control.Ev.Ctl

Methods

pure :: a -> Ctl a #

(<*>) :: Ctl (a -> b) -> Ctl a -> Ctl b #

liftA2 :: (a -> b -> c) -> Ctl a -> Ctl b -> Ctl c #

(*>) :: Ctl a -> Ctl b -> Ctl b #

(<*) :: Ctl a -> Ctl b -> Ctl a #

runCtl :: Ctl a -> a Source #

Run a control monad. This may fail with an "unhandled operation" error if there is a yield to a marker that escaped its prompt scope.

prompt :: (Marker a -> Ctl a) -> Ctl a Source #

Install a prompt with a specific prompt Marker to which one can yield. This connects creation of a marker with instantiating the prompt. The marker passed to the action argument should not escape the action (but this is not statically checked, only at runtime when yielding to it).

yield :: Marker ans -> ((b -> Ctl ans) -> Ctl ans) -> Ctl b Source #

yield m op yields to a specific marker and calls op in that context with a resumption k :: b -> Ctl ans that resumes at the original call-site with a result of type b. If the marker is no longer in the evaluation context, (i.e. it escaped outside its prompt) the yield fails with an "unhandled operation" error.

Unsafe primitives for Control.Ev.Eff

unsafeIO :: IO a -> Ctl a Source #

Unsafe IO in the Ctl monad.

unsafePromptIORef :: a -> (Marker b -> IORef a -> Ctl b) -> Ctl b Source #

Create an IORef connected to a prompt. The value of the IORef is saved and restored through resumptions.