Safe Haskell | Trustworthy |
---|

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:

- http://hackage.haskell.org/package/monad-par
- http://www.cs.indiana.edu/~rrnewton/papers/haskell2011_monad-par.pdf
- http://hackage.haskell.org/package/meta-par
- http://www.cs.indiana.edu/~rrnewton/papers/2012-ICFP_meta-par.pdf

Unlike the `IVar`

type provided by `monad-par`

, the `IVar`

type
provided in this module permits repeated `put`

s 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.

- newtype IVar s a = IVar (LVar s (IORef (Maybe a)) a)
- new :: Par e s (IVar s a)
- get :: HasGet e => IVar s a -> Par e s a
- put :: (HasPut e, Eq a, NFData a) => IVar s a -> a -> Par e s ()
- put_ :: (HasPut e, Eq a) => IVar s a -> a -> Par e s ()
- spawn :: (HasPut e, Eq a, NFData a) => Par e s a -> Par e s (IVar s a)
- spawn_ :: (HasPut e, Eq a) => Par e s a -> Par e s (IVar s a)
- spawnP :: (HasPut e, Eq a, NFData a) => a -> Par e s (IVar s a)
- freezeIVar :: HasFreeze e => IVar s a -> Par e s (Maybe a)
- fromIVar :: IVar Frzn a -> Maybe a
- whenFull :: Maybe HandlerPool -> IVar s a -> (a -> Par e s ()) -> Par e s ()

# Documentation

newtype IVar s a

LVarWBottom IVar | |

LVarData1 IVar | An |

Foldable (IVar Trvrsbl) | |

Eq (IVar s a) | Physical equality, just as with |

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

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

Put a value into an IVar. Multiple `put`

s 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.

# 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`

).