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

  • Home
  • SEARCH
  • 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 6980271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:59:39+00:00 2026-05-27T17:59:39+00:00

Items in tuples don’t have names, which means that you often don’t have a

  • 0

Items in tuples don’t have names, which means that you often don’t have a clear way to document the meanings of each item.

For instance, in this discriminated union:

type NetworkEvent =
| Message of string * string * string
| ...

I want to make it clear that the first and second items are the sender and recipient names respectively. Is it good practice to do something like this:

type SenderName = string
type RecipientName = string

type NetworkEvent =
| Message of SenderName * RecipientName * string
| ...

A lot of C/C++ libraries have a proliferation of types (e.g. win32.h), but in those languages, even though parameter names are optional in many cases, it can still be done. That isn’t the case with F#.

  • 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-27T17:59:40+00:00Added an answer on May 27, 2026 at 5:59 pm

    I think that using type aliases for documentation purposes is a good and simple way to document your discriminated unions. I use the same approach in many of my demos (see for example this one) and I know that some people use it in production applications too. I think there are two ways to make the definition more self-explanatory:

    Use type aliases: This way, you add some documentation that is visible in the IntelliSense, but it doesn’t propagate through the type system – when you used a value of the aliased type, the compiler will treat it as string, so you don’t see the additional documentation everywhere.

    Use single-case unions This is a pattern that has been used in some places of the F# compiler. It makes the information more visible than using type-aliases, because a type SenderName is actually a different type than string (on the other hand, this may have some small performance penalty):

    type SenderName = SenderName of string
    type RecipientName = RecipientName of string
    type NetworkElement =
      | Message of SenderName * RecipietName * string
    
    match netelem with
    | Message(SenderName sender, RecipientName recipiet, msg) -> ...
    

    Use records: This way, you explicitly define a record to carry the information of a union case. This is more syntactically verbose, but it probably adds the additional information in the most accessible way. You can still use pattern matching on records, or you can use dot notation to access elements. It is also easier to add new fields during the development:

    type MessageData = 
      { SenderName : string; RecipientName : string; Message : string }
    type NetworkEvent = 
      | Message of MessageData
    
    match netelem with
    | Message{ SenderName = sender; RecipientName = recipiet; Message = msg} -> ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of items, from which I want to select DISSIMILAR tuples
I have a list of approx. 10000 items. The current situation is that every
Trying to write function that numerize items of list and returns list of tuples
Suppose I have a set of tuples like this (each tuple will have 1,2
Suppose I have a set of tuples with people's names. I want to find
I have a list of 2-item tuples and I'd like to convert them to
I have a list of lists such as: [[1,2,3],[4,5,6],[7,8,9]] I'm trying to create tuples
Python: How to remove all duplicate items from a list Hey guys I have
I have a list of objects that I retrieved from a web service call
Is there a way to write the following function so that my IDE doesn't

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.