Created
October 24, 2014 07:50
-
-
Save zakky-dev/05babf53bd417a9b9708 to your computer and use it in GitHub Desktop.
変換後のコンピュテーション式を覗いてみたところ、規則には出てこないはずのLetがでてきたので一応それを残しておく。
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
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