[Haskell-cafe] Using unsafePerformIO safely

gladstein at gladstein.com gladstein at gladstein.com
Thu Jun 25 11:38:36 EDT 2009

Regarding how to make the show instructions cause printout as soon as
they are executed:

If you write your interpreter to return a list of printout lines
(strings), you get this behavior for free. Haskell's laziness enables
the printing to start right away, while in an imperative language the
list of strings wouldn't be returned until it was complete.

To see this in action, try this program:

main = mapM putStrLn myList

myList = ["first", "second", loop, "third"]

loop = loop 

Despite the infinite loop, "first" and "second" print out.

More information about the Haskell-Cafe mailing list