3 ms·
IMO algebraic data types pretty much solve everything that exceptions try to solve. while also encoding into the type system that it can fail/what failure mode
by Akronymus 5y ago
IMO algebraic data types pretty much solve everything that exceptions try to solve.
while also encoding into the type system that it can fail/what failure modes there are, while also forcing you to handle it locally.
- barrkel 5y agoLocal handling is, of course, an anti-pattern in code using exceptions, and not to be encouraged. It's rare that you handle exceptions; normally, you just abort what you're doing and unwind. If you have an API which fails often enough that you want to handle exceptions from it, it probably shouldn't use exceptions, and use some kind of conditional result or ADT equivalent instead. A concrete example would be the TryParse methods in .NET.
- Akronymus 5y agoI think that it is much better to return an adt with "common exceptional cases" and reserve exceptions for the truly exceptional ones. For example, a lost network connection shouldn't be one, but a put of memory one makes sense. Local handling was meant in terms of locally seeing pitential errors