#Behavior Source

data Behavior :: Type -> Type

A behavior represents a value that changes over time. I.e. a value that depends on time. Semantically a Behavior a can be understood as being equivalent to a function Time -> a. A behavior isn't implemented as a function. But the semantics serve as a mental model in terms of which all other operations can be understood.


#Future Source

data Future :: Type -> Type

A future is a value associated with some point in time. Semantically a Future a is equivalent to (Time, a). That is, a value tagged with time. In practice, Stream is used more often than Future. Future is useful in circumstances where some event occurs exactly once in the future.


#Stream Source

data Stream :: Type -> Type

A stream represents events that occur at specific moments in time. It is a list of future values. Semantically a Stream a can be understood as List (Time, a). That is, a list of values where each value is associated with a specific moment in time. The time values have to be increasing. But, they do not have to be strictly increasing. This means that a stream can have several occurrences at the same moment in time. This can be very useful in certain circumstances.


  • Semigroup (Stream a)

    The Semigroup instance merges two streams by combining their occurrences while keeping them ordered with respect to time.

    One detail to be aware of is what happens in case both the left and the right stream contains occurences that occur simultaneously. The sortWith in the semantics below is stable. This implies that simultaneous ocurrences in the left stream will occurr before ones in the righ stream.


    append s1 s2 = sortWith (\(time, a) -> time) (s1 <> s2)
  • Monoid (Stream a)

    The Monoid instance lets mempty be a stream without any occurrences.

  • Functor Stream

#Now Source

data Now :: Type -> Type

A Now represents a computation that occurs at a specific moment in time. That moment is always "now". This means that computations inside the now can depend on time—but only the current point in time. The requirement that Time is always the current moment in time is enforced and guaranteed by the API for working with time.

In addition to containing time-dependent computations a Now can also contain computations with side-effects. An approximate model of a Now a is that it is equivalent to Time -> IO a.

Now servers two purposes in Hareactive: It makes it possible to create stateful behaviors that depends on the past without introducing space-leaks (a notorious problem in FRP). Additionally, it is the glue between FRP primitives and effectful computations.