78 points · by perihelions · 3y ago · 14 comments
Closures are just functions with an extra parameter for the environment (free variables). Subsequent passes after desugaring can treat them like any other function.
Function composition and currying should also be static transformations. Maybe you made it harder than it has to be?
Implementing these things is maybe easy for you ;) but for myself, doing it well, I would definitely not describe as a walk in the park
My main objection to the grand parent is the idea that functional languages are 10x more difficult to implement than mainstream languages. Maybe that is true for Haskell, but most functional features can be compiled efficiently without much additional complexity. The complexity added by closures for instance would be closer to 1% than 10x.
I wonder what is a zero overhead abstraction. For instance closures are expensive (they malloc), but to what extent can we consider closures to be malloc'd structs; then potentially do away with the concept of structs -- because they've become a subset of the functionality provided by closures. At that point can we not consider closures as zero cost; because malloc of structs is essential to c, and with optimization we need be no more expensive
And to what extent does that hold true for every other feature? In some sense it is maybe always true
[0] http://www.mlton.org/guide/20130715/References.attachments/C... ("Flow-Directed Closure Conversion for Typed Languages")
``` Today: we are able to certify realistic bytecode compilers and abstract machines.
Tomorrow: certification of optimizing native-code compilers? ```
Xavier Leroy actually got the ACM Software System Award in 2021 for CompCert, an optimizing native-code compiler! It's first version seems to have been released in 2005, just 3 years after this presentation was written. Though CompCert is a C compiler, which isn't really a functional language.
- https://en.wikipedia.org/wiki/ACM_Software_System_Award - https://en.wikipedia.org/wiki/CompCert