Josef Sveningsson wrote:
> 1.
> Wy isn't there any documentation on how to write programs so that they can
> be optimized using the foldr/build rule. What I'm after is the lists of
> good listconsumers and -producers. I believe they belong in the chapter
> "Advice on: sooner, faster, smaller, stingier" in the documentation.
There is a very simple reason: ghc doesn't perform foldr/build optimisation.
The source still contains many parts dealing with foldr/build, but the main
part, `MagicUFs.lhs' is commented out. As Simon Peyton Jones once told me via
email, there are several problems in practise, especially with cross-module
optimisation.
(I'm not sure if any official release of ghc ever performed foldr/build
optimisation)
However, I have developed an improved foldr/build optimisation (I submitted a
paper about it to ICFP). I'm currently working on a little stand-alone
prototype. It uses data structures similar to ghc and when it works
satisfactorily I want to add the transformation to GHC. I'm still thinking about
the best way to attack the cross-module problems.
> 2.
> Now that the typesystem is expressive enough, wouldn't it be nice to
> expose build to the programmer? I would find it really neat to be able to
> construct my own functions that can be optimized with the foldr/build
> rule. The prelude is ofcourse often enough but sometimes it's not and
> being able to use build then would not only improve performance but would
> also be good programming style in my opinion.
Actually I don't think using build would be good programming style. Its only
purpose is to enable the foldr/build transformation. It doesn't abstract any
recursion pattern as foldr does.
My new method doesn't require build anymore (only foldr) ;-)
Cheers,
Olaf
--
OLAF CHITIL, Lehrstuhl fuer Informatik II, RWTH Aachen, 52056 Aachen, Germany
Tel: (+49/0)241/80-21212; Fax: (+49/0)241/8888-217
URL: http://www-i2.informatik.rwth-aachen.de/~chitil/