As discussed above, it also depends on your application domain. Writing compilers, and having tried both the result monad and exceptions, I ultimately chose the latter because:
- an error will anyway result in the program termination so I may as well fail fast and not bother tainting my types with
result - using the result monad means your coworkers (who may not be fluent in monadic programming) will also have to undergo this choice (and curse you); besides OCaml doesn’t feature a “standard” monad library and sometimes you may need to write things for which functions such as
liftMormapMmay be needed (worse: you may have to compose with other monads).
Now, I am still not very happy with relying on untracked exception…
Besides my main problem is that I think we lack a discussion on design principles here. A discussion that does not reduce to choosing between exceptions and the result monad. There are several other aspects that, IMO, should be discussed too (and that could be implemented with any technology). E.g.:
- defensive programming vs fail fast
- error recovery (see what Eiffel proposed for instance)
- more concretely: when should you use
invalid_argvsassertvs …