4 ms·
Maybe is not an error-handling mechanism because it doesn't report any error message. I don't know why Haskell programmers think it's any good for reporting err
by skybrian 12y ago
Maybe is not an error-handling mechanism because it doesn't report any error message. I don't know why Haskell programmers think it's any good for reporting errors.
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.)
- deleted 12y ago[deleted]
- codygman 12y ago> You could use Either, but it doesn't give you any guarantee that you'll get a string back 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?
- skybrian 12y agoWhat I mean is something like a stack trace except without all the extra detail: - 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.)
- nbevans 12y agoMaybe is just an example. If you need to return more error codes, perhaps with contextual information such as message(s), then just define your own discriminated union and use that.
- masklinn 12y ago> So, might as write your own ADT and name it right. http://doc.rust-lang.org/std/result/enum.Result.html 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 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.