According to the spec, a use binding requires an identifier (unlike let) instead of a pattern. Why is this? Here’s an example of a scenario that doesn’t work.
type Disposable = Resource of IDisposable
let f disposable =
use (Resource d) = disposable //ERROR: 'use' bindings must be of the form 'use <var> = <expr>'
()
I think the likely answer is that lots of patterns don’t make sense. For instance, how would you expect the compiler to handle the following code?
Your weird error message is probably due to the fact that even if you were using a
letbinding, you’d need to bind(Resource d)rather thanResource(d)(the compiler thinks you’re declaring a new function).For what it’s worth, I do find the inability to use an underscore pattern to be an annoyance at times (particularly when dealing with
IDisposableinstances that exist only to demarcate scopes, likeSystem.Transactions.TransactionScope). One way to generalizeusebindings to handle underscores and a few other situations would be to require the right hand side of ausebinding to be anIDisposablebut to allow any pattern on the left hand side, so that:would syntactically translate to something like