eveff-0.1.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.Util

Contents

Description

Some definitions for common effects.

Synopsis

Reader

data Reader a e ans Source #

A standard reader effect for values of type a.

Constructors

Reader 

Fields

  • ask :: !(Op () a e ans)

    get the reader value of type a (as perform ask ())

reader :: a -> Eff (Reader a :* e) ans -> Eff e ans Source #

A handler for a Reader effect with a value of type a.

State

data State a e ans Source #

A standard state effect of type a.

Constructors

State 

Fields

  • get :: !(Op () a e ans)

    Get the current state (as perform get ())

  • put :: !(Op a () e ans)

    Set the current state (as perform put x)

state :: a -> Eff (State a :* e) ans -> Eff e ans Source #

A state handler that takes an initial state of type a.

Writer

data Writer a e ans Source #

A standard writer effect of type a

Constructors

Writer 

Fields

  • tell :: !(Op a () e ans)

    Output a value of type a (as perform tell msg)

writer :: Monoid a => Eff (Writer a :* e) ans -> Eff e (ans, a) Source #

A standard Writer handler for any monoidal type a. Returns the final result of type ans and the appended tell arguments.

Exception

data Except a e ans Source #

A standard exception effect, throwing values of type a.

Constructors

Except 

Fields

  • throwError :: !(forall b. Op a b e ans)

    Throw an exception with a value of type a (as perform throwError x)

catchError :: Eff (Except a :* e) ans -> (a -> Eff e ans) -> Eff e ans Source #

Handle an exception.

exceptEither :: Eff (Except a :* e) ans -> Eff e (Either a ans) Source #

Transform an exception effect to an Either type.

exceptMaybe :: Eff (Except a :* e) ans -> Eff e (Maybe ans) Source #

Transform an exception effect to a Maybe type.

exceptDefault :: ans -> Eff (Except a :* e) ans -> Eff e ans Source #

Remove the exception effect using a default value in case an exception was thrown.

Choice

data Choose e ans Source #

Choose implements backtracking.

Constructors

Choose 

Fields

  • none :: !(forall a. Op () a e ans)

    @`perform none ()` indicates no result

  • choose :: !(Op Int Int e ans)

    perform choose n` resumes up to n times (returning 1 up to n@)

chooseFirst :: Eff (Choose :* e) ans -> Eff e (Maybe ans) Source #

Return the first result found in a computation using choose for backtracking.

chooseAll :: Eff (Choose :* e) a -> Eff e [a] Source #

Return all possible results found in a computation using choose for backtracking

Orphan instances

Choose :? e => Alternative (Eff e) Source # 
Instance details

Methods

empty :: Eff e a #

(<|>) :: Eff e a -> Eff e a -> Eff e a #

some :: Eff e a -> Eff e [a] #

many :: Eff e a -> Eff e [a] #

Choose :? e => MonadPlus (Eff e) Source # 
Instance details

Methods

mzero :: Eff e a #

mplus :: Eff e a -> Eff e a -> Eff e a #