Hi,
After reading
this article about workflows, I tried to implement something similar myself.
I came up with the following code:
type 'a Script = (unit -> 'a)
let runScript (a: 'a Script) = a()
let delay f = fun () -> runScript (f ())
type ScriptBuilder() =
member b.Return(x) =
printfn "Return (%A)" x
fun() -> x
member b.Let(p, rest) : 'a Script =
printfn "Let (%A)" p
rest p
member b.Bind(p, rest) : 'a Script =
printfn "Bind (%A)" p
rest p
member b.Delay(f) =
printfn "Delay"
delay f
let script = new ScriptBuilder()
However, when I run this snippet:
let num = script { let x = 2
let! y = 21
return x * y }
runScript num |> ignore
I don't see "Let (2)" printed. It's like if ScriptBuilder.Let never gets called.
Does anyone understand why? I'm using F# CTP 1.9.6.0
Thanks a lot for your help!
EDIT: I have tried several other monads and Builder.Let is never called (?!)