Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (34 sloc) 1.6 KB

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.

Discussion thread

Introduction

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

Naming

Type name Success case Failure case
Result Ok Error

Testing considerations

The standard range of testing considerations for F# library types apply.

Proposal for additional functions

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>