News for hackers. Stuff that matters.
Re:Railway-oriented programming by jerf on Friday June 13, 2014 @09:18AM (#7888634)
"1. The "success, but..." scenario. Sometimes you have different types of failures to handle and this style conflates all of them into "failure"."

No, it doesn't. I'm not sure where you get that, because even in this example "Failure" carries an error message. That's a string for didactic purposes, it can be anything you need it to be.

"2. There are different way to fail. There are cases in which you really should not go on with any computation, there are cases in which can go on, just note that you are in "danger" mode (ENOSPC)."

Here is where avoiding the word "monad" probably does not play to the author's favor. Monadic computations are able to examine the results of computations, so nothing stops you from

     case somethingThatMayFail arg1 arg2 of
         Right x -> do
             ... -- carry on the computation
         Left x -> -- fail out however you're going to fail
Which I believe also handles the rest of your questions... the pattern conveniently propagates errors when you don't want to treat them specially, but you can still dig in and examine them if you need to. Whatever you want to do, you can do, because it's just a program like anything else. For 3, the answer is "just write it the way you want it"... there isn't really an "answer" because that's not a problem in the first place, any more than it would be in C. And for 4, again, just do that then. Nothing's stopping you.

There are no comments on this comment yet.