I use F # v 1.9.6.2, and I defined a very simple calculation expression:
type MaybeBuilder() =
member this.Let(x, f) =
printfn "this.Let: %A" x
this.Bind(Some x, f)
member this.Bind(x, f) =
printfn "this.Bind: %A" x
match x with
| Some(x) when x >= 0 && x <= 100 -> f(x)
| _ -> None
member this.Delay(f) = f()
member this.Return(x) = Some x
let maybe = MaybeBuilder()
I put some print statements in the code to indicate which methods are called in the expression. When I execute the following statement:
maybe {
let x = 12
let! y = Some 11
let! z = Some 30
return x + y + z
}
I expect the console to print the following:
this.Let 12
this.Bind Some 12
this.Bind Some 11
this.Bind Some 30
But my actual results are as follows:
this.Bind: Some 11
this.Bind: Some 30
In other words, F # does not execute an element Let. When I rewrite Letto throw an exception, the code runs without exception. Also, when I fully comment on an element Let, I do not receive an error message with a message The field, constructor or member 'Let' is not defined, and the code runs as expected.
( Reflector, , , F # .)
, spec . Let , Let ?