Created
February 23, 2014 19:54
-
-
Save andybrackley/9176410 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Maybe Monad *) | |
(* | |
Taken from FSharpX: | |
https://github.com/fsprojects/fsharpx/blob/master/src/FSharpx.Core/ComputationExpressions/Monad.fs | |
*) | |
type MaybeBuilder() = | |
member this.Return(x) = Some x | |
member this.ReturnFrom(m: 'T option) = m | |
member this.Zero() = None | |
member this.Bind(m, f) = Option.bind f m | |
let maybe = MaybeBuilder() | |
let res = | |
maybe { | |
let! x1 = Some(10) // maybe.Bind(Some(10), fun a -> | |
let! x2 = None // maybe.Bind(None, fun b -> | |
return! Some(x1 + x2) // a + b Using Option | |
} | |
printf "%A" res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment