unamb-custom-0.12: Functional concurrency with unamb using a custom scheduler.

PortabilityGHC only
Stabilityexperimental
MaintainerLuke Palmer <lrpalmer@gmail.com>

UnambCustom.Unamb

Description

Functional concurrency with unambiguous choice. The primary export of this module is the unamb function, which has the following semantics:

 unamb x   _|_ = x
 unamb _|_ x   = x
 unamb x   x   = x

This function is only well-defined when the arguments are constrained to be either equal or _|_. Using it in other capacities will break purity.

In particular, it is always safe to use on the () type.

This is a reimplementation of the unamb package by Conal Elliott. This package implements a custom thread scheduler, whose purpose is to make feasabile "dense" uses of unamb such as:

 foldr1 unamb [ if x == 100 then 100 else undefined | x <- [0..] ] 

Synopsis

Documentation

race :: IO a -> IO a -> IO aSource

Race two actions against each other, returning the value of the first one to finish.

unamb :: a -> a -> aSource

Unambiguous choice. Calling unamb x y has a proof obligation that if x /= _|_ and y /= _|_ then x = y. If this is satisfied, returns the more defined of the two.

unamb will treat any exception raised as _|_.

rebootScheduler :: IO ()Source

Kill all active threads managed by the custom scheduler. Useful for debugging in interactive sessions, but not recommended otherwise (it will cause all running unambs to block forever).