このコード:
type Result = Success of string
type Tracer() =
member x.Bind(p: Result, rest: (string -> Result)) =
match p with
| Success s -> rest s
let tracer = new Tracer()
let t = tracer {
let! x = Success "yes!"
let! y = Success "waste of time"
return! Success x
}
printfn "%A" t
印刷成功 "はい!"
ただし、動作しないことを意味する警告が表示されます。
File1.fs(19,3): 警告 FS0708: この制御構造は、計算式ビルダーが 'ReturnFrom' メソッドを定義している場合にのみ使用できます
奇妙な警告のように思えます: もしそれが正しければ、コードは動作しないはずです。ビルダーが ReturnFrom を合成しなければならなかったと言っているだけですか?
(F# バージョン 1.9.7.4、.NET Framework バージョン v4.0.21006 用にコンパイル)