In F#, is it possible to have a tryParse function that infers the target type
问题 Presently we do this... let parseDate defaultVal text = match DateTime.TryParse s with | true, d -> d | _ -> defaultVal Is it possible to do this... let d : DateTime = tryParse DateTime.MinValue "2015.05.01" 回答1: Yes. Welcome to the world of member constraints, ref, and byref values. let inline tryParseWithDefault defaultVal 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