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

  • Home
  • SEARCH
  • 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 6149045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:23:14+00:00 2026-05-23T19:23:14+00:00

I am having problems running the below recursive function on our development web server.

  • 0

I am having problems running the below recursive function on our development web server. It causes a stack overflow. It runs fine locally when in debugging mode. Here are things I have tried:

  1. Made sure ‘Generate tail calls’ is enabled under build options.
  2. I ran the disassembler and followed the instructions here: http://blogs.msdn.com/b/fsharpteam/archive/2011/07/08/tail-calls-in-fsharp.aspx and it does not appear to be using tail recursion.
  3. I’ve tried rewriting it without using recursion but my F# skills are not the best.

So my questions would be:

  1. Is this function going to be able to use tail end recursions?
  2. Why would it work locally in debugging mode through VS but not on the dev web server?

Thanks!

let rec SimulationLoop (rowNum : int) (h : double) (time : double) (v : double) (s : double) (p : double) (newV' : double) (newS' : double) (newP' : double) (designParameters : DesignParameters) (inputs : ISimulationInputProvider) = seq {
    //let timer = System.Diagnostics.Stopwatch.StartNew()
    let finalTime = (6.0 * inputs.ShockAbsorber.Stroke / designParameters.VelocityAfterImpact)    
    let startH = StartH h time finalTime

    let slopes = Slopes v s p newV' newS' newP' startH designParameters inputs
    let vSlope, sSlope, pSlope = slopes
    let betaList = [ for j in 0 .. 5 -> beta.[j].[4] ]
    let newV' = CalcPrime v startH vSlope betaList
    let newS' = CalcPrime s startH sSlope betaList
    let newP' = CalcPrime p startH pSlope betaList

    let delta = Delta h slopes
    let tau = Tau v s p

    let rowResult, rowNum, time, newV, newS, newP = if delta < tau then RecordResults rowNum time startH v s p slopes designParameters inputs else None, (rowNum + 1), time, v, s, p
    let loop = newS < inputs.ShockAbsorber.Stroke - 0.01 && newV >= 0.0 && rowNum <= 8000 && (time < finalTime && time + h > time)
    let stepLength = StrokeStepLength inputs.ShockAbsorber.Stroke designParameters.HoleSize
    let endH = EndH delta startH tau stepLength newV

    //timer.Stop()
    //System.Diagnostics.Debug.WriteLine("Row: " + rowNum.ToString() + " = " + timer.ElapsedMilliseconds.ToString())
    match (rowResult, loop) with
        | Row(r), true ->
            yield r
            yield! SimulationLoop rowNum endH time newV newS newP newV' newS' newP' designParameters inputs
        | Row(r), false ->
            yield r
        | None, true ->
            yield! SimulationLoop rowNum endH time newV newS newP newV' newS' newP' designParameters inputs
        | None, false -> ()
}
  • 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-23T19:23:15+00:00Added an answer on May 23, 2026 at 7:23 pm

    I ended up rewriting it without recursion. This is not the most elegant solution but it works:

    let SimulationLoop (rowNum : int) (h : double) (time : double) (v : double) (s : double) (p : double) (newV' : double) (newS' : double) (newP' : double) (designParameters : DesignParameters) (inputs : ISimulationInputProvider) = 
        let mutable mKeepLooping = true
        let mutable mRowNum = 1
        let mutable mEndH = h
        let mutable mTime = time
        let mutable mNewV = v
        let mutable mNewS = s
        let mutable mNewP = p
        let mutable mNewV' = newV'
        let mutable mNewS' = newS'
        let mutable mNewP' = newP'
    
        let theList = new List<SimulationRow>()
    
        while mKeepLooping do
            let finalTime = (6.0 * inputs.ShockAbsorber.Stroke / designParameters.VelocityAfterImpact)
            let startH = StartH mEndH mTime finalTime
    
            let slopes = Slopes mNewV mNewS mNewP mNewV' mNewS' mNewP' startH designParameters inputs
            let vSlope, sSlope, pSlope = slopes
            let betaList = [ for j in 0 .. 5 -> beta.[j].[4] ]
            let mNewV' = CalcPrime v startH vSlope betaList
            let mNewS' = CalcPrime s startH sSlope betaList
            let mNewP' = CalcPrime p startH pSlope betaList
    
            let delta = Delta mEndH slopes
            let tau = Tau mNewV mNewS mNewP
    
            let rowResult, rowNum, time, newV, newS, newP = if delta < tau then RecordResults mRowNum mTime startH mNewV mNewS mNewP slopes designParameters inputs else None, (mRowNum + 1), mTime, mNewV, mNewS, mNewP
            mRowNum <- rowNum
            mTime <- time
            mNewV <- newV
            mNewS <- newS
            mNewP <- newP
            let loop = newS < inputs.ShockAbsorber.Stroke - 0.01 && newV >= 0.0 && rowNum <= 8000 && (time < finalTime && time + h > time)
            mKeepLooping <- loop
            let stepLength = StrokeStepLength inputs.ShockAbsorber.Stroke designParameters.HoleSize
            mEndH <- EndH delta startH tau stepLength newV
    
            match rowResult with
            | Row(r) ->
                theList.Add(r)
            | _ -> ()
    
        theList
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm having problems running my MVC project on my server. The main project on
I'm running ASP.NET MVC on a shared server and I'm having problems connecting to
I have been having some problems trying to get my PHP running. When I
I'm having a problem running a T4 template using TextTransform.exe on my build server.
Recently, I've started having a problem with my SQL Server 2005 client running on
I am having some problems running a find loop inside of a subroutine when
I'm having a problem running a VS 2005 app on some machines and not
Im having problems displaying records to my view when passing viewdata to a user
Im having problems building a query with the linq to sql data query expression
I have recently started having problems with TortoiseCVS, or more specifically with plink, the

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.