
Gregg Reynolds wrote:
Donn Cave wrote:
Quoth Gregg Reynolds wrote:
Look again at the sentence you trimmed off the end:
Of course, the point is that this result is an *IO action* of type IO Int, it's not the Int you would get "when executing this action".
I believe that more or less points to the key to this discussion. If it didn't make sense to you, or didn't seem relevant to the question of pure functions, then it would be worth while to think more about it.
Ok, let's parse it out. "…it's not the int you would get 'when executing this action". Close, but no cooky: it's not any kind of int at all (try doing arithmetic with it). "IO Int" is a piece of rhetoric for the mental convenience of the user; Haskell does not and cannot know what the result of an IO action is, because it's outside the scope of the language (and computation). (The "Int" part of "IO Int" refers to the input, not the output; it's just a sort of type annotation.) It's not even a computation, unless you want to take a broad view and include oracles, interaction, etc. in your definition of computation.
Why would IO Int be something special or mysterious? It's an ordinary value like everything else; it's on the same footing as [Char], Maybe Int, Int -> String, Bool, and so on. I see no difference between the list [1,2,3] :: [Int] and the action "pick a random number between 1 and 6" :: IO Int . Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com