Enumerations

Category:
Defining Types
Description: Enums are lightweight types, similar to discriminated unions. Unlike discriminated unions, each data tag must be given a constant value of the same type
Code:
type FaceCard =
| Jack = 11
| Queen = 12
| King = 13
| Ace = 1

let EnumSample() =
let isAce card =
match card with
| FaceCard.Ace -> true
| _ -> false

printfn "Checking if a Jack is an Ace.....%A" (isAce FaceCard.Jack)

Execution Result:
Checking if a Jack is an Ace.....false

Last edited Sep 14, 2011 at 2:36 AM by ttliu2000, version 1

Comments

No comments yet.