import Data.IORef
runClosure f
= mapM_ f
[0..5]
main = do
x <- newIORef (0, (+ 1))
runClosure $ \i -> do
(n,f) <- readIORef x
writeIORef x
(f n
, if i `
mod`
2 == 0 then (+ 1) else (* 2))
aW1wb3J0IERhdGEuSU9SZWYKCnJ1bkNsb3N1cmUgZiA9IG1hcE1fIGYgWzAuLjVdCgptYWluID0gZG8KICB4IDwtIG5ld0lPUmVmICgwLCAoKyAxKSkKICBydW5DbG9zdXJlICQgXGkgLT4gZG8KICAgIChuLGYpIDwtIHJlYWRJT1JlZiB4CiAgICBwcmludCAkIGYgbgogICAgd3JpdGVJT1JlZiB4IChmIG4sIGlmIGkgYG1vZGAgMiA9PSAwIHRoZW4gKCsgMSkgZWxzZSAoKiAyKSk=