How to write function where argument is type but not typed value?
- by ssp
I want to convert a string representations of few dozen enum types to enum values.
It's easy to convert string to concrete type:
Enum.Parse(typeof<FontStyle>,"Bold") |> unbox<FontStyle>
but for now i want to write function where type and string are parameters.
The best one i can write is:
> let s2e (_: 'a) s = Enum.Parse(typeof<'a>,s) |> unbox<'a>;;
val s2e : 'a -> string -> 'a
> s2e FontStyle.Regular "Bold";;
val it : FontStyle = Bold
Is there any option to write something like this but with type itself as first argument?