rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Add "tail modulo constructor" transformation

Open johnridesabike opened this issue 3 years ago • 0 comments

I'm wondering if it would be possible to implement the "tail modulo constructor" transformation that was added to recent OCaml versions. It allows some non-tail-recursive functions (e.g. the OCaml stdlib List.map) to run in a tail-recursive manner with constant stack space.

This would be very beneficial since stack size is a significant limitation in JavaScript.

It looks like Belt.List already does something similar to the TMC-style output (if I'm understanding it correctly), except that it's hand-written and with external calls. Making the TMC transformation a first-class feature would open up this kind of optimization for other code as well.

johnridesabike avatar Jul 22 '22 14:07 johnridesabike