3 ms·
This example code must be monomorphized at compile time, meaning that each closure will have a different representation. "Tail call optimization at the type lev
by tatterdemalion 10y ago
This example code must be monomorphized at compile time, meaning that each closure will have a different representation. "Tail call optimization at the type level" is not possible with this compilation model.
(The problem is solved by using a trait object to dynamically dispatch the inner call. https://play.rust-lang.org/?gist=0d3c0a5f1291eb34ba61bd39449cb5eb&version=stable&backtrace=0 https://play.rust-lang.org/?gist=0d3c0a5f1291eb34ba61bd39449...)
- hornetblack 10y agoFrom memory I solved it using more CPS and currying. Well manually currying with functions like curry1, curry2, etc... Although I'm pretty sure you can overload the Fn* traits to implement currying in Rust. (Fn traits are unstable). Which is neat. // Something like this: impl<F, A, B, R> (FnOnce(A) -> Curry<F, A, B>) for F where F: FnOnce(A, B) -> R, { ... } // and impl<F, A, B, R> (FnOnce(B) -> R) for Curry<F, A, B> where F: FnOnce(A, B) -> R I think I got it working... but you would need some work for more arguments. (And it worked different on different versions of rust-nightly :/)