3 ms·
Good writeup. Haskell actually does have an Error type class and ErrorT monad transformer for more fine-grained error handling. Maybe gives you binary error ha
by tkahn6 14y ago
Good writeup. Haskell actually does have an Error type class and ErrorT monad transformer for more fine-grained error handling.
Maybe gives you binary error handling, it either fails (Nothing) or succeeds (Just).
Either gives you "stringly-typed" errors which is sometimes a good choice.
http://hackage.haskell.org/packages/archive/mtl/1.1.0.2/doc/html/Control-Monad-Error.html http://hackage.haskell.org/packages/archive/mtl/1.1.0.2/doc/...
- tikhonj 14y agoErrorT 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.