MyNixOS website logo
Description

Monad transformers that can be run and resumed later, conserving their context.

Given an inner monad M and a transformer T, if T is an interruptible transformer, it becomes possible to intercalate functions over its context with functions over the inner monad. That is, code like this:

runT (f 1 >>= g)
where
f :: Int -> T M a
g :: a -> T M b

Can be broken up like this:

do
let c0 = inTCtx 1
c1 <- resume f ct1
_ <- resume g ct2

That makes it possible to intercalate the execution of different contexts, and treat contexts like data, for iterating or returning them.

As shown on the example, interruptible transformers are resumed with the resume function. State may be managed by specialized functions usually named as inTransfomerCtx and peelTransformerCtx that enclose a value in an initial context and retrieve the value from a context.

Interruptible transformers can be stacked. On this case, they must be resumed with a composition of resume calls, and their contexts must be created and peeled on the inverse order that they appear on the stack. Like:

do
let c0 = inT2Ctx . inT1Ctx $ 1
c1 <- (resume . resume) f ct1
_ <- (resume . resume) g ct2
where
f :: Monad m => Int -> T1 T2 M a
g :: Monad m => a -> T1 T2 M b

For convenience, the Interruptible module exports the resume2 to resume5 functions as composotions of resume. They can be composed further as in resume7 = resume3 . resume4 if necessary.

This package also contains the appliable instantiations of Interruptible for the mtl transformers, the intercalateWith function, that intercalates calls of a function through a list of contexts and parameters, and the SafeIO module that lifts IOException treatment from the base monad into the current resumed context.

Metadata

Version

0.1.1.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows