unamb-0.2.7: Unambiguous choice

Copyright(c) Conal Elliott 2008
LicenseBSD3
Maintainerconal@conal.net
Stabilityexperimental
Safe HaskellNone
LanguageHaskell98

Data.Unamb

Contents

Description

Unambiguous choice

For non-flat types (where values may be partially defined, rather than necessarily bottom or fully defined) and information merging, see the lub package, http://haskell.org/haskellwiki/Lub.

See unamb.cabal for the list of contributors.

Synopsis

Purely functional unambiguous choice

unamb :: a -> a -> a Source #

Unambiguous choice operator. Equivalent to the ambiguous choice operator, but with arguments restricted to be equal where not bottom, so that the choice doesn't matter. See also amb.

If anything kills unamb while it is evaluating (like nested unambs), it can be retried later but, unlike most functions, work may be lost.

unamb' :: a -> a -> a Source #

For use when we already know that neither argument is already evaluated

Some useful special applications of unamb

unambs :: [a] -> a Source #

n-ary unamb

assuming :: Bool -> a -> a Source #

Yield a value if a condition is true. Otherwise undefined.

asAgree :: Eq a => a -> a -> a Source #

The value of agreeing values (or undefined/bottom)

parCommute :: (a -> a -> b) -> a -> a -> b Source #

Turn a binary commutative operation into one that tries both orders in parallel. Useful when there are special cases that don't require evaluating both arguments. For non-flat types and information merging, see parCommute in the lub package.

parCommuteShortCircuit :: (a -> a -> b) -> a -> a -> b Source #

Turn a binary commutative operation into one that may try both orders. unlike parCommute, if one argument is already evaluated, the function is tried *only* with that as its first argument and not in both orders. When in doubt, use parCommute.

parAnnihilator :: Eq a => (a -> a -> a) -> a -> a -> a -> a Source #

Binary operation with annihilator element. For instance, (*) & 0, (&&) & False, (||) & True, min & minBound, max & maxBound. Tests either argument as annihilator, in parallel.

parIdentity :: Eq a => (a -> a -> a) -> a -> a -> a -> a Source #

Binary operation with left & right identity element. For instance, (*) & 1, (&&) & True, (||) & False, min & maxBound, max & minBound. Tests either argument as identity, in parallel.

parAnnihilatorIdentity :: Eq a => (a -> a -> a) -> a -> a -> a -> a -> a Source #

por :: Bool -> Bool -> Bool Source #

Parallel or

pand :: Bool -> Bool -> Bool Source #

Parallel and

pmin :: (Ord a, Bounded a) => a -> a -> a Source #

Parallel min with minBound short-circuit and maxBound identity

pmax :: (Ord a, Bounded a) => a -> a -> a Source #

Parallel max with maxBound short-circuit and minBound identity

pmult :: (Eq a, Num a) => a -> a -> a Source #

Parallel multiplication with 0 short-circuit, and 1 identity

Some related imperative tools

amb :: a -> a -> IO a Source #

Ambiguous choice operator. Yield either value. Evaluates in separate threads and picks whichever finishes first. See also unamb and race.

amb' :: a -> a -> IO a Source #

For use when we already know that neither argument is already evaluated

race :: IO a -> IO a -> IO a Source #

Race two actions against each other in separate threads, and pick whichever finishes first. See also amb.

Exception thrown if neither value evaluates

data BothBottom Source #

Use a particular exception as our representation for waiting forever.