
Nathan Hüsken
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.
You can still write isPressed by interpreting it as "has been pressed" instead: isPressed :: KeySym -> WireP [SDL.Event] Bool isPressed sym = True <$ keyUp sym . keyDown sym <|> fix (\again -> False . not (keyDown sym) --> True . not (keyUp sym) --> again) However, I rather recommend against passing multiple SDL events at once. Wires can handle individual events much better and, when properly designed, also faster. 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.