Stop using "Int" for microsecond delays in "base"

Paul Johnson paul at
Sun Mar 27 11:15:48 CEST 2011

On 26/03/11 19:16, Henning Thielemann wrote:
> Paul Johnson schrieb:
>> The "base" library has the "threadDelay" primitive, which takes an Int
>> argument in microseconds.  Unfortunately this means that the longest
>> delay you can get on a 32 bit machine with GHC is just under 36 minutes
>> (2^31 uSec), and a hypothetical compiler that only used 30 bit integers
>> (as per the standard) would get under 10 minutes.  It is a bit tricky to
>> write general-purpose libraries with this.
> Isn't it just a
> waitLong :: Integer ->  IO ()
> waitLong n =
>     let stdDelay = 10^7
>         (q,r) = divMod n stdDelay
>     in  replicateM_ (fromInteger q) (threadDelay (fromInteger stdDelay))
>          >>  threadDelay (fromInteger r)
True, but:

1: Low level stuff like this belongs in the library, not the 
application.  I'm writing Haskell, not C!

2: I actually want to use timeout, which inherits the same limitation.  
Right now it looks like the simplest thing to do would be to copy the 
existing timeout code but use "waitLong" instead of "wait".  But I 
shouldn't have to do that.


More information about the Libraries mailing list