3 ms·
ErrorT is similar to EitherT, so I just used the latter to make the names less confusing. Either doesn't have to be "stringly typed" per se thanks to sum types
by tikhonj 14y ago
ErrorT is similar to EitherT, so I just used the latter to make the names less confusing.
Either doesn't have to be "stringly typed" per se thanks to sum types. You can write a type like:
data ErrorType = SomeError
| OtherError String
| ...
The compiler can now check that you handle all possible errors and will give you a warning if you don't, so it's strictly better than using strings.
Coincidentally, this is one place where some sort of sub-typing would be nice, I think. This sort of type would be perfect using OCaml's polymorphic variants because then you could share different error cases around while specifying a very specific type for each computation.