
Miguel Negrao wrote:
One other question, is it possible in reactive-banana to define “recursive” event streams. For instance consider a stream which receives numbers between 0.0 and 1.0. If the last outputted value was between 0.8 an 1.0 then output 1-x otherwise output x. After that it only leta numbers through if they are between 0.0 and 0.2 or between 0.8 and 1.0.
The standard way to do recursion in reactive-banana is to use multiple recursion between a Behavior and an Event . See also http://stackoverflow.com/a/7852344/403805 Note that the specification you gave does not require recursion, though. Here an implementation of your example. import Reactive.Banana example :: Event t Double -> Event t Double example e = filterJust e2 where e2 = f <$> bIsFirst <@> e bIsFirst = stepper True $ False <$ e between x a b = a < x && x < b f True x | between x 0.8 1.0 = Just $ 1 - x | otherwise = Just $ x f False x | between x 0.8 1.0 = Just $ x | between x 0.0 0.2 = Just $ x | otherwise = Nothing Here an example output GHCi> interpretModel example [[0.9],[0.3],[0.4]] [[9.999999999999998e-2],[],[]] Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com