-
Notifications
You must be signed in to change notification settings - Fork 833
Description
What
The following code snippet leads to the resulting error message: -
let rec foo() = async { return foo() }Type mismatch. Expecting a
'a
but given a
Async<'a>
The resulting type would be infinite when unifying ''a' and 'Async<'a>'
Why
99/100 times the cause is simply that the developer has forgotten to return! rather than return. The current error message is confusing, does not explain why the error has occurred and does not present the likely solution.
How
Suggest a rewording that follows Error / Explanation / Suggestion format: -
Type mismatch. Expecting a
'a
but given a
Async<'a>
You are attempting to recursively return the result of an asynchronous call which is not awaited. Have you forgotten to use 'return!' instead of 'return' ?
Perhaps someone could explain what an infinite type is as well - I have no idea, although I sort of understand why this error occurs... :-) As I don't, the "explanation" bit of this error needs reworking for sure. I know that common parlance is to use "Consider" but in this case it's a guess more than anything. I also don't like use of "await" but am not sure what the correct term is.