Coder Social home page Coder Social logo

Add Trampoline about arrow HOT 1 CLOSED

arrow-kt avatar arrow-kt commented on August 19, 2024
Add Trampoline

from arrow.

Comments (1)

pakoito avatar pakoito commented on August 19, 2024

Description from #77

Trampoline is often used to emulate tail recursion. The idea is to have some step code that can be trampolined itself to emulate recursion. The difference with standard recursion would be that there is no need to rewind the whole stack when we reach the end of the stack, since the first value returned that is not a trampoline would be directly returned as the overall result value for the whole function chain. That means Trampoline emulates what tail recursion does.

There are languages that do not have tailrec modifier that use Trampoline to emulate the same behavior. But Trampoline is also useful for languages that also have trampolines out of the box:

"As long as you use tail recursion with one function everything is fine as the compiler will optimize it for you and transform it in a loop, issues come when you are trying to use tail recursive calls between two functions or when you don’t have a tail recursive call."

Trampolines are stack safe, since they do not need to maintain a function call stack (since they don't need to rewind it). So trampolines are useful also when you don't want to blow your stack up for too long recursive operations.

from arrow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.