3 ms·
Why not upgrade the compiler to detect the algebraic implementation and optimize it to the buffer implementation?
by oakwhiz 13y ago
Why not upgrade the compiler to detect the algebraic implementation and optimize it to the buffer implementation?
- cliffbean 13y agoBecause 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!
- tikhonj 13y agoIt 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-stream-fusion http://stackoverflow.com/questions/578063/what-is-haskells-s... [2]: http://www.haskell.org/ghc/docs/7.0.1/html/users_guide/rewrite-rules.html http://www.haskell.org/ghc/docs/7.0.1/html/users_guide/rewri...
- lmm 13y agoObvious 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?