3 ms·
It basically comes down to nondeterminism. Pure functional languages supposedly make it easier to exploit associativity, commutativity, and distributivity to al
by User23 4y ago
It basically comes down to nondeterminism. Pure functional languages supposedly make it easier to exploit associativity, commutativity, and distributivity to allow many expressions to have nondeterministic semantics that are amenable to concurrent execution. Argument evaluation also can be specified nondeterministic so the runtime is free to execute something like the following with two or more CPU threads:
f(g(), h())
Of course a well designed imperative language could also avoid overspecifying deterministic semantics and open itself up to similar optimizations, but for various reasons that hasn’t caught on. One example would be specifying the conditional to select a branch with a true guard nondeterministically rather than deterministically in the order of appearance in the program text. Dijkstra’s EWDs give many practical examples of why one might want such a thing.
Another example would be deducing when statement composition is symmetric and allowing nondeterminism when it is. For example if f and g don’t have access to each other’s data then the following can be executed in two threads even with mutation:
f(); g()
Side effects will appear nondeterministically though which may or may not be a problem. As always an algorithm needs to be designed for the semantics the language has not those the programmer wishes it does.
- alexisread 4y agoThis makes a good case for effect systems in conjunction with FP, so they can be reasoned about as well. Something like https://koka-lang.github.io/koka/doc/index.html https://koka-lang.github.io/koka/doc/index.html Having said that, having something like Daedelus in there as well would give a handle on temporal-based determinism, and then some allowance for delimited continuations would top things off nicely.