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

The Archive Base Latest Questions

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

I ran into something with Array.map2 that I don’t understand. Consider this code: type

  • 0

I ran into something with Array.map2 that I don’t understand.

Consider this code:

type r1 = {
    v1 : int
    X : int
}

type r2 = {
    v1 : int 
    Y : int
}

let a1 = [|{v1=1;   X=1};   {v1=2;   X=2}|]   // val a1 : r1 [] ...
let a2 = [|{v1=100; Y=100}; {v1=200; Y=200}|] // val a2 : r2 [] ...

Array.map2 (fun x1 x2 -> (x1.X, x2.Y)) a1 a2   // works as expected
Array.map2 (fun x1 x2 -> (x1.v1, x2.v1)) a1 a2  // error FS0001: Type mismatch. Expecting a r2 [] but given a r1 [] 

Both records have a field v1. In the last line, I try to get a tuple of the values of v1, but from the different record types r1 and r2. It seems to throw an error when I try to select fields that have the same name on different records.

Somehow it jumps to the conclusion that x1 must be of type r2, why doesn’t the second line infer the type from the two parameters a1 and a2?

edit

This fixes it but I would expect to get the type right from the parameters.

Array.map2 (fun (x1:r1) x2 -> (x1.v1, x2.v1)) a1 a2  // works
  • 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-13T12:37:02+00:00Added an answer on June 13, 2026 at 12:37 pm

    The type checker works from left to right, so there isn’t enough information to resolve conflicts in the second example. Your first example is fine because .X and .Y are unique fields on r1 and r2 respectively.

    That said, in this case you could use piping to make types of a1 and a2 available to the type checker prior accessing record fields:

    (a1, a2) ||> Array.map2 (fun x1 x2 -> (x1.v1, x2.v1))
    

    In general, you should use record patterns which contain unique fields to identify correct types:

    Array.map2 (fun {v1 = a; X = _} {v1 = b; Y = _} -> (a, b)) a1 a2
    

    or provide fully qualified field names:

    Array.map2 (fun {r1.v1 = a} {r2.v1 = b} -> (a, b)) a1 a2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on some legacy code and I ran into something that I'm not
I ran into something a little odd this morning and thought I'd submit it
I just ran into something in Visual Studio 2010 RC that wasn't previously happening
I'm learning about interface properties and ran into something that I thought should work
I was doing some performance metrics and I ran into something that seems quite
I just started playing around with threading today and I ran into something that
I ran into something that I never thought of before and it stumped me.
So I ran into something interesting that I didn't realize about the ternary operator
Im learning C++ and I ran into something strange that I couldn't find any
I ran into something odd today that maybe someone knows something about. I have

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.