3 ms·
This idea touches on (or rather, even expands on) an idea I've had brewing for a while. For those unfamiliar, there is a programming language called Unison [1]
by reggieband 5y ago
This idea touches on (or rather, even expands on) an idea I've had brewing for a while. For those unfamiliar, there is a programming language called Unison [1] that has a nice feature where each function is identified by a hash of its AST. I often thought a cluster environment, maybe something BEAM-ish, would be an interesting idea where functions are retrievable based on a pair of (`func-name`, `hash`). You could have some kind of execution environment (maybe a lightweight process) that receives a hash identifying the function to execute and some pointer to the data (probably a URL) to act as input.
Given tech like described in the linked article, you could reasonably lookup such a function from a peer-to-peer network.
1. https://www.unison-lang.org/ https://www.unison-lang.org/
- octoberfranklin 5y agoThis approach to mobile code in functional languages has been tried repeatedly since the 1990s. > each function is identified by a hash of its AST. That encoding for mobile code only works if the expression has no free variables (i.e. is closed). It turns out that it is surprisingly difficult to write code which you can be sure has no free variables at particular points (the "send this code to another machine for execution" points). Especially in functional languages. If you write a higher-order functional, you know nothing about the closedness of its argument. If you require that all function arguments be closed it breaks all the useful functional programming techniques. The only way to make it workable is to check closedness only on those values which need to be mobile. If you do the closedness-check at runtime, toy examples will work fine and the technique looks quite powerful, but once your codebase gets to a meaningful level of complexity it turns into a game of whack-a-mole with closedness heisenbugs. You quickly discover that closedness is data-dependent. In order to check closedness statically you need quite a sophisticated system of modal types. MetaOCaml was the most usable result of all this research: https://okmij.org/ftp/ML/MetaOCaml.html https://okmij.org/ftp/ML/MetaOCaml.html The important upshot here is that this isn't just some check you can slap onto the compiler. The programmer has to think about these types, and craft them carefully, as an integral part of the programming process. Basically you aren't just writing a program, you're writing a program plus a proof that it won't try to mobilize open code. Writing formal machine-checked proofs is not something that most programmers are good at.
- pharmakom 5y agoWould it be possible to copy any captured variables with the function? I’m sure smart people have figured out why this wouldn’t work.
- jlokier 5y agoIn pure functional programs it's possible to copy the state (monad/environment/free variables), but it's not always efficient, depending on what those are. In general programs, doesn't have to be functional, the environment is stateful and often has abstract, black box processes. This can be transferred as well, by copying some things, transforming others, and in general where necessary using a two-way pipe of some kind. By analogy, imagine creating a WebSocket at the same time as making a JSON-RPC call. Except for the black boxes, this kind of transfer can be taken further to make a general distributed system. Think things like Paxos, Raft, CRDTs. If the data is also mobile to where it is used, this performs well for many tasks. When that is done, in some ways everything comes back to messages and state again and doesn't need specific pipes. That's more robust then the simple form of transfer. The resulting architecture is often much faster than the non-distributed version for many tasks, and robust, but it takes a lot of tricky parts to make a general purpose architecture with those qualities and stay high performance.
- octoberfranklin 5y agoIt's not a question of efficiency. You can copy values but you can't copy unbound free variables.
- jlokier 5y ago> you can't copy unbound free variables. You can copy them in a pure functional program if the function AST you're transporting is sufficiently expressive, because the values of the unbound free variables in pure FP are available at the point where the function is defined, so can be inlined into it, and included in its hash. But when it's not pure FP, then indeed you can't copy the values into the function AST, because the environment at the point of each call to the function is what matters. (The pipe stuff is just for making it more efficient, and handling black boxes which sit outside the paradigm of concrete values, things like I/O monads and devices).