Given the following code:
type MyDU =
| B of bool
| I of int
| S of string
type Ops () =
static member myFn<'T> x =
let v =
match x with
| B b -> box b
| I i -> box i
| S s -> box s
match v with
| :? 'T as y -> Some y
| _ -> None
... the following produce error FS0717: Unexpected type arguments
:
I 7 |> Ops.myFn<int>
Ops.myFn<int> <| I 7
However, this works just fine:
Ops.myFn<int> (I 7)
Also, I get no errors if I define myFn
in a module:
let myFn<'T> x =
let v =
match x with
| B b -> box b
| I i -> box i
| S s -> box s
match v with
| :? 'T as y -> Some y
| _ -> None
I 7 |> myFn<int> // Works fine
Explanation?