Repository navigation
Replies: 2 comments 1 reply
|
I think this would be a very good idea. We should have done it years ago, but we did hope that the ES6 specifications would win out and TCO would be implemented. Instead the vendors are claiming it's too problematic, even after Safari demonstrated that it's not a real issue. I think we'd have to come up with a different implementation than the linked trampoline = pc => {
while (typeof pc === 'function') {
pc = pc();
}
return pc;
},This treats functions as different from other values, with the implicit assumption that a recursive function couldn't return a function. I'd have to think about how best to implement one, though. |
0 replies
|
Maybe related, a gist of mine using a Loop-Recur implementation adapted from one seen on StackOverflow: const Loop = (fn, ... init) => {
let r = fn (... init)
while (r instanceof Recur) r = fn (... r)
return r
}
const Recur = ( ...v) => Object .create (
Recur .prototype,
{[Symbol .iterator]: {value: _ => v .values ()}}
) |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Recursive functions are integral to FP.
8 years after ES6, Tail-Call Elimination is just supported by WebKit — so on Safari and Bun JS runtimes.
On other runtimes,
trampolineis needed to avoid stack overflow errors.Since it would be a great use-case for
R.thunkify,trampolinetoo would be a good fit for Ramda. IMO.History:
R.trampolinewas already suggested in R.trampoline #1484.RA.trampolinewas attempted in #1425Usage:
Signature
As high-order function returning an auto-curried function the signature could be something like
trampoline :: ((a, b, …, j) → Thunk k) → a → b → … → f → kThunk k = (() → (k | () → (k | … )))Otherwise when simply applying the recursion
trampolineApp :: Thunk a → aI'd prefer the higher-order function, though.
The implementation is straight forward.
Do we need this?
All reactions