3 ms·
I hope that the DSL evaluator can statically determine the oldest historical value that the code will use and avoid keeping unused historical values around? FR
by joeyh 8y ago
I hope that the DSL evaluator can statically determine the oldest historical value that the code will use and avoid keeping unused historical values around?
FRP has a more general purpose way to do that kind of thing; a behavior can accumulate occurrances of an event, using a function provided by the user that takes the previous accumulation and adds a new value to it. This makes it easy to implement things like a rolling average, or to access historical values without keeping unnecessary ones around.
For example, here's a rolling buffer of size n in haskell's reactive-banana:
rollingbuffer n event = accumB [] (fmap update event)
where
update v l
| length l < n || null l = v : l
| otherwise = v : init l
Of course, this needs a language that functions can be implemented in, not a special-purpose DSL.