Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6330503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:52:58+00:00 2026-05-24T17:52:58+00:00

I have an enumeration in F#, like this: type Creature = | SmallCreature =

  • 0

I have an enumeration in F#, like this:

type Creature =
   | SmallCreature = 0
   | MediumCreature = 1
   | GiantCreature = 2
   | HumongousCreature = 3
   | CreatureOfNondescriptSize = 4

I do not like manually typing out numbers, and I want to easily insert more items in the enumeration later without having to shift the numbers.

I tried this

type Creature =
   | SmallCreature
   | MediumCreature
   | GiantCreature
   | HumongousCreature
   | CreatureOfNondescriptSize

but it caused an 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 assigning number values to each item?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:52:59+00:00Added an answer on May 24, 2026 at 5:52 pm

    Unfortunately, you can’t. Are the numeric values important? If so, it somewhat escapes the intended use of enums (flags aside). You might consider a class or discriminated union in that case.

    Your second example is, in fact, a discriminated union. But your later use of EnumOfValue, which expects an enum, is causing the error.

    Another option is to store the enum to number mapping in a dictionary and replace the pattern matching with a dictionary lookup. Then, the numeric value of the enum would be irrelevant.

    I agree that manually managing enum values is burdensome. I hope it’s addressed in a future version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have registered an enumeration type ClefType within my header file - this enum
I have this serious problem. I have an enumeration within 2 namespaces like this:
I have an Application Delegate class with a enumeration which looks like this: typedef
I have a set of enumeration values that have 138 values. Something like: type
I have an enumeration like Enum Complexity { NotSoComplex, LittleComplex, Complex, VeryComplex } And
I have an enumeration for my Things like so: public enum Things { OneThing,
Does Perl have an enumeration type that adheres to best practices , or maybe
I have different kinds of enumerations in this flavour class Gender extends Enumeration {
I'm using Scala 2.8 and defining an Enumeration like this: object Stooges extends Enumeration
I have an enumeration which I'd like to persist as a value of some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.