Created
January 4, 2016 21:10
-
-
Save hodzanassredin/ef306c8267f616b89ffb to your computer and use it in GitHub Desktop.
fsharp free monad proto
This file contains hidden or 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
// Learn more about F# at http://fsharp.net | |
// See the 'F# Tutorial' project for more help. | |
type Prj<'a> = Async<Option<'a>> | |
type ProjectBuilder() = | |
member this.Bind(x, f) = | |
async{ | |
let! x = x | |
match x with | |
| Some(x) -> return! f(x) | |
| _ -> return None | |
} | |
member this.Return(x) = async.Return(Some x) | |
let proj = ProjectBuilder() | |
let op () = async.Return(Some(1)) | |
[<EntryPoint>] | |
let main argv = | |
let r = proj{ | |
let! a = op() | |
return a | |
} | |
printfn "%A" <| Async.RunSynchronously r | |
0 // return an integer exit code | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment