I think the likely answer is that many templates do not make sense. For example, how do you expect the compiler to process the following code?
type DisposablePair = DisposablePair of IDisposable * IDisposable let f disposablePair = use (DisposablePair(x,y)) = disposablePair ()
Your strange error message is probably due to the fact that even if you used let
binding, you need to bind (Resource d)
and not Resource(d)
(the compiler thinks you are declaring a new function).
For what it's worth, I find the inability to use the underscore pattern as sometimes annoying (especially when working with IDisposable
instances that exist only to delimit areas, such as System.Transactions.TransactionScope
). One way to generalize use
bindings to handle underscores and several other situations is to require the right side of the use
binding to be IDisposable
, but to allow any pattern on the left side, so that:
use p = v in e
will syntactically translate to something like
let ((p:System.IDisposable) as d) = v in try e finally d.Dispose()
source share