I’ve been looking for answer for this question and found this blog post. It says that fail has advantages over error because it isn’t constrained to the IO monad.
Should i use fail instead of error all over my code? Does fail raise Control.Exception.catchable exceptions in IO?
EDIT: I’ve found an update for the link above.
Here’s my advice:
If you’re in
IOcode already, use proper exceptions viathrowIOfromControl.Exception.If your code uses a monad stack already, add errors to your monad stack if it doesn’t support it already, and use those.
If you are in non-monadic code, write total functions. I.e., avoid
errorand incomplete patterns if you can. Usingfailhere would only force your code to be unnecessarily monadic. If you need exceptional results, use a proper data type (such asMaybeorEitheror a custom datatype).