3 ms·
We do have data hiding in functional programming, even if we would not have modules, which we do, we do have type classes, and for example in OCaml you can hide
by danielscrubs 6y ago
We do have data hiding in functional programming, even if we would not have modules, which we do, we do have type classes, and for example in OCaml you can hide constructors if that's your jam.
It's not like when I use a sorting function that the implementors couldn't swap it out for a caching one or a parallel one.
One of the amazing things I remember is changing an int to a float in a very well used "struct" that was touching thousands of functions but because the functions in Haskell usually so extremely general I didn't have to change a single other line (Number type is heavily used and doesn't incur an extra performance cost, which it very much does in Java).
In fact we can be even more precise or loose in what assumptions need to be made via dependent types in functional programming languages like Agda.
I encourage you to take a look at any popular Haskell-framework to see how it's done in practice.