Description
Unlike a normal let
binding, the let!
binding requires parentheses when it has a type annotation. It would be better if this special syntax were not required. It does not seem to be covered in the language specification. Also documentation for let!
could be more easily discoverable (e.g., by linking to it from https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/functions/let-bindings). If the syntax cannot be improved, then perhaps at least the error message could suggest a possible fix and/or a codefix could be added to fix it.
Without the parentheses, it yields a compile-time error:
error FS0010: Unexpected symbol ':' in expression
Repro steps
open System.IO
let stream = File.Open("filename", FileMode.Open)
let bufferSize = 64
// let just stores the result as an asynchronous operation.
let result1 : Async<byte[]> = stream.AsyncRead(bufferSize)
// let! completes the asynchronous operation and returns the data.
let! result2 : byte[] = stream.AsyncRead(bufferSize)
Changing the last line like this fixes it:
let! (result2 : byte[]) = stream.AsyncRead(bufferSize)
Metadata
Metadata
Assignees
Type
Projects
Status