I'm using the below bit of code
// Neat method of finding the TryParse method for any type that supports it.
// See https://stackoverflow.com/a/33161245/158285
let inline tryParseWithDefault (defaultVal:'a) text : ^a when ^a : (static member TryParse : string * ^a byref -> bool) =
let r = ref defaultVal
if (^a : (static member TryParse: string * ^a byref -> bool) (text, &r.contents))
then !r
else defaultVal
but I notice that the type constraint
^a : (static member TryParse : string * ^a byref -> bool
is used twice. Is there any way to do the following
constraint Parsable a = ( a : ^a : (static member TryParse : string * ^a byref -> bool)
and use Parsable like
// Neat method of finding the TryParse method for any type that supports it.
// See https://stackoverflow.com/a/33161245/158285
let inline tryParseWithDefault (defaultVal:'a) text : Parsable =
let r = ref defaultVal
if (^a : (Parsable) (text, &r.contents))
then !r
else defaultVal