I have not installed the new version yet, but I agree that this looks a little suspicious. I suppose this restriction may be a good reason, but your example in another question seems rather complicated.
As a workaround, I think adding a witness parameter (which is not used, but hints what type of result will be) might work:
let (|Value|_|) (witness:unit -> 'T) value : 'T option = match box value with | :? 'T as x -> Some x | _ -> None
Of course, this makes use a little ugly because you need to come up with some kind of argument. In the above example, I used a witness like unit -> 'T , hoping that the following could compile:
let witness () : 'T = failwith "!" match box 1 with | Value witness 1 -> printfn "one"
If this does not work, you can probably try using a witness parameter of type 'T (but then you must provide the actual function, not just the generic function).
Tomas petricek
source share