Picture an object-oriented procedural language like Java, and then make everything immutable; for every 'void' method, return an updated copy of 'this'; for every non-void function, return a tuple of the updated copy and the value you were going to return. No change to const methods, obviously. And you're done, and you can still take advantage of encapsulation, polymorphism, and inheritance without any hoops. You can even do it in Java itself as a style thing without too much effort and only a modest amount of boilerplate. Alternatively, it's not that much work to build this same thing out of lambdas and dictionaries, if your language has those but not objects (adding mutation into that object system would then be trivial) (and of course, you can build dictionaries out of lambdas and lambdas out of objects, if need be).
Re:Interview with Simon Peyton-Jones
by mgummelt on Thursday April 19, 2018 @11:47PM
(#16882029)
Sure, but mutability is orthogonal to OOP.
[ Parent
| on HN ]
As fond as I am of Erlang, I still find it hard to picture an immutable OO language.
> I still find it hard to picture an immutable OO language.
Write in scala using only "vals" and there you have it!