It actually does this in a bunch of cases; see Haskell's stream fusion[1] and rewrite rules in general[2] for examples.
However, there aren't any rewrite rules for list-based code, at least with the standard library. Rewrite rules are generally used for libraries designed explicitly with performance in mind like Vector and Bytestring; the standard String type and the Prelude don't fall into this category.
Obvious follow-up question: why does cabal not use more performance-oriented libraries? Does it have to avoid depending on anything because it's the dependency manager?
Because if it's a common pattern, then it's nice to put it in a common library anyway, instead of having everyone write it out by hand. It makes the code cleaner and more efficient. Win win!
Comments
Why not upgrade the compiler to detect the algebraic implementation and optimize it to the buffer implementation?
It actually does this in a bunch of cases; see Haskell's stream fusion[1] and rewrite rules in general[2] for examples.
However, there aren't any rewrite rules for list-based code, at least with the standard library. Rewrite rules are generally used for libraries designed explicitly with performance in mind like Vector and Bytestring; the standard String type and the Prelude don't fall into this category.
[1]: http://stackoverflow.com/questions/578063/what-is-haskells-s...
[2]: http://www.haskell.org/ghc/docs/7.0.1/html/users_guide/rewri...
Obvious follow-up question: why does cabal not use more performance-oriented libraries? Does it have to avoid depending on anything because it's the dependency manager?
Because if it's a common pattern, then it's nice to put it in a common library anyway, instead of having everyone write it out by hand. It makes the code cleaner and more efficient. Win win!