
Excerpts from C.M.Brown's message of Sat Sep 06 16:43:23 +0200 2008:
Nicolas,
OK, let's restrict the word side-effect to printing on the screen as the only side-effect possible.
Some recalls:
Example:
putStrLn is a side-effecting function expecting *2* arguments, the first one is the string to print, and the second one is the world state. So if you could give to arguments to putStrLn you could make a side-effect, however you don't have a value of type RealWorld.
Is this clear?
Yes! Thanks for giving such a clear and insightful explanation. I guess I forgot about the IO being an abstraction for something else. So can I clarify that it's the runtime system that triggers the side-effect, and not Haskell?
Right.
I have one last question that is still confusing me: what if I have a function that reads something from a file, say, and does something depending on that input - would that be a side-effect?
Reading is treated like writing, but it's a little more complicated to understand because it rely on binding part of (>>=), the first one was sequencing (as in (>>)). Example with getLine getLine >>= \name -> putStrLn ("Hello " ++ name ++ "!") getLine have type IO String, so it's a function that waits for *1* argument. (>>=) in the case of IO is a function that expect *3* arguments: the first is computation that produce something, the second is a function that tell what to do with the result (a kind of continuation), and the third argument is again the RealWorld value.
Consider something modifying a file outside of the Haskell world that changes a program's behaviour. Am I right in thinking that the side-effect happens at runtime - but in Haskell, the funtion is still pure.
Yes
I feel, also, that as a reasonably experienced Haskell user, I am getting confused with what should be fundamental Haskell concepts. Perhaps these concepts should be made much clearer to beginners in the first instance.
This article [1] seems a good introduction. Maybe one could sum-up what you think is missing from this article and extend it a bit. For instance one could explain the point about the run-time system. [1]: http://www.haskell.org/haskellwiki/Introduction_to_IO -- Nicolas Pouillard aka Ertai