[Haskell-cafe] Functions with side-effects?

Bulat Ziganshin bulatz at HotPOP.com
Thu Dec 22 17:22:59 EST 2005

Hello Daniel,

Wednesday, December 21, 2005, 6:24:29 PM, you wrote:

DC> So I can have an IO bit (e.g. a do-block) that calls functions (which
DC> are purely functional code) but I can't have a function that executes 
DC> any IO.

it's true

DC> For example, it is not possible to write a function "my_read_file" that 
DC> could work like this:

DC> my_data = my_read_file("my_file.txt")

DC> Correct? Otherwise this would be a function that is not referentially 
DC> transparent.

you are right. type "IO a", after all, stands for "RealWorld ->
(a,RealWorld)", i.e. it gets RealWorld as parameter and returns,
besides value of type "a", a new RealWorld state. the function which
type don't ended with "IO a", just can't receive or return value of
type RealWorld, so there is just no way to check something outside or
return new state of the outer world

Best regards,
 Bulat                            mailto:bulatz at HotPOP.com

More information about the Haskell-Cafe mailing list