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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:20:33+00:00 2026-05-11T02:20:33+00:00

Messing around with ‘extension functions’ for the List module. (I spent quite a while

  • 0

Messing around with ‘extension functions’ for the List module. (I spent quite a while developing ‘mapfold’ – which threads an accumulator like fold, but uses it as a parameter to create new values like map – then discovered that that is what List.scan_left does)

For generation of test data, I needed to do a cross product of two lists, This is what I came up with:

///Perform cross product of two lists, return tuple let crossproduct l1 l2 =     let product lst v2 = List.map (fun v1 -> (v1, v2)) lst     List.map_concat (product l1) l2 

Is this any good, or is there already some better way to do this?

Same question for this one:

///Perform cross product of three lists, return tuple let crossproduct3 l1 l2 l3 =     let tuplelist = crossproduct l1 l2 //not sure this is the best way...     let product3 lst2 v3 = List.map (fun (v1, v2) -> (v1, v2, v3)) lst2     List.map_concat (product3 tuplelist) l3 
  • 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. 2026-05-11T02:20:33+00:00Added an answer on May 11, 2026 at 2:20 am

    another option is to use F# ‘sequence expressions’ and write something like this:

    let crossproduct l1 l2 =   seq { for el1 in l1 do           for el2 in l2 do             yield el1, el2 };; 

    (actually, it is almost the same thing as what you wrote, because ‘for .. in .. do’ in sequence expression can be viewed as map_concat). This works with (lazy) sequences, but if you want to work with lists, you’d just wrap the code inside [ … ] rather than inside seq { … }.

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

Sidebar

Related Questions

I'm messing around with Safari extensions, and I'd like my extension to respond to
I am messing around with a tornado web app with which I need a
I am messing around with a toy interpreter in Java and I was considering
I was messing around with RhinoMocks this morning and couldn't run my tests because
I am messing around with Doctrine (version 1.0.3) to see if would make a
I'm messing around with some C code using floats, and I'm getting 1.#INF00, -1.#IND00
I've been messing around with the free Digital Mars Compiler at work (naughty I
When messing around with Haskell using GHC, I can use various meta-commands like :i
I am messing around with the Indy 10 supplied with Delphi 2009 and am
I am sure am messing around with a lot of casting and such in

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.