
On Jun 26, 2009, at 00:43 , Hector Guilarte wrote:
Thanks! Actually, if I understood well what you proposed, that's how I first tought of doing it, but with a [Maybe String] and only append whenever I actually had a (Just string), but as I said before, I don't think my teacher is gonna like that solution since it is not going to print when the interpreter finds the show instruction in the GCL code, it is gonna wait until it finishes
I think maybe you don't quite have a grasp of lazy evaluation yet. Try it.
Also, nobody has told me why I shouldn't just use my original solution using unsafePerformIO, is it really bad? is it dangerous? why is it "unsafe"?
You were told earlier:
Well, writing to the standard output is certainly a side effect. (This does not mean that you cannot use unsafePerformIO. The compiler, however, may assume that any value is free from side effects. This means that you could get, in theory, less or more output from your program than you want. In this sense it is not "safe".)
Because pure (i.e. non-IO) values by definition never change, the compiler is free to assume that it can do them exactly once and remember the result. This means that it is possible for the compiler to evaluate your unsafePerformIO once and never again... or, more likely, to notice that the pure result is always () (because unsafePerformIO "hides" the IO from the compiler) and optimize it away completely (the "do it exactly once" being at compile time instead of run time). -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH