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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:01:54+00:00 2026-06-04T18:01:54+00:00

I am trying to write a bootstrap algorithm in F# that takes a collection

  • 0

I am trying to write a bootstrap algorithm in F# that takes a collection of inputs and creates a list of outputs. If I only need to use the previous element it is straightforward to use recursion :

let buildElement head previous =
    // do something to create new float 
    1.0

let buildList inputs =
    let rec bootstrap elements previous = 

        let addElement head tail =
            let newElement = buildElement head previous
            newElement :: bootstrap tail newElement   

        match inputs with
            | []    -> []
            | h::t  -> addElement h t
    bootstrap inputs 1.0

However, if I want to use the previously created elements (eg say I wanted to pass in an average of the new values as the previous value), how do I access them in the inner functions? Do I create a collection in the outer function and fill it up in the inner function? If so, do I need to make it mutable?

  • 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-04T18:01:56+00:00Added an answer on June 4, 2026 at 6:01 pm

    If you need to calculate the new value based on some information from the past values, you would essentially do the same thing as what you’re doing now – instead of passing ingle last value in previous, the previous parameter could be a list of past values that you recalculate as you go.

    I think it is difficult to give a better answer without knowing a specific example. However, say you wanted to calculate floating average – for that, you need the count and the sum of all previous values. You could encode that directly using recursion, or you can use Seq.scan:

    [ 1.0 .. 100.0 ] 
    |> Seq.scan (fun (count, sum) elem -> count + 1, sum + elem) (0, 0.0)
    |> Seq.map (fun (count, sum) -> sum / float count)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write function that numerize items of list and returns list of tuples
I'm trying to write a script that generates Twitter Bootstrap styled elements by simply
I am trying write a function that generates simulated data but if the simulated
Trying to write a simple jQuery function that will multiple the index of an
Trying to write a couple of functions that will encrypt or decrypt a file
Trying to write a code at the moment that basically tests to see if
Trying to write a code that searches hash values for specific string's (input by
Trying to write a game such that most of the screen gets filled with
Im trying to write a simple script that slides the next 'slide' div in
I'm trying write a simple perl script that reads some fields from a password

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.