Learning to Program with F# (Vol.2)

Here’s the main driver of the program:

open Helpers

[EntryPoint]
let main _ =

    let name =      nameRetrieval()
    let ethnicity = ethnicityRetrieval()

    displayInfo name ethnicity
    exit()

Here’s the implementation details:

module Helpers

open System

let nameRetrieval() =
    Console.WriteLine("Enter your name\n\n")
    Console.ReadLine()

let ethnicityRetrieval() =
    Console.WriteLine("\n\nEnter your ethnicity")
    Console.ReadLine()

let startsWithVowel (word:string) =
    
    let isVowel (charater:char) = 

        let value = charater.ToString().ToLower()

        match value with
        | "a" | "e" | "i" | "o" | "u" -> true
        | _                           -> false

    word.Chars(0) |> isVowel
    
let modifier (ethnicity:string) =
    if (ethnicity.Length >= 3 && ethnicity.Contains(" ") && ethnicity |> startsWithVowel)
    then "an "
    else ""

let displayInfo name ethnicity =
    printfn "\n\nHello %s\n\nYou are %s%s" name (modifier ethnicity) ethnicity

let exit() =
    let _ = Console.ReadKey()
    0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: