A let! nested in a simple let binding is currently not allowed by the compiler.
Example:
let y() =
task {
let a =
let! b = System.IO.File.ReadAllLinesAsync("")
b
return a
}
The 4th line produces error FS0750: This construct may only be used within computation expressions.
(Except for SDK 10.0, where the let! is silently compiled as a simple let, see #19456.)
I believe this behavior is a bug and the above example should compile correctly.
The spec, as quoted here, prescribes the following transformations:
{{ let binding in cexpr }} => let binding in {{ cexpr }} and
{{ let! pattern = expr in cexpr }} => builder.Bind(expr, (fun pattern -> {{ cexpr }}))
It seems that applying them to the example code is straightforward and should lead to correct compilation of the CE rather than to an error message.
A
let!nested in a simpleletbinding is currently not allowed by the compiler.Example:
The 4th line produces
error FS0750: This construct may only be used within computation expressions.(Except for SDK 10.0, where the
let!is silently compiled as a simplelet, see #19456.)I believe this behavior is a bug and the above example should compile correctly.
The spec, as quoted here, prescribes the following transformations:
{{ let binding in cexpr }}=>let binding in {{ cexpr }}and{{ let! pattern = expr in cexpr }}=>builder.Bind(expr, (fun pattern -> {{ cexpr }}))It seems that applying them to the example code is straightforward and should lead to correct compilation of the CE rather than to an error message.