News for hackers. Stuff that matters.
Re:Functional core, imperative shell (2012) by dwohnitmok on Friday September 21, 2018 @07:57PM (#18043583)
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.

Re:Functional core, imperative shell (2012) by JBiserkov on Saturday September 22, 2018 @05:03AM (#18045182)
>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

http://www.hypirion.com/musings/understanding-clojure-transi...

Re:Functional core, imperative shell (2012) by taeric on Friday September 21, 2018 @08:01PM (#18043606)
It 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.
Re:Functional core, imperative shell (2012) by branislav on Saturday September 22, 2018 @02:08AM (#18044739)
It'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.