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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:59:37+00:00 2026-06-10T12:59:37+00:00

I’m completely baffled by observing this behaviour in my F# code, here taken from

  • 0

I’m completely baffled by observing this behaviour in my F# code, here taken from an interactive session:

Microsoft (R) F# 2.0 Interactive build 4.0.40219.1
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> type foo = Foo of (string * int);;
  type foo = | Foo of (string * int)

> let f = Foo ("bar",42);;
  val f : foo = Foo ("bar", 42)

> match f with Foo x -> x;;
  val it : string * int = ("bar", 42)

> type bar = Bar of string * int;;
  type bar = | Bar of string * int

> let b = Bar ("baz",21);;
  val b : bar = Bar ("baz",21)

> match b with Bar x -> x;;
  match b with Bar x -> x;;
  -------------^^^^^

stdin(7,14): error FS0019: This constructor is applied to 1 argument(s) but expects 2
> 

It seems obvious to me that pattern matching on both Foo and Bar with a single variable should be valid – so I was wondering if anyone knew the reason for this wierd behaviour, or if you like me consider it a bug.

Update:
Just to clarify, the reported types of the constructors Foo and Bar are:

> Foo;;
val it : string * int -> foo = <fun:clo@14-1>
> Bar;;
val it : string * int -> bar = <fun:clo@13>

So certainly, they should accept the same set of valid patterns

  • 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-10T12:59:39+00:00Added an answer on June 10, 2026 at 12:59 pm

    I agree this looks quite confusing. As pad explained, the difference between the two declarations is not just syntactical – you are actually defining discriminated union cases that consist of different types.

    • In case of Foo, the case contains one element of type int * string
    • In case of Bar, the case contains two elements of type int and string

    The two options are very similar, but they are actually different. You can see that if you look at the type definitions in the F# specification. Here are the bits that describe type definitions of discriminated union:

    union-type-defn :=
       type-name ‘=’ union-type-cases type-extension-elementsopt

    union-type-cases :=
       ‘|’opt union-type-case ‘|’ … ‘|’ union-type-case

    union-type-case :=
       attributesopt   union-type-case-data

    union-type-case-data :=
       ident                                   – null union case
       ident of type * … * type      — n-ary union case

    Note that the “n-ary union case” consists of multiple elements (type * ... * type). A type is defined as follows (not surprisingly, it can be a tuple):

    type :=
       ( type )
       type -> type         — function type
       type * … * type    – tuple type
       …                         – lots of other types

    I do not know why union-type-case-data does not use just unary union case (instead of n-ary) and always treat the elements as tuple. I think that would make perfect sense, but it might be something that F# inherited from OCaml or ML. However, at least the specification explains this!

    In fact, I suppose the specification is a bit ambiguous, because you could treat Foo of int * int as both n-ary union case and unary case with a tuple (but without the bracketted type ( type )).

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build

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.