New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trampolines #30
Comments
Thanks for opening this. It’s certainly something I’ve thought about and others have brought up. It just hasn’t affected us (SlamData) in practice yet, so we haven’t prioritized it. I think the first step is to come up with some test cases (marked |
@sellout Makes sense, but it would require coverage of every recursion scheme in the entire library, seeing as they can all stack overflow. Perhaps migrating to a uniform representation of recursion schemes which can be tested on its own will be less prohibitive? |
Curious on your feelings on this now. We’ve made some significant strides in terms of the way things are defined (although some of it hasn’t yet been PRed). Almost all |
Agreed. |
Cool, then I’m closing this and will expect specific issues for cases when this isn’t enough. |
Hi ! For reference, I let that here : def cataTrampoline[E[_],A](t: Fix[E])(f: Algebra[E, A])
(implicit BT: Traverse[E]):Trampoline[A] = {
//with regular cata being :
//t.hylo[E,A](f, x => x.unFix)
t.hyloM[Trampoline,E,A](
x => Trampoline.delay(f(x)),
x => Trampoline.delay(x.unFix))
} |
|
All of matryoshka's recursion operators at the moment are not stack-safe. However, always trampolining them can be a performance issue. Therefore, is there any interest in representing recursion schemes in a recursion-less fashion, so that they can be executed in a trampolined or partially-trampolined (a la http://blog.higher-order.com/blog/2015/06/18/easy-performance-wins-with-scalaz/) context?
One way to do this without sacrificing the ability to make plain (not trampolined) recursive calls for data which is known to be small is to write recursion schemes in CPS, such that an ordinary recursive function
is represented as:
Then the scheme can make calls to
loop
instead of explicitly recursing, and it can be executed with each step trampolined, or with none of them trampolined, or with only steps exceeding some maximum stack size trampolined.The text was updated successfully, but these errors were encountered: