HeinrichApfelmus/reactive-banana — Issue #26: Proposal: One semantics to bind them all
Author: HeinrichApfelmus
Created: 2012-01-03 12:58:39+00:00
State: open
Labels: design-discussion

Several proposals for changes in semantics are floating around right now

* issue #22 on `Behavior` replacing `Discrete`
* issue #25 on multiple simultaneous events

The cost of switching semantics in an existing library are traditionally high, but I want to facilitate experimentation with the following proposal.

### Proposal

Implement a primitive version of the API on top of which alternate proposals can be implemented.

The idea is to have a module `Primitive` offering, say, two data types

module Reactive.Banana.Primitive where

data Event a
data Behavior a

which are the basic building blocks for implementing other semantics. (Though I'm not sure yet what these data types are going to be.)

For instance, event streams that allow multiple simultaneous events (see issue #22) can then be implemented as

module Reactive.Banana.Simultaneous where

import qualified Reactive.Banana.Primitive as Primitive

type Event a = Primitive.Event [a]
type Behavior a = Primitive.Behavior a

union :: Event a -> Event a -> Event a
union = Primitive.unionWith (++)
...

Another example would be behaviors with an integrated notion of updates (issue #25)

module Reactive.Banana.Updated where

import qualified Reactive.Banana.Primitive as Primitive

type Event a = Primitive.Event a
type Behavior a = (Primitive.Behavior a, Event a)

fromPoll :: IO a -> Event () -> NetworkDescription (Behavior a)
fromPoll m e = do
b <- Primitive.fromPoll m
return $ (b, b <@ e)
...

And so on.

Of course, one variant would count as "offical" and the intention is that experimentation will help find the most blessed semantics. This proposal also allows for reasonably easy backward compatibility whenever the official semantics are being changed; you just have to change a few imports.

Thoughts?