Q: Forcing repeated evaluation

Jan Kybic kybic@ieee.org
17 Sep 2002 21:38:11 +0200


> > > collection. I want to try to force l to be generated on-the-fly
> > > every time it is needed, to see if it improves performance.
> > > What is a good way to do it? Would something like
> > >
> ...
> > The easiest way is to make it a function
> >
> > l _ = [ i*i*i | i <- [0..n] ]   -- for very large n
>
> 
> I asked a similar question a while ago, and (I think) there was general
> agreement that this was not a reliable solution because the expression

I found a solution which works in some cases. For example:

reeval f x = do xref <- newIORef x
		x' <- readIORef xref
		return (f x')

Then the IO action "reeval f x"
should reevalue f each time it is invoked. Is this safe? Will this work
in all cases?

Thanks for any comments.



-- 
-------------------------------------------------------------------------
Jan Kybic <kybic@ieee.org>      Odyssee, INRIA, Sophia-Antipolis, France
       or <Jan.Kybic@sophia.inria.fr>,tel. work +33 492 38 7589, fax 7845
             http://www-sop.inria.fr/odyssee/team/Jan.Kybic/index.en.html