3 ms·
The code examples don't make any sense, the functions may return a error but they are not being checked for in the next function. Using thir own metaphor, their
by SkeuomorphicBee 4y ago
The code examples don't make any sense, the functions may return a error but they are not being checked for in the next function. Using thir own metaphor, their functions may deviate to the red rail, but then the next function just assume everything is always coming from a green rail, they don't codify the real possibility that the input is from the red rail.
For me it seems like a method that may work with the right language sugar, but without a sugar made specific for this you will have to pollute all functions with extra error handling to handle the possible red-rail-input. At this point it should be better to just handle those errors when they happen, and quit the happy path there, instead of following along the "happy path" just passing errors to all the following functions.
- gjm11 4y agoI got the impression that the author of the article didn't actually understand the idea they were writing about. It reads like blogspam whose real purpose is not to convey understanding but to contain advertisements for, in this case, LogRocket.
- robertlagrant 4y agoAgreed - the original content this is cribbing from[0] is really good. Worse CSS, though :) [0] https://fsharpforfunandprofit.com/rop https://fsharpforfunandprofit.com/rop
- xnorswap 4y agoYes, this article (the OP article that is) is horribly confusing and doesn't follow the ROP architecture at all. The core idea is that instead of a Func that takes in a Foo and returns a Bar, you can take in a Maybe<Foo> and return a Maybe<Bar>. Then you don't need error handling in the outer composition, once everything is of the form F = Maybe<T1> -> Maybe<T2>, etc, then you can fully compose everything at the outer layer into a F = Maybe<T1> -> Maybe<Tn>. So then you just check for Ok() at the very end and unwrap and handle any errors there.
- robertlagrant 4y agoYeah it makes loads of sense. Syntactic sugar required to make the medicine go down, of course :)