3 ms·
> When you’re implementing a function, you are, in a sense, telling apply what to do with it – what code to execute. You’re implementing individual chunks of ap
by Twisol 6y ago
> When you’re implementing a function, you are, in a sense, telling apply what to do with it – what code to execute. You’re implementing individual chunks of apply. These chunks are usually scattered all over your program, sometimes anonymously in the form of lambdas.
I feel like this is a much deeper philosophical point worth pausing and pondering. (It's also very suggestive as to the whole point of defunctionalization -- nice foreshadowing!)
- mlazos 6y agoI’ll need to reread some of his posts, but I don’t find this particularly enlightening. Apply has always been pure variable substitution in my mind. From this point of view, of course apply is dependent on the code snippet you’re supplying, it’s the code that’s getting “modified” by the substitution.
- Twisol 6y agoThe point I took from it is that "apply" is normally given by your programming system, and its cases are spread out over your whole program. but there's no reason you can't build your own "apply" on your own function-like type. (The `Expr = Lit Int | Add Expr Expr` type is probably the best-known example.) Functions happen to be things that your PL provides natively. Defunctionalization is all about capturing a piece of the global `apply` for functions, and translating it into an `apply` on a custom data type.