(As always, standard disclaimers apply, use at your own risk, etc.)
open System // For query ReadKey only.
/// <summary>Query helper.</summary>
let rec internal GetQuery q =
printf "%s (y/n) " q
let key = Console.ReadKey().KeyChar
printfn ""
match key with
| 'y' | 'Y' -> Some()
| 'n' | 'N' -> None
| _ -> GetQuery q
let black = lazy ( GetQuery ("Is it a black?") )
let orange = lazy ( GetQuery ("Is it a orange?") )
let white = lazy ( GetQuery ("Is it a white?") )
let (|Black|_|) _ = black.Value
let (|Orange|_|) _ = orange.Value
let (|White|_|) _ = white.Value
let x a =
match a with
| Black & Orange -> a+" is a tiger."
| Black & White -> a+" is a zebra."
| _ -> a+" is a sasquatch."
let y a =
match a with
| Black & Orange -> a+" is a tiger."
| Black & White -> a+" is a zebra."
| _ -> a+" is a sasquatch."
printfn "%s" (x "Rover")
printfn "%s" (y "Rover")
Console.ReadLine() |> ignore
No comments:
Post a Comment