F# RFC FS-1004 - Result type
The design suggestion Result type has been implemented in F# 4.1. This RFC covers the detailed proposal for this suggestion.
In order to be able to write code that you can easily consume that does not throw an exception it's useful to have a fsharp type who contains the result on success or the error on failure
type Result<'TSuccess,'TError> = | Success of 'TSuccess | Error of 'TError
The type should be added in
|Type name||Success case||Failure case|
The standard range of testing considerations for F# library types apply.
Proposal for additional functions
bind : ('T -> Result<'U, 'TError>) -> Result<'T, 'TError> -> Result<'U, 'TError> map : ('T -> 'U) -> Result<'T, 'TError> -> Result<'U, 'TError> mapError : ('TError -> 'U) -> Result<'T, 'TError> -> Result<'T, 'U>
A result builder should be a separate RFC which covers adding builders for both
attempt : (unit -> 'a) -> Result<'a,exn>