[Haskell] Real life examples

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Wed Nov 24 20:22:04 EST 2004


John Meacham wrote:

 >On Wed, Nov 24, 2004 at 10:40:41PM +0000, Ben Rudiak-Gould wrote:
 >
 >>If the unsafePerformIO hack doesn't work in your new Haskell
 >>compiler, you can replace it with some other magic that does work. It's
 >>fine for the Haskell environment to hide impure magic behind a pure
 >>interface -- that's what the language is all about.
 >
 >That is exactly the problem we are trying to solve. coming up with a
 >sane 'magic' which interacts well with all the semantics and program
 >transforms we expect to be valid in a functional setting.

Ah ha. I see the source of confusion.

I want the interface of George Russell's library to be /the/ way of 
creating top-level TWIs in Haskell, on which everything else is based, 
just as the various standard IO actions are /the/ way of doing I/O. I'm 
treating the implementation of his library as below the line, in the 
same category as GHC's internal state-threading implementation of IO. 
Yes, it needs special compiler support, but that support doesn't need to 
be standardized and doesn't need to be general.

As such, the implementation doesn't need unsafePerformIO or NOINLINE, it 
only needs primReadRef1#, primWriteRef1#, primReadRef2#, and 
primWriteRef2#, which read and write the exactly two process-global refs 
supported natively by the runtime system. (Two because his 
implementation happens to use two global IORefs, but of course that 
could be reduced to one.) Everyone else who wants global IORefs gets 
them through the high-level interface built on those two primitive ones.

You are treating the implementation of his library as above the line, 
and proposing a different primitive with which it can be implemented. 
Nothing wrong with that, but I claim it's not /necessary/, because his 
library alone is enough.

-- Ben

P.S. I'm getting tired of calling it "George Russell's library" -- can 
anyone suggest a better name?



More information about the Haskell mailing list