Way Along towards F# Introductory Article

Today, in this article we will try to create a very simple F# program whose work is to identify person's age details.When the user specifies some age, it should display the type of category that the person belongs to.

The Complete Code for this Application looks like this:

open System

 

let (|Teenage|Younger|) n = if n >= 1 && n < 8  then Teenage else Younger;

let (|Younger|MidAge|) n = if n >= 8  && n < 18  then Younger else MidAge;

let (|MidAge|Older|) n = if n >= 18  && n < 35  then MidAge else Older;

let (|Older|SeniorCitizen|) n = if  n > 65  then SeniorCitizen else Older;

                             

let Simple n =

   match n with

   | Teenage -> printfn "This Person's Age is : %d is Teenage \n" n

   | Younger -> printfn "This Person's Age is : %d is Younger \n" n

   | MidAge -> printfn "This Person's Age is : %d is MidAge \n" n

   | Older -> printfn "This Person's Age is : %d is Older \n" n

   | SeniorCitizen -> printfn "This Person's Age is: %d is Senior Citizen \n" n

  

Console.WriteLine("The List of Person's Details are as Follows: \n")

 

Simple 1

Simple 3

Simple 8

Simple 6

Simple 9

Simple 15

Simple 25

Simple 37

Simple 70

 

Console.ReadKey(true)}


The Output for this Application looks like this:

pic1.gif

 

I hope this article is useful for you. I look forward for your comments and feedback.

MVC Corporation
MVC Corporation is consulting and IT services based company.