比如我有这样的一段代码, 它不能编译,但你可以看到我的意图。我试过各种搜索方式,但都没有找到答案。这个能做到吗?
let inline read (s:string) : ^x =
let parsed = (^x : (static member ofString: string -> ^x option) (s))
// this is the bit I'm not sure how do to. This doesn't compile.
// I'm trying to determine what the statically chosen type for ^x is.
let t = typeof<^x>
match parsed with
| Some y -> y
| None -> failwithf "can't parse %s into %s" s (t.Name)