[Haskell-beginners] firering event in netwire
nathan.huesken at posteo.de
Sat Sep 29 19:19:46 CEST 2012
On 09/29/2012 08:56 AM, Ertugrul Söylemez wrote:
>> Or asked differently, how is the "keyDown" event defined, that was
>> talked of in an earlier mail?
> In the direct case you can define it as a simple composition:
> isSym :: KeySym -> SDL.Event -> Bool
> isSym s (KeyDown s') = s == s'
> isSym _ _ = False
> keyDown = require . isSym
While I understand the principals, I am unsure about the practical usage.
The input of keyDown is an SDL.Event. But in an application, I would
have a list of Events for every invocation of stepWire. So I could
define keyDown like this:
keyDown s = require . and . map (isSym s)
That would give me an event when my desired keypress event is in the
list of input events.
but if I then want to create a wire passed in this which outputs if a
given key is currently pressed, I would attempt something like this:
isPressed :: KeySym -> WireP [SDL.Event] Bool
isPressed s = hold . (True . (keyDown s) <|> False . (keyUp s))
But if some fast typer releases and presses within one stepWire a
certain key, isPressed would produce an incorrect result.
More information about the Beginners