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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:02:32+00:00 2026-05-27T04:02:32+00:00

You could pattern-match against multiple arguments of a function by creating a tuple and

  • 0

You could pattern-match against multiple arguments of a function by creating a tuple and then destructuring it in a match expression:

let f x y =
  match x, y with
  | pattern1 -> expr1
  | ...

Alternatively, if you don’t need a curried function, you could do this by making f take a tuple as the only argument:

let f (x, y) = function
  | pattern1 -> expr1
  | ...

The advantage of the latter method is that you don’t have to write the arguments twice every time you define a function. But functions that take a tuple seems to be not as popular than curried ones.

So which of the two is deemed canonical, or preferred, in the OCaml community?

EDIT: Just as pad pointed out below, I mean let f = function blah blah in the second code snippet.

  • 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-27T04:02:33+00:00Added an answer on May 27, 2026 at 4:02 am

    A tuple is not just a syntactic construct, it represents a real data structure. This means that fun (x,y) is (very slightly) less efficient than f x y in the case were x and y aren’t already tupled, because a tuple has to be allocated. If this isn’t clear, the rough equivalent in Java would be

    void foo(X x, Y y) { ... }
    void bar(Tuple<X,Y> t) { ... }
    
    /* client code */
    X x = new X();
    Y y = new Y();
    
    foo(x, y);  // Just uses x and y directly
    bar(new Tuple<X,Y>(x, y)); // Has to "new" a Tuple
    

    For this reason, it’s generally preferable to avoid using tuples as function arguments unless you have a good reason to do so.

    P.S. A similar consideration applies to datatype declarations, where the following are subtly different:

    type 'a foo = Foo of 'a * 'a;
    type 'a bar = Bar of ('a * 'a);
    

    Foo is a datatype constructor that takes two arguments. Bar is a constructor that takes one argument (a tuple).

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

Sidebar

Related Questions

could someone help me with the regex pattern that i could use to match
Is there a pattern that I could apply to refactor this code? The only
I was wondering if anyone could advise on a good pattern for loading textures
Could someone recommend any good resources for creating Graphics User Interfaces, preferably in C/C++?
I'm writing grepath utility that finds executables in %PATH% that match a pattern. I
Let's say I want to make a special case for a function that matches
I'm looking for a regex that will scan a document to match a function
I'm trying to match a string 123,1234 using regex.h. Following pattern does the job:
I want to match a string I read against an array of possible matches.
I want a regex expression that will match; www http https It should make

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.