I personally don't use functional languages because I find them too difficult given the needs and interests I have. I think about computations sequentially most of the time.
I personally don't use functional languages because I find them too difficult given the needs and interests I have. I think about computations sequentially most of the time.
int ret = doStepOne();
if (ret == RESULT_OK) {
ret = doStepTwo();
}
if (ret == RESULT_OK) {
ret = doStepThree();
}
return ret;
would just be doStepOne() >>= doStepTwo() >>= doStepThree()
in a language with support for monads.[1] https://dilbert.com/search_results?terms=Random+Number+Gener... [2] https://xkcd.com/221/
This is also true for other things in other paradigms, such as async functions in javascript.
This is a good thing, however. In imperative programming, you have invisible temporal coupling. In pure-FP you have the same coupling, but it's exposed.
Then again, there are lots of monads, such as `Maybe` and `List`, where you can get values out. These aren't contagious at all.
I agree with you that this is a good thing. Effects show up in the type signature - and it's all about those effects and managing them.