Re:Monads as a Programming Pattern
by Double_Cast on Monday August 12, 2019 @06:46PM
(#20680899)
The value of monads is that they fold side-effects into the return values.
If C++ were pure, the type-signatures would look like
The drawback is that the type-signature of function_b(function_a()) becomes complex. Now, function_b needs to accept and pass-on the upstream side-effects. To compose function_a and function_b, we need to convert the type-signature of function_b to
Fortunately, ">>=" converts function_b under the hood. Which allows us to write
and pretend that each ">>=" is just a ";" without wrestling with compound inputs and compound returns.
[ Parent
| on HN ]
There are no comments on this comment yet.