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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:04:42+00:00 2026-06-01T16:04:42+00:00

As per the MSDN documentation, while writing recursive function, The use of the accumulator

  • 0

As per the MSDN documentation, while writing recursive function, The use of the accumulator argument makes the function tail recursive, which saves stack space.
I’m using two example given on the MSDN site to calculate of sum of all the numbers in a list-

first without tail recursion-

let rec Sum myList =
    match myList with
    | [] -> 0
    | h::t -> h + Sum t

and now with tail recursion-

let Sumtail list =
    let rec loop list acc =
        match list with
        | h::t -> loop t acc + h
        | [] -> acc
    loop list 0

and running both the functions with input [1..100000].
Function Sum successfully calculates the sum of this list but gives stackoverflow exception if I pass [1..1000000]
but the second function Sumtail fails at [1..100000] while it should give better performance then the first function since it uses tail recursion.
Are there any other factors which affects the recursive function?

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

    Your second function isn’t tail-recursive since loop t acc + h is parsed as (loop t acc) + h which makes + become the last operation on loop.

    Change loop t acc + h to loop t (acc + h) in order that the function becomes tail-recursive.

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

Sidebar

Related Questions

Per the MSDN documentation , the following syntax is used: // A read-write instance
As per the MSDN Documentation TaskFactory.StartNew it Creates and starts a Task. So, for
I want to use wcf performance counters per operation , like here: http://msdn.microsoft.com/en-us/library/ms731052(v=vs.90).aspx how
As per the MSDN documentation with the Office 2007 system, office Addins are registered
As per this MSDN article: W3C Extended Log File Format (IIS 6.0) It says
http://msdn.microsoft.com/en-us/library/dd997415.aspx Per the article referenced above I am trying to handle exceptions in a
Using Visual Studio 2005 As per the title; MSDN and google can't tell me,
Per the Java documentation, the hash code for a String object is computed as:
Per MSDN , calling Type.GetMethods() stores reflected method information in a MemberInfo cache so
I am trying to understand how to use SyndicationItem to display feed which is

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.