3 ms·
GHC does have special support for fusion and rewriting. See e.g. [1]. The laziness comes with the language, but turning it efficient requires a series of these
by reikonomusha 6y ago
GHC does have special support for fusion and rewriting. See e.g. [1]. The laziness comes with the language, but turning it efficient requires a series of these rewrite rules expressed as GHC-specific metadata.
[1] https://markkarpov.com/tutorial/ghc-optimization-and-fusion.html#rewrite-rules https://markkarpov.com/tutorial/ghc-optimization-and-fusion....
- sukilot 6y agoGHC is the most complicated compiler of any language (or very near to it), except perhaps Mathematica which is similar: It's an optimizer for a graph-reduction engine. It doesn't mean much to call out "special support" for any one bit of style of programming, since the language itself has nearly no concept of performance -- you just write functional code and the compiler will find the fastest runtime computation of the evaluation that it can.
- eru 6y ago> It doesn't mean much to call out "special support" for any one bit of style of programming, since the language itself has nearly no concept of performance -- you just write functional code and the compiler will find the fastest runtime computation of the evaluation that it can. While GHC is glorious, it's still very limited in what it can do, performance wise. You are right that languages themselves seldom have a direct concept of performance. But language features and restrictions have a big impact on achievable performance. Eg Haskell's purity-by-default means that the compiler has quite a bit of freedom when choosing how to translate something like eg the 'map' or 'filter' functions. The equivalent in C++ gives the compiler less flexibility, because the helper function handed over at runtime might have side-effects. Similarly, Haskell functions are still allowed one important side effect: non-determination. In a more restricted language like Agda that's not allowed. Thus giving the compiler more degrees of freedom to work with. Or in a different direction: the query optimizers for SQL can do very impressive work, because SQL is so limited.
- dan-robertson 6y agoI was referring to the RULES pragma. My argument was that it is a general mechanism and not a built in understanding of list functions in the compiler. I suppose I ought not conflate the with Haskell but approximately everyone uses ghc.