Edit: I wrote an elaboration, https://news.ycombinator.com/item?id=8877732
So yeah, that's how he would know about them. They're extremely common in two areas of his interest (Go discussion/criticisms, language design).
A+
It's not pretty (and not in broad adoption), but neither is it impossible.
Also it doesn't allow for the use of already defined functions to do the transformations, (e.g. `maybe.flatMap(existingFn).flatMap(otherFn)` wont ever work, new closures will have to be defined that do casts before calling the existing functions).
So basically, its just-as-error-prone and just-as-tedious as checking error codes but in a different way. Both benefits of the pattern are gone. Given this, I don't think that the word "impossible" is a stretch at all (not having any of the benefits of the pattern = not implementing the pattern)
You could use Either, but it doesn't give you any guarantee that you'll get a string back, and the naming is lousy. (Left and Right? Really? I know there's a mnemomic, but we can do better than that.)
So, might as write your own ADT and name it right.
(Also, a real error-reporting mechanism should support cause chaining so you can see the dependencies; you can sort of do it with string concatenation but it gets awkward after a few levels.)
1. It's better not to use strings and instead use a user defined error type. 2. What do you mean "doesn't give you any guarantee you'll get a string back"?
> real error-reporting mechanism should support cause chaining so you can see the dependencies;
Can you elaborate on cause chaining, perhaps with an example?
- Can't persist shopping cart
- RPC request failed: http://example.com/update_cart
- Can't write to database "carts"
- Can't save file: "/a/b/c"
- OS error: disk full
Ideally, all errors in the cause chain should be logged, and they typically cross abstraction boundaries; the message at each level comes from a different part of the stack. This seems hard to do across languages, but within a language there should be a standard way to do it.(Go falls down on this too. Perhaps we don't need Java-style stack traces that go on for multiple screens, but we should have more than a string.)
http://doc.rust-lang.org/std/result/enum.Result.html
> (Also, a real error-reporting mechanism should support cause chaining so you can see the dependencies; you can sort of do it with string concatenation but it gets awkward after a few levels.)
http://doc.rust-lang.org/std/error/trait.Error.html
Either isn't custom-built for error reporting, so it makes sense that its naming only conventionally matches.