allowing non-sequentiality in IO

Hal Daume III hdaume@ISI.EDU
Sat, 16 Feb 2002 09:37:32 -0800 (PST)


In general, when working in the IO monad, it guarentees that the order of
operations is the same as how it's specified.  For instance:

main = 
  do putStrLn "hi"
     putStrLn "bye"

could not possibly output "bye" before "hi".

What if I don't care about this?  Is there any way to tell the compiler
that it is free to reorder these?

The reason I ask is that I'm generating a FSM description file and it
doesn't matter which order I list the transitions in.  I'm curious whether
I could get the program to run any faster if I don't care about order.

The only thing I can think of would be to define a new nonsequential IO
monad that basically used unsafePerformIO to do the computations.  So it
would basically transform the above from to:

main = 
  unsafePerformIO (putStrLn "hi") `seq`
  unsafePerformIO (putStrLn "bye")

and then order wouldn't be guarentee, right?

 - Hal

Hal Daume III

 "Computer science is no more about computers    |
  than astronomy is about telescopes." -Dijkstra |