[Haskell-cafe] Infinite lists in real world programs

Yves Parès limestrael at gmail.com
Sun Dec 26 12:35:42 CET 2010


>I had a similar experience under Windows. Never really got to find out
>why it happened. You might try adding a short threadDelay call in your
>main loop and see what happens; I think it helped back then.

Wow... it's even worse. Even with a threadDelay of 1ms the FPS drop down to
a chaotic 20~30.
I forgot to say: I run Ubuntu 10.10 (32bits), and I use HGL for the
graphics, not GLFW. This may be important since HGL seems to react badly to
threadDelay (The application simply blocks if there are no key pressed or
mouse moved), so maybe the original problem comes from it.
This is my main loop :

mainLoop :: H.Window -> (Input -> IO (H.Graphic, Bool)) -> Time -> IO ()
mainLoop win driver elapsed = do
  clk <- mkClock
  threadDelay 1000   -- in microseconds
  events <- whileJust (H.maybeGetWindowEvent win) return
  (graphic, continue) <- driver $ Input elapsed events
  H.setGraphic win graphic
  when continue $ do
    el <- clk
    print $ round $ 1/el
    mainLoop win driver el

Where
   data Input = Input Data.Time.Clock.NominalDiffTime [H.Event]

mkClock generates an IO action that, when evaluated, gives the time elapsed
since mkClock.


>Note that Param is essentially the same as
>combining the Simple variant with a reader monad layer, so it shouldn't
>affect the basic operation of the library.

Okay. It wasn't very likely the problem came from it.


2010/12/26 Patai Gergely <patai_gergely at fastmail.fm>

> > I keep on experimenting with Elerea. I'm on my way to achieve a simple
> > Pong
> > game, but the display is awfully jerky, however the sampling occurs on
> > average every 0,0015 sec, which gives 670 FPS.
> I had a similar experience under Windows. Never really got to find out
> why it happened. You might try adding a short threadDelay call in your
> main loop and see what happens; I think it helped back then.
>
> > All the elerea-examples run perfectly fine on my computer, however I use
> > FRP.Elerea.Param, which none of the examples use. But there isn't no
> > known problem with Param?
> Haven't heard of any. Note that Param is essentially the same as
> combining the Simple variant with a reader monad layer, so it shouldn't
> affect the basic operation of the library.
>
> Gergely
>
> --
> http://www.fastmail.fm - Same, same, but different...
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101226/6cd2db4a/attachment.htm>


More information about the Haskell-Cafe mailing list