[Haskell-cafe] Improving event management in elerea

Patai Gergely patai_gergely at fastmail.fm
Fri Aug 14 04:51:18 EDT 2009

> or
> event :: a -> Signal Bool -> (a -> a) -> SignalMonad (Signal a)
> event v0 b f = accumIf v0 f =<< return b
> ?
That's not a good idea, because it doesn't take time into consideration,
so you'd jump a huge amount in every frame. What I had in mind is
something like this:

ifte :: Signal Bool -> Signal a -> Signal a -> Signal a
ifte sc st sf = (\c t f -> if c then t else f) <$> sc <*> st <*> sf 

And then:

playerX <- integral playerX0
             ( ifte (lpress &&@ (playerX >@ pure (-fieldW))) (-1) 0
             + ifte (rpress &&@ (playerX <@ pure (fieldW-playerW))) (1)

This won't be perfect, since the paddle can get a bit beyond the edge of
the field. This can be prevented by using some kind of clamped integral,
for instance, which you can again define in terms of transfer, just like
the plain integral.

Also, note that mixing bind and return is redundant, since "f =<< return
b" is equivalent to "f b".


http://www.fastmail.fm - Choose from over 50 domains or use your own

More information about the Haskell-Cafe mailing list