[Haskell] Re: Question for the haskell implementors: Arrays, unsafePerformIO, runST

Simon Marlow simonmarhaskell at gmail.com
Tue Feb 21 18:04:40 EST 2006


John Meacham wrote:
> On Tue, Feb 21, 2006 at 10:15:59AM +0000, Malcolm Wallace wrote:
> 
>>John Meacham <john at repetae.net> wrote:
>>
>>
>>>I generalized this primitive to 
>>>
>>>drop__ :: a -> b -> b
>>
>>Also known in the Prelude as "const"...
> 
> 
> well, 'flip const' but yes.
> 
> 
>>The difference is that you propose it be primitive, with the intention
>>that a clever compiler should not be able to bypass it by inlining its
>>definition and propagating the loss of the first argument outwards.
> 
> 
> sure, well whatever is required on a given compiler to ensure it has the
> above qualities, which might mean making it a primitive or have it have
> some compiler-specific pragmas attached.

Your drop__ reminds me of GHC's touch#, which is like drop__ in the IO 
monad.  We use it to control lifetimes, eg. inside withForeignPtr.  You 
could implement drop in terms of touch#:

    drop__ a b = case touch# a realworld# of s -> b

I'm not sure about the other way around.  Something like "touch# a s = 
drop__ (a,s) s" looks possible, but is wrong - the compiler can see the 
same s is returned.

touch# compiles to no code at all in GHC, which is what you want, but it 
does keep its argument alive as far as the GC is concerned - that 
behaviour isn't necessary (is undesirable?) for drop__.

Cheers,
	Simon


More information about the Haskell mailing list