apfelmus at quantentunnel.de
Thu Sep 20 14:02:58 CEST 2012
Ertugrul Söylemez wrote:
> Wire is also an Alternative, which
> allows concise and efficient switching with very little cruft. The
> following wire renders "yes" when the "keyDown Space" event happens and
> "no" otherwise:
> pure "yes" . keyDown Space <|> pure "no"
> Or with the OverloadedStrings extension:
> "yes" . keyDown Space <|> "no"
> All classic (non-wire) FRP implementations need switching or another
> ad-hoc combinator for this. If you happen to need switching it's also a
> lot simpler using wires:
> "please press space" . notE (keyDown Space) --> "thanks"
> This one waits for the Space key and then outputs "thanks" forever. So
> far Netwire has the fastest and most elegant way of dealing with events
> compared to all other libraries I have tried.
These examples look neat!
I'm a bit confused about the model you are using, though. If I
understand that correctly, you don't distinguish between events and
behaviors; rather, you are working with data streams in discrete time
steps. Still, I don't quite understand. What is
pure "yes" . keyDown Space <|> pure "no"
supposed to mean? If it's a function Time -> String , how long does it
have the "yes" value? 439.7 milliseconds? If it's an event, how often
does the "no" event fire?
Concerning the other example, I don't understand what the expression
"please press space" . notE (keyDown Space)
means. If it's a function, what value does it have when the key was
pressed? If it's an event, how often does it "fire" the string value?
More information about the Beginners