I've been playing around with (WriterT [Int] IO), trying to get the log out and map `print` over it... and do it lazily. However, I'm not really happy with what I have so far, since I've had to resort to `unsafePerformIO`. Any hints are welcome.
What I have so far is:
foo = let
_tell i = do
a <- return $ unsafePerformIO $ sleep 1
tell [a + 1 `seq` i]
in do
mapM_ _tell [1..10]
main = do
(_, ~res) <- runWriterT foo
mapM_ print res
Without the `seq` the call to sleep will simply be skipped (is there an
easier way to force evaluation there?). Without `unsafePerformIO` all
the sleeping is done up front, and all numbers are print at once at the
end.
The goal is of course to use code along the same shape to do something
more useful, and then `unsafePerformIO` will really be unsafe...
/M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
