4 ms·
Although it means something different and is not the the actual semantic opposite, I've found the syntactically opposite phrase "Functional shell, imperative co
by dwohnitmok 8y ago
Although it means something different and is not the the actual semantic opposite, I've found the syntactically opposite phrase "Functional shell, imperative core" also useful, which the speaker alludes to when he talks about local variable rebinding that is invisible to the outside.
That is locally scoped, mutation-heavy, imperative code is fine as long as you can wrap it in a deterministic, immutable interface for general use. This is the premise behind things like Haskell's ST type. More generally it's the usual way FP languages try to recover competitive performance.
- taeric 8y agoIt is also how your computer does basic addition. It isn't like there is such a thing as immutable numbers when it gets to the silicon. Look at how a barrel shifter is implemented someday, or a comparator.
- branislav 8y agoIt's also how something like React.js works. Wrapping stateful DOM manipulation in a functional shell, made performant thanks to the Virtual DOM diffing algorithm.
- JBiserkov 8y ago>locally scoped, mutation-heavy, imperative code is fine as long as you can wrap it in a deterministic, immutable interface for general use. Yes! Clojure supports this via transients. What's even better is that you can write the loop using immutable data, make sure it works. Then just 1. add a call to transient in the initializations, 2. add a call to persistent! in the end and 3. add a ! to each function that modifies the transient, e.g. conj becomes conj! The benefit in doing it this way is that the language will catch and flag as errors any "mixed" usage - calling a pure function with a mutable argument or vice-versa. https://clojure.org/reference/transients https://clojure.org/reference/transients http://www.hypirion.com/musings/understanding-clojure-transients http://www.hypirion.com/musings/understanding-clojure-transi...