lvish-1.1.4: Parallel scheduler, LVar data structures, and infrastructure to build more.

Safe HaskellTrustworthy
LanguageHaskell98

Data.LVar.IVar

Contents

Description

IVars are the very simplest form of LVars. They are either empty or full, and contain at most a single value.

For further information on using IVars in Haskell, see the monad-par and meta-par packages and papers:

Unlike the IVar type provided by monad-par, the IVar type provided in this module permits repeated puts of the same value, in keeping with the lattice-based semantics of LVars in which a put takes the least upper bound of the old and new values.

Synopsis

Documentation

newtype IVar s a Source

An IVar is the simplest form of LVar.

Constructors

IVar (LVar s (IORef (Maybe a)) a) 

Instances

LVarWBottom IVar 
LVarData1 IVar

An IVar can be treated as a generic container LVar which happens to contain at most one value! Note, however, that the polymorphic operations are less useful than the monomorphic ones exposed by this module.

Foldable (IVar Trvrsbl) 
Eq (IVar s a)

Physical equality, just as with IORefs.

Show a => Show (IVar Trvrsbl a)

For convenience only; the user could define this.

Show a => Show (IVar Frzn a) 
DeepFrz a => DeepFrz (IVar s a) 
type LVContents IVar a = () 
type FrzType (IVar s a) = IVar Frzn (FrzType a) 

Basic IVar operations, same as in monad-par

new :: Par d s (IVar s a) Source

A new IVar that starts out empty.

get :: IVar s a -> Par d s a Source

Read the value in a IVar. The get can only return when the value has been written by a prior or concurrent put to the same IVar.

put :: (Eq a, NFData a) => IVar s a -> a -> Par d s () Source

Fill an IVar.

put_ :: Eq a => IVar s a -> a -> Par d s () Source

Put a value into an IVar. Multiple puts to the same IVar are not allowed, and result in a runtime error, unless the values put happen to be (==).

This function is always at least strict up to WHNF in the element put.

Derived IVar operations, same as in monad-par

spawn :: (Eq a, NFData a) => Par d s a -> Par d s (IVar s a) Source

A simple future represented as an IVar. The result is fully evaluated before the child computation returns.

spawn_ :: Eq a => Par d s a -> Par d s (IVar s a) Source

A version of spawn that uses only WHNF, rather than full NFData.

spawnP :: (Eq a, NFData a) => a -> Par d s (IVar s a) Source

LVar-style operations

freezeIVar :: IVar s a -> Par QuasiDet s (Maybe a) Source

A specialized freezing operation for IVars that leaves the result in a handy format (Maybe).

fromIVar :: IVar Frzn a -> Maybe a Source

Unpack a frozen IVar (as produced by a generic freeze operation) as a more palatable data structure.

whenFull :: Maybe HandlerPool -> IVar s a -> (a -> Par d s ()) -> Par d s () Source

Register a handler that fires when the IVar is filled, which, of course, only happens once.