Created
December 7, 2015 20:50
-
-
Save ygrenzinger/070cba1fc50249ed33c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
type Person = { | |
Name : string | |
Age : int | |
} | |
let deal (person: Person) = | |
match person with | |
| { Person.Name = name; Person.Age = age } when age >= 20 -> printfn "%s is adult." name | |
| { Person.Name = name; Person.Age = age } when age > 13 && age < 20 -> printfn "%s is a teenage." name | |
| { Person.Name = name; Person.Age = age } when age < 13 -> printfn "%s is a kid." name | |
| { Person.Name = name; Person.Age = _ } -> printfn "I don't know if %s is ET." name | |
let rec inputAge () : int = | |
Console.WriteLine("Please input age") | |
let couldParse, age = Int32.TryParse(Console.ReadLine()) | |
if couldParse then age | |
else inputAge() | |
let canInput () = | |
Console.WriteLine("Continue Input? Y or N?") | |
if Console.ReadLine() = "Y" then true | |
else false | |
[<EntryPoint>] | |
let main args = | |
let mutable list : Person List = [] | |
while canInput() do | |
Console.WriteLine("Please input name") | |
let name = Console.ReadLine() | |
let age = inputAge() | |
list <- { Name = name; Age = age } :: list | |
List.iter(deal) list | |
Console.ReadKey() | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment