reactive-0.0: Simple foundation for functional reactive programmingSource codeContentsIndex
Data.Future
Stabilityexperimental
Maintainerconal@conal.net
Description

A future value is a value that will become knowable only later. This module gives a way to manipulate them functionally. For instance, a+b becomes knowable when the later of a and b becomes knowable. See http://en.wikipedia.org/wiki/Futures_and_promises.

Primitive futures can be things like /the value of the next key you press, or the value of LambdaPix stock at noon next Monday/.

Composition is via standard type classes: Functor, Applicative, Monad, and Monoid. Some comments on the Future instances of these classes:

  • Monoid: mempty is a future that never becomes knowable. a mappend b is whichever of a and b is knowable first.
  • Functor: apply a function to a future. The result is knowable when the given future is knowable.
  • Applicative: pure gives value knowable since the beginning of time. '(<*>)' applies a future function to a future argument. Result available when both are available, i.e., it becomes knowable when the later of the two futures becomes knowable.
  • Monad: return is the same as pure (as always). (>>=) cascades futures. join resolves a future future into a future.

The current implementation is nondeterministic in mappend for futures that become knowable at the same time or nearly the same time. I want to make a deterministic implementation.

See Data.SFuture for a simple denotational semantics of futures. The current implementation does not quite implement this target semantics for mappend when futures are available simultaneously or nearly simultaneously. I'm still noodling how to implement that semantics.

Synopsis
data Future a
force :: Future a -> IO a
newFuture :: IO (Future a, a -> IO ())
future :: IO a -> Future a
never :: Future a
race :: Future a -> Future a -> Future a
race' :: Future a -> Future a -> Future a
runFuture :: Future (IO ()) -> IO ()
Documentation
data Future a Source
Value available in the future.
show/hide Instances
force :: Future a -> IO aSource
Get a future value. Blocks until the value is available. No side-effect.
newFuture :: IO (Future a, a -> IO ())Source
Make a Future and a way to fill it. The filler should be invoked only once. Later fillings may block.
future :: IO a -> Future aSource
Make a Future, given a way to compute a (lazy) value.
never :: Future aSource
A future that will never happen
race :: Future a -> Future a -> Future aSource
A future equal to the earlier available of two given futures. See also 'race\''.
race' :: Future a -> Future a -> Future aSource
Like race, but the winner kills the loser's thread.
runFuture :: Future (IO ()) -> IO ()Source
Run an IO-action-valued Future.
Produced by Haddock version 2.3.0