
Neil Mitchell wrote:
Hi
I agree with Bulat that Haskell has, if anything, even better optimisation potential than something like C. With Haskell you can do the crazy high-level optimisations that things like C would demand really advanced alias-analysis. Compare this to low-level optimisations which in Haskell require strictness analysis but in C are easy. At some point high-level will become more important than low-level, when it does, we win :-)
I had this conversation where Mr C++ basically said that my code implements 3 loops and it's "not possible" to optimise that into just 1 loop like the C program is doing. Then I (or rather, Don) demonstrated that the stream fusion library *has* optimised it into just 2 loops. (Apparently the library isn't 100% complete as yet.) I liken transformations like this to the sort of high-level optimisations that a database engine might do given an SQL statement. An SQL SELECT certainly *looks* just like a loop construct. But it isn't; it declares the result, not the algorithm, freeing the database to use *any* algorithm that produces the right answer. The result is that, as is well known, databases are supremely good at executing SQL queries blisteringly fast. When I see the compiler turn 3 loops into 2 by using algebraic properties of the program source code, that's how I think of it. Hmm, perhaps to really show this off, we need a more complicated program. Something that would be just too hard to implement as 1 loop in C, but is easy for the GHC optimiser to build. I shall meditate on this further...