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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:15:48+00:00 2026-06-04T15:15:48+00:00

Has anyone written a formal paper describing a method to (automatically) convert functions to

  • 0

Has anyone written a formal paper describing a method to (automatically) convert functions to be tail recursive? I am looking for a university-level formal treatment including the limitations (types of functions that can be converted), procedures for conversion, and, if possible, proofs of correctness? Examples in Haskell would be a bonus.

  • 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-04T15:15:49+00:00Added an answer on June 4, 2026 at 3:15 pm

    a method to (automatically) convert functions to be tail recursive?

    So there are two parts to this:

    • recognizing that a given recursive function can be converted to a tail recursive form and making that transformation
    • implementing tail calls in an efficient way, so the transformation is worth while.

    Transforming recursion into tail recursion

    It appears relatively straight forward to recognize tail recursive definitions syntactically. After all, ‘tail recursive’ just means that the call appears syntactically in the tail of the expression.

    E.g. the Scheme folks describe:

    merely compiling appropriate self-calls as jumps is not suficient to
    achieve full tail-recursion. Instead, we syntactically divide all
    sub-expression positions in the source language into two classes: tail
    (or reduction) position and subproblem position. In the simple
    expression (if predicate consequent alternative), the predicate is a
    subproblem position, while both consequent and alternative are in
    reduction positions. This syntactic notion can be easily extended to
    arbitrarily nested sub-expressions.

    • Compiling Higher-Order Languages into Fully Tail-Recursive Portable C

    Transforming functions into tail calls

    The tricky part of your question is optimizations for identifying and transforming candidate recursive computations into tail recursive ones.

    One reference is in GHC, which uses inlining and a wide array of simplification rules to collapse away recursive calls, until their underlying tail recursive structure remains.

    • Secrets of the GHC inliner

    Tail Call Elimination

    Once you have your functions in a tail-recursive form, you’d like to have that implemented effiicently. If you can generate a loop, that’s a good start. If your target machine doesn’t, then the tail call elimination” will need a few tricks. To quote Odersky and Schinz, cited below,

    Various techniques have been proposed over the years to eliminate
    general (and not only recursive) tail calls, mostly for compilers
    targeting C.

    … put the whole program in a big function and to simulate
    function calls using direct jumps or switch statements inside this function.

    … A popular technique is to use a trampoline. A trampoline is an outer
    function which repeatedly calls an inner function. Each time the inner function
    wishes to tail call another function, it does not call it directly but simply
    returns its identity (e.g. as a closure) to the trampoline, which then does the
    call itself. Unlimited stack growth is thus avoided, but some performance is
    inevitably lost, mostly because all the calls made by the trampoline are calls
    to statically unknown functions.

    Another technique is Henry Baker’s “Cheney on the M.T.A.”
    With his technique, the program first has to be converted to continuation passing
    style (CPS), therefore turning all calls into tail calls, and can then be
    compiled as usual. At run-time, when the stack is about to overflow, the
    current continuation is built and returned (or longjmped) to the trampoline
    “waiting” at the bottom of the call stack.

    • Tail call elimination on the Java Virtual Machine, Michel Schinz Martin Odersky, 2001

    • Henry G. Baker, Jr. CONS should not CONS its arguments, part II: Cheney
      on the M. T. A. Draft Version, January 1994.

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

Sidebar

Related Questions

Has anyone written a nice extension method 'library' for System.Drawing.Color. Would be nice to
Has anyone written, or know of a library, that generates fairly accurate looking Western
Has anyone written a macro that will remove and sort your usings in an
Has anyone written XACML Implementations other than the Sun XACML Implementation and XEngine? Who
Has anyone written either a long or short program in COW that demonstrates what
Has anyone written a Fast Algorithm that generates a LARGE dummy file in PHP,
Has anyone written a fast Fourier transform extension for R that modifies R's native
Has anyone written an 'UnFormat' routine for Delphi? What I'm imagining is the inverse
Has anyone written some interesting or cool Linq extension methods they would like to
Has anyone written, or know of a query, that will find and drop all

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.