Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.org
- // See the 'F# Tutorial' project for more help.
- open System
- type Person = {
- name : String;
- age : int
- }
- let rec inputPerson () =
- printf "Name: "
- let name = Console.ReadLine()
- if String.IsNullOrEmpty(name) then
- List.Empty
- else
- printf "Age: "
- let canParse, age = Int32.TryParse(Console.ReadLine())
- if canParse then
- let person = {name = name; age = age}
- person :: inputPerson()
- else
- printfn "Could not parse age, ending input phase."
- List.Empty
- let formatPerson person =
- let statement = match person.age with
- | x when x >= 20 -> "is no longer a teenager."
- | x when x > 13 -> "is a tennager."
- | _ -> "is a kid."
- sprintf "%s %s" person.name statement
- [<EntryPoint>]
- let main argv =
- printfn "Input people. Input blank name or invalid age to end input phase."
- inputPerson() |> List.iter (fun x -> printfn "%s" (formatPerson x))
- Console.ReadKey() |> ignore
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement