I have an enumeration in F #, for example:
type Creature = | SmallCreature = 0 | MediumCreature = 1 | GiantCreature = 2 | HumongousCreature = 3 | CreatureOfNondescriptSize = 4
I don’t like manually typing numbers, and I want to easily insert more elements into the enumeration later, without rearranging the numbers.
I tried this
type Creature = | SmallCreature | MediumCreature | GiantCreature | HumongousCreature | CreatureOfNondescriptSize
but this caused the error The type 'Creature' is not a CLI enum type later in the program
let input = Int32.Parse(Console.ReadLine()) let output = match EnumOfValue<int, Creature>(input) with // <---Error occurs here | Creature.SmallCreature -> "Rat" | Creature.MediumCreature -> "Dog" | Creature.GiantCreature -> "Elephant" | Creature.HumongousCreature -> "Whale" | Creature.CreatureOfNondescriptSize -> "Jon Skeet" | _ -> "Unacceptably Hideous Monstrosity" Console.WriteLine(output) Console.WriteLine() Console.WriteLine("Press any key to exit...") Console.Read() |> ignore
How can I define an enumeration without manually linking the values of the numbers to each element?
source share