# Old-reactive

### From HaskellWiki

m (→Data.Reactive: Reactive --> Stepper) |
m (→Data.Reactive) |
||

Line 51: | Line 51: | ||

</haskell> |
</haskell> |
||

− | This <hask>Reactive</hask> representation can be thought of a "reactive weak head normal form", to which arbitrary reactive expressions may be rewritten. The rewrite rules and their justification in terms of simple denotational semantics will be described in an upcoming paper. |
+ | This <hask>Reactive</hask> representation can be thought of a ''reactive weak head normal form'', to which arbitrary reactive expressions may be rewritten. The rewrite rules and their justification in terms of simple denotational semantics will be described in an upcoming paper. |

Although the basic <hask>Reactive</hask> type describes ''discretely''-changing values, ''continuously''-changing are defined simply by composing <hask>Reactive</hask> and a simple type functions of time (see below). |
Although the basic <hask>Reactive</hask> type describes ''discretely''-changing values, ''continuously''-changing are defined simply by composing <hask>Reactive</hask> and a simple type functions of time (see below). |

## Revision as of 03:56, 20 December 2007

## Contents |

## 1 Abstract

**Reactive** is a simple foundation for programming reactive systems functionally. Like Fran/FRP, it has a notions of (reactive) behaviors and events. Like DataDriven, Reactive has an efficient, data-driven implementation. The main difference between Reactive and DataDriven are

- Reactive provides and builds on "functional futures", which in turn build on Concurrent Haskell threads, while DataDriven builds on continuation-based computations; and
- The algebras of events and reactive values (called events and sources in DataDriven) are
*purely*functional. I couldn't figure out how to accomplish that in DataDriven. - Reactive manages (I hope) to get the efficiency of data-driven computation with a (sort-of) demand-driven architecture. For that reason, Reactive is garbage-collector-friendly, while DataDriven depends on weak references (because GC favors demand-driven computation.)
- Reactive elegantly and efficiently
*caches*values. - Reactive uses the term "reactive values" (), where DataDriven uses "sources" (Reactive).Source

Besides this wiki page, here are more ways to find out about Reactive:

- Read the Haddock docs.
- Get the code repository:
.`darcs get http://darcs.haskell.org/packages/reactive` - Install from Hackage.
- See the version history.

Please leave comments at the Talk page.

## 2 Modules

### 2.1 Data.Future

A "future" is a value that will become knowable only later. 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:- :Monoidis a future that never becomes knowable.memptyis whichever ofa `mappend` bandais knowable first.b
- : apply a function to a future. The result is knowable when the given future is knowable.Functor
- :Applicativegives value knowable since the beginning of time.pureapplies 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: is the same asreturn(as always).purecascades futures.(>>=)resolves a future future value into a future value.join

### 2.2 Data.SFuture

A target denotational semantics for Data.Future -- simple, precise, and deterministic, in terms of time/value pairs.

### 2.3 Data.Reactive

This module defines *events* and *reactive values*. An event is stream of future values in order of availability. A reactive value is a discretly time-varying value. These two types are closely linked: a reactive value is a current value and an event (the future values), while an event is simply a future reactive value.

newtype Event a = Event (Future (Reactive a)) data Reactive a = a `Stepper` Event a

*reactive weak head normal form*, to which arbitrary reactive expressions may be rewritten. The rewrite rules and their justification in terms of simple denotational semantics will be described in an upcoming paper. Although the basic

*discretely*-changing values,

*continuously*-changing are defined simply by composing

type Time = Double type ReactiveB = Reactive :. Fun Time