6 ms·
> For example, instead of a power function that uses a loop, you could generate specialized code like x * x * x * x * x directly. This eliminates runtime overh
by kldx 1y ago
> For example, instead of a power function that uses a loop, you could generate specialized code like x * x * x * x * x directly. This eliminates runtime overhead and creates highly optimized code.
Could anyone explain to me how this is different from templates or parameter pack expansion in C++? I can see the constexpr-ness here is encoded in the type system and appears more composable, but I am not sure if I am missing the point.
I looked at the paper but I can't find anything related to C++.
- gsliepen 1y ago> Could anyone explain to me how this is different from templates or parameter pack expansion in C++? I don't think it's any different. > I can see the constexpr-ness here is encoded in the type system I also see they introduce new constructs like let$, so it's not just a type system thing. > I looked at the paper but I can't find anything related to C++. I don't think the author needs to compare their code to C++. That said, it looks to me like it is similar to the upcoming C++26's reflection capabilities.
- naasking 1y agoTypically, multistage languages permit program generation at any stage, including runtime. So that would be different than C++.
- gsliepen 1y agoYou can get pretty far in C++ though: https://codereview.stackexchange.com/questions/259045/poor-mans-jit-using-nested-lambdas https://codereview.stackexchange.com/questions/259045/poor-m...
- naasking 1y agoThis looks like a reinvention of the final, tagless interpreter, which has been a great, common technique in functional languages for awhile: https://okmij.org/ftp/tagless-final/index.html#tagless-final https://okmij.org/ftp/tagless-final/index.html#tagless-final It's an interpreter though, not a JIT. This kind of programming language thing is a bit of a hobby horse of mine, so see the comment I just posted on this for full details: https://codereview.stackexchange.com/questions/259045/poor-mans-jit-using-nested-lambdas/297544#297544 https://codereview.stackexchange.com/questions/259045/poor-m...