3 ms·
> But your solution cannot fix the conceptual lack of clarity that follows from the decision of the API designer to return both error information and data for f
by catnaroek 10y ago
> But your solution cannot fix the conceptual lack of clarity that follows from the decision of the API designer to return both error information and data for further processing from the same function call.
Why is it unclear? If the API supports using a reader after an error happens, the types have to reflect just that. It's not the kind of API I would design, but it's what you asked for.
> It's not a formal problem.
The inability to express your intention in a mechanically enforceable way is very much a formal problem.
- fauigerzigerk 10y agoIt is unclear because it violates the expectations people have about the result of functions: It's either an error or data for further processing, but never both. A language that uses sum types (whithout any further guarantees) for error handling cannot formally enforce that invariant. What I called pragmatic was that we may not want that sort of formal guarantee because we may sometimes want to trade conceptual clarity for efficiency.
- catnaroek 10y ago> A language that uses sum types (whithout any further guarantees) for error handling cannot formally enforce that invariant. Huh? The invariant is enforceable: type result = | Success of result_you_want | Error of error_info You just need to be consistent about what you want. First you ask for returning partial successful results alongside error information, then you ask for the exact opposite. You can make a typeful model of lots of things, but first you need to make up your mind. > trade conceptual clarity for efficiency. Could you describe where exactly the efficiency gain comes from? If indirection is the problem, well, if anything, the Go approach requires more indirection.
- fauigerzigerk 10y ago>The invariant is enforceable No, what you are showing is how an API designer could enforce a particular API design decision. That's fine, but what I'm talking about is how a language designer could enforce the invariants of a particular error handling concept. I think that sum types alone are not sufficient to do that. But I have to say I really don't like your tone. I'm not asking for one thing and then the exact opposite. I'm simply discussing pros and cons and I'm thinking about the consequences of different designs. I'll make my mind up when I feel I know enough the subject to do so. If that offends you, then I suggest you talk to someone else.
- catnaroek 10y ago> No, what you are showing is how an API designer could enforce a particular API design decision. That's fine, but what I'm talking about is how a language designer could enforce the invariants of a particular error handling concept. I think that sum types alone are not sufficient to do that. Different APIs have different ways to handle errors. The language designer's job is to allow the programmer to express his intention in the most precise way possible.