[Haskell-cafe] Functions with side-effects?
daniel.carrera at zmsl.com
Wed Dec 21 10:24:29 EST 2005
Creighton Hogg wrote:
> x is a String, getLine has type IO String. That's what I
> was getting at in one of my last e-mails.
Hmm... let's see if I understand:
* getLine() has type IO String.
* The <- will "convert" an IO String to a plain String
* So if I do x <- getLine() then x has the type String.
So, the <- effectively ammounts to an IO a -> a conversion.
In another email John Hughes said that one could think of "IO a" as a
set of instructins for obtaining a. I guess that means that IO is a sort
of imperative layer that helps the purely functional code interact with
the outside world.
So I can have an IO bit (e.g. a do-block) that calls functions (which
are purely functional code) but I can't have a function that executes
For example, it is not possible to write a function "my_read_file" that
could work like this:
my_data = my_read_file("my_file.txt")
Correct? Otherwise this would be a function that is not referentially
\/_/ I am not over-weight, I am under-tall.
More information about the Haskell-Cafe