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 8637937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:35:54+00:00 2026-06-12T10:35:54+00:00

let “one“ x = One(x) type Number = | One of int | Two

  • 0
let ``one`` x = One(x)
type Number = 
| One of int
| Two
with 
    member this.Hi x = ``one`` x

Basically, I want to define a let binding that references a discriminated union, and I want to use it in one of the extensions to that union, because I know you can’t define let bindings inside unions for some strange reason. The double ticks are for emphasis.

Actually, what I want is to make a sort of concise constructor for members of the union. I understand discriminated unions can’t have constructors, but is there a way to do this, perhaps without using a let binding as above?

  • 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-06-12T10:35:56+00:00Added an answer on June 12, 2026 at 10:35 am

    You can use type extensions to define the type, then write a number of let bindings (top-level or in a module) and then add member declaration to the type:

    type Number =  
      | One of int
      | Two 
    
    let one x = One(x) 
    
    type Number with
      member this.Hi x = one x 
    

    If you write this in a single file, then this is an intrinsic type extension, which means that the code will be compiled as a standard type with members (and the members will be directly usable from C#). If you added the extension in another file, then that would be different (more like C# extension methods).

    For F# class declarations, you can also use local let bindings inside the class (before declaring members), but sadly this is not supported for discriminated unions.

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

Sidebar

Related Questions

Let's say that I've got a sheet - number one - with over 5000
Let's say I have two text files that I need to extract data out
Let say I want to create an iOS app that download music files from
Let say I've this URL: http://example.com/image-title/987654/ I want to insert download to the part
Let assume we have two activities. A - main activity, that is home launcher
Let's assume I want to deserialize this (I've removed the namespaces to make things
Let me be more specific..What i want to do is that when i click
Let's say that I have 2 lines like this. Some Label: First element Second
Let's say I have five integer values that must all be unique. int a;
Let's say I don't have photoshop, but I want to make pattern files (.pat)

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.