Q: Forcing repeated evaluation
Jan Kybic
kybic@ieee.org
12 Sep 2002 11:27:16 +0200
Hello,
I have another question regarding the optimisation of Haskell code:
I have a relatively inexpensive function generating a long list, imagine
something like (I simplified a lot):
l = [ i*i*i | i <- [0..n] ] -- for very large n
This long list is consumed several times in the program:
x1 = f1 l
x2 = f2 x1 l
x3 = f3 x2 l
I found that the list l is calculated just once and that the
computational time is dominated by the allocations and garbage
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
unsafePerformIO $ return l
do the job? Isn'it there any flag for the compiler (ghc) to suggest
this optimisation? Thank you for your feedback.
Jan
--
-------------------------------------------------------------------------
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