The design suggestion Result type has been implemented in F# 4.1. This RFC covers the detailed proposal for this suggestion.
- Approved in principle
- Details: under discussion
- Implementation: Completed
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 FSharp.Core
library
Type name | Success case | Failure case |
---|---|---|
Result | Ok | Error |
The standard range of testing considerations for F# library types apply.
Uncontentious:
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 Option
and Result
.
Suggested:
attempt : (unit -> 'a) -> Result<'a,exn>