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

Safe HaskellTrustworthy

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

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) 

Basic IVar operations, same as in monad-par

new :: Par e s (IVar s a)

A new IVar that starts out empty.

get :: HasGet e => IVar s a -> Par e s a

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 :: (HasPut e, Eq a, NFData a) => IVar s a -> a -> Par e s ()

Fill an IVar.

put_ :: (HasPut e, Eq a) => IVar s a -> a -> Par e s ()

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 :: (HasPut e, Eq a, NFData a) => Par e s a -> Par e s (IVar s a)

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

spawn_ :: (HasPut e, Eq a) => Par e s a -> Par e s (IVar s a)

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

spawnP :: (HasPut e, Eq a, NFData a) => a -> Par e s (IVar s a)

LVar-style operations

freezeIVar :: HasFreeze e => IVar s a -> Par e s (Maybe a)

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

fromIVar :: IVar Frzn a -> Maybe a

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 e s ()) -> Par e s ()

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

Note that like fork, adding handlers doesn't introduce specifically tracked effects in the e signature.