MyNixOS website logo
Description

Explore continuations with trepidation.

Please see the README on GitHub at https://github.com/isovector/prospect#readme

prospect

Build Status | Hackage

Dedication

It is absolutely necessary, for the peace and safety of mankind, that some of earth's dark, dead corners and unplumbed depths be let alone; lest sleeping abnormalities wake to resurgent life, and blasphemously surviving nightmares squirm and splash out of their black lairs to newer and wider conquests.

H.P. Lovecraft

Overview

prospect is a library that provides primitives for exploring functions, and by extension, monads. As such, it allows for a best-attempt static analysis of free monads. Such power, however, does not come for free; using prospect is an implicit promise with the Eldrich horrors that you'll tread lightly. Feckless wanderers into these depths will be rewarded with naught but terror, madness, and runtime crashes.

Usage

The library provides a function, prospect :: Free f a -> (Maybe a, [f ()]), which can probe the depths of a free monad, finding as many f constructors as it can before the monad branches dynamically.

Be careful when inspecting the f ()s, if any of them depend on variables bound in the monad, they will leak exceptions when you are least expecting them. It's a good idea to run your f ()s through ensure :: Alternative m => a -> m a after you've scrutinized their constructors.

Example

prospect can be used to perform a best-effort static analysis of a free monad:

data Pattern a
  = Cont (Bool -> a)
  | Action Int a
  deriving (Functor, Generic1)


cont :: MonadFree Pattern m => m Bool
cont = liftF $ Cont id


action :: MonadFree Pattern m => Int -> m ()
action i = liftF $ Action i ()


success :: (Maybe String, [Pattern ()]
success = prospect $ do
  a <- cont
  action 1
  pure "success"
-- success = (Just "success", [Cont (const ()), Action 1 ()])


failure :: (Maybe String, [Pattern ()]
failure = prospect $ do
  a <- cont
  action 1
  if a  -- static analysis ends here, as it would require branching on the
        -- result of a monadic action
    then action 2
    else action 3
  action 4
  pure "failure"
-- failure = (Nothing, [Cont (const ()), Action 1 ()])

In these examples, we can continue analyzing a Free Pattern monad until the result of its Cont continuation is forced.

Metadata

Version

0.1.0.0

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