Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
Created January 4, 2016 21:10
Show Gist options
  • Save hodzanassredin/ef306c8267f616b89ffb to your computer and use it in GitHub Desktop.
Save hodzanassredin/ef306c8267f616b89ffb to your computer and use it in GitHub Desktop.
fsharp free monad proto
// 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