@hackage mpeff0.1.0.0

Efficient effect handlers based on evidence-passing semantics

MpEff: Efficient effect handlers based on Evidence Passing Semantics

Efficient effect handlers based on Evidence Passing Semantics. The implementation is based on

Generalized Evidence Passing for Effect Handlers, Ningning Xie and Daan Leijen, 2021 (pdf).

The implementation is closely based on the Ev.Eff library described in detail in

Effect Handlers in Haskell, Evidently, Ningning Xie and Daan Leijen, Haskell 2020 (pdf).

The Mp.Eff and Ev.Eff libraries expose the exact same interface, but the Mp.Eff library can express full effect handler semantics, including non-scoped resumptions -- it is slightly slower though (see the 2021 paper for benchmarks and a detailed comparison).

Installation:

  • First install stack
  • Build with > stack build

An example of defining and using a Reader effect:

{-# LANGUAGE  TypeOperators, FlexibleContexts, Rank2Types #-}
import Control.Mp.Eff

-- A @Reader@ effect definition with one operation @ask@ of type @()@ to @a@.
data Reader a e ans = Reader{ ask :: Op () a e ans }

greet :: (Reader String :? e) => Eff e String
greet = do s <- perform ask ()
           return ("hello " ++ s)

test :: String
test = runEff $
       handler (Reader{ ask = value "world" }) $  -- @:: Reader String () Int@
       do s <- greet                              -- executes in context @:: Eff (Reader String :* ()) Int@
          return (length s)

Enjoy,

Ningning Xie and Daan Leijen, Mar 2021.