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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:30:05+00:00 2026-06-11T14:30:05+00:00

for i in a..b do res <- res * myarray.[i] res Do I have

  • 0
 for i in a..b do
     res <- res * myarray.[i]
 res

Do I have to use like

  Array.fold (*) 1 (Array.sub myarray a (b - a + 1))

, which I believe is rather slow and not that concise?

  • 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-11T14:30:06+00:00Added an answer on June 11, 2026 at 2:30 pm

    Daniel’s solution is pretty neat and I think it should be nearly as efficient as the for loop, because it does not need to clone the array.

    If you wanted a more concise solution, then you can use indexer instead of Array.sub, which does need to clone some part of the array, but it looks quite neat:

    myarray.[a .. b] |> Seq.fold (*) 1
    

    This clones a part of the array because the slicing operation returns an array. You could define your own slicing operation that returns the elements as seq<'T> (and thus does not clone the whole array):

    module Array =
      let slice a b (arr:'T[]) = 
        seq { for i in a .. b -> arr.[i] }
    

    Using this function, you could write:

    myarray |> Array.slice a b |> Seq.fold (*) 1
    

    I believe this more directly expresses the functionality that you’re trying to implement. As always with performance – you should measure the performance to see if you need to make such optimizations or if the first version is fast enough for your purpose.

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

Sidebar

Related Questions

I have in /res/values/styles.xml different font styles but I need to change that for
I have the following code which return wmi information (unknown array) For Each objMgmt
Resources$NotFoundException: File res/color/dark.xml from drawable resource I have that error. I tried clean project.
I have this in res/values/styles.xml <style name=ListViewRowBorder > <item name=android:width>1dp</item> <item name=android:color>@color/listview_row_stroke_color</item> </style> I
So I have a file in res/values/ on my desktop, in it is strings.xml,
Is there any folder like res/drawable for mp3 or generally audio files? If yes,
I have a picture in res/drawable directory: res/drawable/picture.jpeg. Can I dynamically update this picture.jpeg
Can not parse json using this var res = eval('(' + response + ')');
This is my array.xml file in the res/values folder: <?xml version=1.0 encoding=utf-8?> <resources> <string-array
I'm trying to extract the Android /res folder into a separate project that's included

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.