2 ms·
The union approach fails when, say, barError is the type of a success return somewhere. Sum types (as in Rust, for example) avoid this problem.
by amluto 3y ago
The union approach fails when, say, barError is the type of a success return somewhere. Sum types (as in Rust, for example) avoid this problem.
- valenterry 3y agoWell, yes and no. What you say also applies if two errors have the same type but you want to differentiate where it comes from. In all these cases you can wrap the result or error into something, which essentially means tagging it (but without actually needing sumtypes as a language concept. Sumtypes sure are useful, but I believe that except for GADTs, you can emulate sumtypes with uniontypes, but not vice versa.