haskell-cafe@haskell.org
[Top] [All Lists]

Re: [Haskell-cafe] scheduling an alarm

Subject: Re: [Haskell-cafe] scheduling an alarm
From: Ketil Malde
Date: Thu, 28 Jan 2010 09:05:39 +0100
Brian Denheyer <briand@xxxxxxxxxxx> 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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>