Can I get the type of a statically permitted type parameter?

Say I have something like this. It does not compile, but you can see what I'm trying to do. I tried every time in google, but without dice. It can be done?

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) 
+5
source share
1 answer

This works fine, and you can use typeof for statically permitted parameters - the problem is that the parser cannot deal with <^ , because it can also be parsed as an operator.

You can easily fix this by simply adding spaces around ^x :

 let t = typeof< ^x > 
+9
source

Source: https://habr.com/ru/post/1269845/


All Articles