It is encapsulation with the mandatory law stating that an encapsulation of an encapsulation must be as deep as a single encapsulation.
Note that this informal statement doesn't necessarily mean you have to be encapsulating data. A behavior, a contract, an assertion, compositions of all of these etc can also be encapsulated.
Fun ideas (not necessarily true but fun to think about):
* Monads kinda convert nesting to concatenations.
* A monad is the leakiest of the abstractions. You are always a single level of indirection away from the deepest entity encapsulated within.
* What's common among brackets, curly braces and paranthesises(?) is them being monadic if you remove them from their final construction while keeping the commas or semicolons.
Very important note: You should have already stopped reading by now if you got angry to due these false analogies.
Remember, `bind` only unwraps one layer. Without it unwrapping one layer, programs would continue accumulating large stacks of monads in monads.
I would also point out that it only collapses abstractions of the same kind; Maybe's bind only unwraps one layer of Maybe's. If you have a Promise<Maybe<Foo>> where Foo contains potentially more monads as instance-variables, those don't all get collapsed.
I like the 'converting nesting to concatenating' observation.
Sometimes we do need parentheses though, because most languages are not associative 5 - 2 - 1 is not the same as 5 - (2 - 1). Basically minus does not form a monoid, so the parens matter.
Any references that explain the "converts nesting to concatenation" idea? I find it fascinating, in particular because I write a lot of code that works on deeply nested data structures -- structs of values (which can be structs) or lists of values. The distinction between struct, list and value and the need to treat them differently in code is interesting and annoying, and goes beyond merely working with functors and applicables. I don't understand lenses at all, but I understand monads.
Note that this informal statement doesn't necessarily mean you have to be encapsulating data. A behavior, a contract, an assertion, compositions of all of these etc can also be encapsulated.
Fun ideas (not necessarily true but fun to think about):
* Monads kinda convert nesting to concatenations.
* A monad is the leakiest of the abstractions. You are always a single level of indirection away from the deepest entity encapsulated within.
* What's common among brackets, curly braces and paranthesises(?) is them being monadic if you remove them from their final construction while keeping the commas or semicolons.
Very important note: You should have already stopped reading by now if you got angry to due these false analogies.