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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:33:29+00:00 2026-06-02T21:33:29+00:00

Is it possible to unpack a type by binding its data to a single

  • 0

Is it possible to unpack a type by binding its data to a single value instead of a tuple?

# type foo = Foo of int * string;;
type foo = Foo of int * string
# Foo (3; "bar");;
  Foo (3; "bar");;
Error: The constructor Foo expects 2 argument(s),
       but is applied here to 1 argument(s)
# Foo (3, "bar");;
- : foo = Foo (3, "bar")

# (* Can this possibly work? *)
# let Foo data = Foo (3, "bar");;
  let Foo data = Foo (3, "bar");;
Error: The constructor Foo expects 2 argument(s),
       but is applied here to 1 argument(s)

# (* Here is the version that I know works: *)
# let Foo (d1, d2) = Foo (3, "bar");;
val d1 : int = 3
val d2 : string = "bar"

Is this syntactically possible?

  • 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-02T21:33:31+00:00Added an answer on June 2, 2026 at 9:33 pm

    This is a tricky part of OCaml syntax. If you define your type as you show, its constructor Foo expects two values in parentheses. And it always has to be two values, it’s not a single value that’s a tuple.

    If you’re willing to use a different type, you can do something more like what you want:

    # type bar = Bar of (int * string);;
    type bar = Bar of (int * string)
    # let Bar data = Bar (3, "foo");;
    val data : int * string = (3, "foo")
    # let Bar (d1, d2) = Bar (3, "foo");;
    val d1 : int = 3
    val d2 : string = "foo"
    

    When declared this way, the constructor Bar expects one value that’s a tuple. This can be more flexible, but it also takes a little more memory to represent it, and a little longer to access the parts.

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

Sidebar

Related Questions

Possible Duplicate: XPath: How to match attributes that contain a certain string I'm trying
Possible Duplicate: Space bar not working in form fields Has anyone run into an
How to (or is it possible to) unpack a parameter pack with a numeric
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: C# okay with comparing value types to null Consider the following code
Is it possible to iterate over a pymongo Cursor as a key-value pair like
I am getting the too many values to unpack error. Any idea how I
In Python, the assignment operator can unpack a list or a tuple into variables,
From this question: bytearray - Perl pack/unpack and length of binary string - Stack
Possible Duplicate: C++ templates that accept only certain types For example, if we want

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.