On Wed, Dec 21, 2011 at 7:31 AM, Joachim Breitner <m...@joachim-breitner.de> wrote: > this problem comes up in various places; forcing the whole thunk is of > course an option, but would it be possible – theoretical, with the GHC > runtime, or even with current tools – to have a function > evaluateUntilItDoesNotNeed :: a -> b -> a > such that > f x `evaluateUntilItDoesNotNeed` x > will not retain a reference to x, but is otherwise as lazy as possible? > > If thunks retain references to their free variables, and these can be > introspected, then it should be possible to keep seq’ing those thunks > that refer to x, until the expression is either fully evaluated or no > referenced thunk references x.
Sounds complicated. What about map f xs `evaluateUntilItDoesNotNeed` xs If it evaluated only the head of 'map f xs' then the result would not depend on 'xs' anymore, but it would depend on the tail of 'xs'. Cheers, -- Felipe. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe