Hacker News new | ask | show | jobs
by ovis 2098 days ago
It's interesting that I could write your last sentence, but replacing "exceptions" with "monadic error handling."

Ultimately, both are equally expressive and it's reasonable to personally prefer either. The "Result" type approach maps better to the concept of a program as a series of inputs and outputs (functions).

1 comments

Rust doesn't have "monadic error handling" as it doesn't have monads. Haskell has monads and syntax for managing them, so when you declare a type like Result (which is not a monad as merely a data structure) you hide it as a monad (wherein you implement the Monad trait and define how the Result type propagates errors) and then it just becomes part of the usage of do notation in the language (like any other monad). If Rust has gone with monadic error handling I would have been elated, but it didn't: it went for manual, but required, error checking, which was a bit ridiculous in the 2010s and the opposite of monads (which I would argue exceptions are much closer to: they are effectively a hardcoded implementation of Monad for an implicit type wrapper of every function result and a do notation you can't opt out of).