atzeus / FRPNow

Other
89 stars 14 forks source link

Is it possible to export a non-Eq version of toChanges? #12

Closed ocharles closed 9 years ago

ocharles commented 9 years ago

A Behavior is defined as being a constant paired with the next future Event. I'm wondering if this means it's possible to have a toChanges that doesn't wait for an actual observable change, just the switching itself happening:

toChanges' :: Behavior a -> EvStream a
toChanges' b = S $ do
  let loop b = do
        (a,switching) <- observeSwitch b
        switched <-
          plan (fmap loop switching)
        fmap (switch (pure a) switched)
  in loop b

(something like that, anyway)

The reason this is important is for Behaviors that either do not have a notion of equality (eg functions), or for data where equality is more expensive than occasionally seeing the same event multiple times (large tree structures).

ocharles commented 9 years ago

Probably best to hold off on this one, even I'm not convinced of the benefit - it's too easy to lull yourself into a false sense of security as to how often a Behavior is changing. Hm.

atzeus commented 9 years ago

In FRPNow, a behavior is not defined as a constant paired with the next future event (the implementation is similar, but this is not the point), but it is defined as a function from time to value (that's its denotation). This definition makes it impossible to implement toChanges without Eq. Depending on your point of view, this can be perceived as a feature or a bug :) I consider it a feature: how could one observe a change without being able to differentiate between two things?