How to write function where argument is type but not typed value?

Posted by ssp on Stack Overflow See other posts from Stack Overflow or by ssp
Published on 2010-03-16T13:16:22Z Indexed on 2010/03/16 13:46 UTC
Read the original article Hit count: 187

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about F#

Related posts about types