F# Basic Tutorial
F# Useful Resources
Selected Reading
- F# - Namespaces
- F# - Modules
- F# - Events
- F# - Interfaces
- F# - Inheritance
- F# - Operator Overloading
- F# - Structures
- F# - Classes
- F# - Exception Handling
- F# - Pattern Matching
- F# - Enumerations
- F# - Delegates
- F# - Generics
- F# - Basic I/O
- F# - Mutable Dictionary
- F# - Mutable Lists
- F# - Arrays
- F# - Mutable Data
- F# - Discriminated Unions
- F# - Maps
- F# - Sets
- F# - Sequences
- F# - Lists
- F# - Records
- F# - Tuples
- F# - Options
- F# - Strings
- F# - Functions
- F# - Loops
- F# - Decision Making
- F# - Operators
- F# - Variables
- F# - Data Types
- F# - Basic Syntax
- F# - Program Structure
- F# - Environment Setup
- F# - Overview
- F# - Home
F# Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
F# - Enumerations
F# - Enumerations
An enumeration is a set of named integer constants.
In F#, enumerations, also known as enums, are integral types where labels are assigned to a subset of the values. You can use them in place of pterals to make code more readable and maintainable.
Declaring Enumerations
The general syntax for declaring an enumeration is −
type enum-name = | value1 = integer-pteral1 | value2 = integer-pteral2 ...
The following example demonstrates the use of enumerations −
Example
// Declaration of an enumeration. type Days = | Sun = 0 | Mon = 1 | Tues = 2 | Wed = 3 | Thurs = 4 | Fri = 5 | Sat = 6 // Use of an enumeration. let weekend1 : Days = Days.Sat let weekend2 : Days = Days.Sun let weekDay1 : Days = Days.Mon printfn "Monday: %A" weekDay1 printfn "Saturday: %A" weekend1 printfn "Sunday: %A" weekend2
When you compile and execute the program, it yields the following output −
Monday: Mon Saturday: Sat Sunday: SunAdvertisements