Result type
In functional programming, a result type is a Monadic type holding a returned value or an error code. They provide an elegant way of handling errors, without resorting to exception handling; when a function that may fail returns a result type, the programmer is forced to consider success or failure paths, before getting access to the expected result; this eliminates the possibility of an erroneous programmer assumption.
Examples
- In OCaml, it is defined by the standard library as
type ('a, 'b) result = Ok of 'a | Error of 'b type
. - In Rust, the standard library provides the
Result<T, E>
type to handle return values or error codes, expanding on the functionality of theOption<T>
type. - Haskell has a type that is sometimes used in a similar way, called
Either
, which is defined asdata Either a b = Left a | Right b
.
gollark: Deliver them unto me
gollark: I require the mods which have been added.
gollark: Too bad, bee them, they ARE to be subject to gender neutral pronouns in some cases.
gollark: * red
gollark: Why is it read?
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.