Skip to content

Instantly share code, notes, and snippets.

@zakky-dev
Created October 24, 2014 07:50
Show Gist options
  • Save zakky-dev/05babf53bd417a9b9708 to your computer and use it in GitHub Desktop.
Save zakky-dev/05babf53bd417a9b9708 to your computer and use it in GitHub Desktop.
変換後のコンピュテーション式を覗いてみたところ、規則には出てこないはずのLetがでてきたので一応それを残しておく。
open System
open Quotations.Patterns
type Maybe<'a> = Nothing | Just of 'a
type MaybeBuilder () =
member __.Quote() = ()
member __.Run(x: Quotations.Expr<'a>) =
Console.WriteLine(x)
Just 42
member __.Zero() = Nothing
member __.Return(x) = Just x
member __.ReturnFrom(x) = x
member __.Bind(x, f) = match x with Just v -> f v | _ -> Nothing
member __.Using(x: #IDisposable, f) =
try
f x
finally
match x with
| null -> ()
| _ -> x.Dispose()
let maybe = MaybeBuilder()
let returnJust x = Just x
let returnNothing _ = Nothing
[<EntryPoint>]
let main argv =
maybe {
let! j = returnJust 10
return j
}
|> ignore
Console.ReadKey false |> ignore
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment