System.Timeout inoperative with Data.IORef
I would like to write some code that gathers as many answers as possible within a certain time period. Seems like System.Timeout is what I need, but it doesn't appear to work when the IO monad only uses IORefs rather than read/write calls. The documentation doesn't mention anything about System.Timeout having this limitation.
I would guess that there needs to be some way for IO operations to check for timeouts, even if they don't register a file descriptor with the IO manager.
Here's some sample code that highlights the problem:
import Data.IORef import System.Timeout
fib:: Int -> Int fib 0 = 0 fib 1 = 1 fib n = fib (n - 1) + fib (n - 2)
runFibs accum i = do
let v = fib i modifyIORef accum (\l -> (i,v):l) --putStrLn $ show (i, v) -- add this back, and it works runFibs accum (i+1)
main = do
accum <- newIORef [] timeout 10000 (runFibs accum 1) rv <- readIORef accum putStrLn $ show rv
Trac metadata
Trac field | Value |
---|---|
Version | 7.0.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Runtime System |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |