I just recently came across this paper (with the same title as this blog post), and just had to post it and say “wow”. The idea of the paper is pretty simple, actually, for Haskell at least- see, the advantage of purely functional code is that it doesn’t matter when it actually gets executed. Haskell’s lazy evaluation enforces this (the “hair shirt” that SPJ talks about). Purely functional code can run at any time- including compilation time. So why not? Hoist as much code as is resonable and precompute it at compile time. Everything that isn’t directly dependent upon I/O is a possible target. Which means that large chunks, even a majority, of Haskell programs are potiential targets for this optimization.
Now this work is obviously in the early stages, and is yet to be proven out on real world code. And there are a lot of open questions left- like what are good heuristics for when it’s profitable to apply this optimization? But it’s an example of the sorts of large scale programmatic rewrites which are possible with Haskell, but difficult bordering on impossible even with Ocaml, let alone C++ or Java. There’s a whole realm of compiler optimizations out there which hasn’t been explored- because with normal languages the optimizations are just too hard to implement, and so likely to not be applicable in the majority of cases, diluting the effectiveness of the optimization. But the structure of Haskell makes it easy to apply to large parts of the code (“is it using the I/O monad? No? Good, we can precompute it”), and easy to implement.
No related posts.
Pingback: Enfranchised Mind » Supero Followup
Pingback: Upped The Recent Post/Popular Post Widget Count | Enfranchised Mind