reactive-0.5.0.1: Simple foundation for functional reactive programming

Stabilityexperimental
Maintainerconal@conal.net

Data.SFuture

Contents

Description

A sort of semantic prototype for functional futures, roughly as described at http://en.wikipedia.org/wiki/Futures_and_promises.

A future 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.

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: Ord, Functor, Applicative, Monad, and Monoid. Some comments on the Future instances of these classes:

  • Ord: a min b is whichever of a and b is knowable first. a max b is whichever of a and b is knowable last.
  • Monoid: mempty is a future that never becomes knowable. mappend is the same as min.
  • 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 value into a future value.

Futures are parametric over time as well as value types. The time parameter can be any ordered type.

Please keep in mind that this module specifies the interface and semantics, rather than a useful implementation. See Data.Future for an implementation that nearly implements the semantics described here.

On second thought, I'm experimenting with using this module in an usable implementation of events. See Data.MEvent.

Synopsis

Time & futures

type Time t = Max (AddBounds t)Source

Time of some event occurrence, which can be any Ord type. In an actual implementation, we would not usually have access to the time value until (slightly after) that time. Extracting the actual time would block until the time is known. The added bounds represent -Infinity and +Infinity. Pure values have time minBound (-Infinity), while eternally unknowable values (non-occurring events) have time maxBound (+Infinity).

newtype Future t a Source

A future value of type a with time type t. Semantically, just a time/value pair, but those values would not be available until forced, which could block.

Constructors

Future 

Fields

unFuture :: (Time t, a)
 

Instances

Ord t => Monad (Future t) 
Functor (Future t) 
Ord t => Applicative (Future t) 
Eq (Future t a) 
Ord t => Ord (Future t a) 
(Show t, Show a) => Show (Future t a) 
Ord t => Monoid (Future t a) 

futTime :: Future t a -> Time tSource

A future's time

futVal :: Future t a -> aSource

A future's value

sequenceF :: Functor f => Future t (f a) -> f (Future t a)Source

Make a future container into a container of futures.

To go elsewhere

newtype Max a Source

Ordered monoid under max.

Constructors

Max 

Fields

getMax :: a
 

Instances

Bounded a => Bounded (Max a) 
Eq a => Eq (Max a) 
Ord a => Ord (Max a) 
Read a => Read (Max a) 
Show a => Show (Max a) 
(Ord a, Bounded a) => Monoid (Max a) 

newtype Min a Source

Ordered monoid under min.

Constructors

Min 

Fields

getMin :: a
 

Instances

Bounded a => Bounded (Min a) 
Eq a => Eq (Min a) 
Ord a => Ord (Min a) 
Read a => Read (Min a) 
Show a => Show (Min a) 
(Ord a, Bounded a) => Monoid (Min a) 

data AddBounds a Source

Wrap a type into one having new least and greatest elements, preserving the existing ordering.

Constructors

MinBound 
NoBound a 
MaxBound 

Instances

Bounded (AddBounds a) 
Eq a => Eq (AddBounds a) 
Ord a => Ord (AddBounds a) 
Read a => Read (AddBounds a) 
Show a => Show (AddBounds a)