fork download
  1. import Data.IORef
  2.  
  3. runClosure f = mapM_ f [0..5]
  4.  
  5. main = do
  6. x <- newIORef (0, (+ 1))
  7. runClosure $ \i -> do
  8. (n,f) <- readIORef x
  9. print $ f n
  10. writeIORef x (f n, if i `mod` 2 == 0 then (+ 1) else (* 2))
Success #stdin #stdout 0.01s 3548KB
stdin
Standard input is empty
stdout
1
2
4
5
10
11