[Haskell-beginners] Re: clarification on IO

Will Ness will_n48 at yahoo.com
Sun Mar 1 21:28:18 EST 2009


Gregg Reynolds <dev <at> mobileink.com> writes:

> 
> 
>> On Sun, Mar 1, 2009 at 4:28 AM, Will Ness <will_n48 <at> yahoo.com> wrote:
>> 
>> 
>> Michael Easter <codetojoy <at> gmail.com> writes:
>> ...
>> It's just that _its value_ can cause the system to actually perform
>> these IO actions in some circumstances.
>> 
>> 
>> May be to call them "action functions"?
> 
> 
> This was a big problem for me; I find terms 
like "action", "computation", "function" completely misleading for IO 
terms/values.  You might find ["Computation" considered harmful. "Value" not so 
hot either] useful; see also the comment "Another try at the key sentence".  
There are a few other articles on the blog that address this terminology 
problem.


Have read it now. Didn't like the formulation in that comment though. It's 
mixing together issues of monad in general and IO in particular when it speaks 
of "side-effects" being attached "to a value". 

No value has side-effects in Haskell. There are no side effects in Haskell.

There are no values in Haskell either, only expressions denoting values. (1+
(1+1)) , (1+2), 3 - it's all the same, and nothing precludes Haskell 
implementation from actually exchanging one with another right away. 

Here's one possible sketch-out of IO monad to clarify what I mean:

data IO a = IORec -> (a,IORec) -- record of I/O activities to be performed

instance Monad IO where
  return a rec = (a,rec)              -- return :: a -> IO a
  (m »= g) rec = uncurry g $ m rec    -- g      :: a -> IO b

putStrLn :: a -> IO ()
putStrLn a rec = ((),rec ++ [("putStrLn", a)]) 


Thus it is all just pure Haskell, building a record of I/O requests that can 
get executed "on the outside" by the run-time system. Being defined once, it 
can be run several times, or none at all.

This is exactly like your idea on that log you mentioned about separating the 
pure Haskell world and the "outer" impure world of I/O - or IOW, pure 
compiler's world and run-time system.




More information about the Beginners mailing list