HeinrichApfelmus/reactive-banana — Issue #27: Proposal: Infinitesimal delays
Author: ehird
Created: 2012-01-06 16:21:43+00:00
State: open

Splitting this off from issue #25 to stop derailing it :)

### The proposal

The basic idea is to add a combinator

```haskell
delay :: Event a -> Event a
```

We define its semantics by adding an infinitesimal element ε to `Time` and implementing `delay` as follows:

```haskell
delay = map (\(t,x) -> (t+ε,x))
```

We can then give a more natural definition for `union`, avoiding the problems of simultaneous events (as discussed in issue #25):

```haskell
union xss@((tx,x):xs) yss@((ty,y):ys) =
case compare tx ty of
LT -> (tx,x) : union xs yss
EQ -> (tx,x) : union (delay xs) (delay yss)
GT -> (ty,y) : union xss ys
```

and perhaps other combinators (`stepper`?).

### Advantages

The complications of simultaneous occurrences can be eliminated without sacrificing the "compositionality" that `union` offers is retained.

>In fact, the more that I think about it, the more that it would be nice to have a way to delay an event. There is a situation in my code where the most declarative way for me to express my code unfortunately involved an event cycle which meant I had to uglify it and duplicate some code in order to break the cycle. Having the ability to delay an event in order to explicitly break cycles would be useful --- though it also gives one the ability to create infinite loops, as I had done inadvertently in my original definition :-), though I think I know how to fix that.

— @gcross

### Problems

* Conal thinks it complicates the semantics (@HeinrichApfelmus: Can you expand on what he found objectionable? Adding infinitesimals to `Time` seems simple to me.)
* We don't have a model for it.
* ?