
Christopher Howard
Summary: FRP is about handling time-varying values like they were regular values.
Ouch!... Ouch!... My head is beginning to explode!
So, I think I understand the main idea you just explained, but now I am curious about how this black magic is possible. Presumably, these mystical "time-varying values" would actually have to be some kind of partially applied function that receives a time parameter. But how do we, as in your example, add a literal number to a function?
One very simple and naive way to implement FRP is this: newtype Behavior a = Behavior (Time -> a) 'Behavior' is the traditional name for a time-varying value. Then a constant is, as the name says, a constant: instance Applicative Behavior where pure = Behavior . const {- ... -} To get the notation I have used you just need Haskell's fromInteger magic: instance (Num a) => Num (Behavior a) where (+) = liftA2 (+) (-) = liftA2 (-) {- ... -} fromInteger = pure . fromInteger Given that and a behavior that returns the current time, time :: Behavior Time time = Behavior id you can now have 10 + 2*time Greets, Ertugrul -- Not to be or to be and (not to be or to be and (not to be or to be and (not to be or to be and ... that is the list monad.