[Haskell-cafe] do

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Mon Oct 15 16:51:58 EDT 2007

On Oct 15, 2007, at 13:32 , Peter Verswyvelen wrote:

> jerzy.karczmarczuk at info.unicaen.fr wrote:
>>> Yes, *different approach*. So, there *are* differences.  
>>> Compilers, anyway,
>>> are special applications. I wanted to see - responding to Brandon  
>>> - a
>>> "normal" Haskell program, which does IO without monads, that't all.
>>> The problem is then when you hide something, you hide. It is  
>>> possible to
>>> superpose a kind of monadic framework on unique worlds, files,  
>>> etc. in
>>> Clean, but the reverse operation goes beyond my horizons.
>>> Some examples, anybody?
> Ah yes, I see what you mean now. I have no idea, I guess only  
> unsafePerformIO will allow you to do something like that... But  
> that will completely break referential transparency. But I really  
> don't know. What do the experts have to say?

Use the source of unsafePerformIO as an example of how to write code  
which passes around RealWorld explicitly, but without unencapsulating  
it like unsafePerformIO does.

The main problem here, I think, is that because all the GHC runtime's  
functions that interact with RealWorld (aside from unsafe*IO) are  
themselves only exported wrapped up in IO, you can't (as far as I  
know) get at the lower level internal (e.g.) putStrLn' :: RealWorld - 
 > String -> (# RealWorld,() #) to do I/O in a direct/explicit/non- 
monadic style.  In theory, one could export those and use them directly.

(Actually, as a practical matter, IIRC GHC "knows about" RealWorld  
and removes all of it when generating cmm code once it's done the job  
of sequencing Haskell evaluation; I'm not sure how well that would  
work if you wrote I/O in direct/explicit style.  unsafePerformIO  
doesn't really count for that because it removes the RealWorld itself.)

brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH

More information about the Haskell-Cafe mailing list