Skip to content

Instantly share code, notes, and snippets.

@otf
Created July 6, 2011 13:55
Show Gist options
  • Save otf/1067279 to your computer and use it in GitHub Desktop.
Save otf/1067279 to your computer and use it in GitHub Desktop.
let inline readValue< ^T when ^T : (static member TryParse : string -> bool * ^T)> name =
let rec readValue() =
seq {
printf"input %s: " name
let str = Console.ReadLine ()
let success, value = (^T: (static member TryParse : string -> bool * ^T) str)
(* TryParse <- このTryParseを型パラメータの型のスタティックメソッドとして呼び出したい *)
if success
then yield value
else yield! readValue()
}
readValue() |> Seq.head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment