[Haskell] Re: Question for the haskell implementors: Arrays,
john at repetae.net
Tue Feb 21 19:50:54 EST 2006
On Tue, Feb 21, 2006 at 11:04:40PM +0000, Simon Marlow wrote:
> 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
Ah, cool. there isn't an optimization that can determine that b is
passed through unchanged is there? some sort of core level points-to
analysis for instance.
> 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.
Also, drop__ completly disapears when grin is first generated from jhc
core and more grin-level optimizations are done that could loose the
fact a should exist at least as long as s. some sort of grin-level
primitive for touch# would be needed in jhc (or some sort of explicit
region annotations? I have not thought enough about those).
> 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__.
I would think undesirable. simply because there is no need and one of
drop__s uses is to fine-tune memory management. though, I don't think it
makes a big difference in the examples I gave.
I think perhaps drop__ might be useful enough to standardize on, if not
in haskell' then perhaps as a common convention between ghc and jhc
because it solves a couple issues that have come up on the list before
in a way that is more lightweight than hypothetical PRAGMAs.
I am not attached to the name drop__ BTW, double underscores at the end
of a name in jhc are equivalent in intent to # at the end in ghc, it
just means "this might be special in some way" but if we were to have a
common name, it should be something more descriptive. perhaps `dependingOn` ?
> dependingOn :: a -> b -> a
> dependingOn = flip drop__
> f x = ... where
> y = foo (z `dependingOn` x)
John Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell