[Haskell-cafe] scheduling an alarm

Ketil Malde ketil at malde.org
Thu Jan 28 03:05:39 EST 2010


Brian Denheyer <briand at aracnet.com> writes:

>>>>> doEvent f usDelay = forkIO $
>>>>>   threadDelay usDelay
>>>>>   doEvent f usDelay
>>>>>   f

There's a missing 'do' here, right?

>> Infinite loop?  yes, that is what you wanted.  Memory gobbling?  Why
>> would you think that?

> Why would I think that ?

> doEvent f usDelay = do forkIO $ threadDelay usDelay
>                        doEvent f usDelay
>                        f

Are you sure this isn't interpreted as:

    doEvent f usDelay = do (forkIO $ threadDelay usDelay)
                           doEvent f usDelay
                           f

I.e. just forking off processes that only does a delay, never even
getting to 'f'?

I interpreted Thomas's code to mean:

    doEvent f usDelay = forkIO $ 
                 (do threadDelay usDelay
                     doEvent f usDelay
                     f)

Which appears to work nicely here.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Haskell-Cafe mailing list