[Haskell-cafe] guided seq (Was: Interruptible threads with IO loops)

Felipe Almeida Lessa felipe.lessa at gmail.com
Wed Dec 21 14:04:38 CET 2011


On Wed, Dec 21, 2011 at 7:31 AM, Joachim Breitner
<mail at 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.



More information about the Haskell-Cafe mailing list