Nice write-up. I'm the author of the mentioned peano and typenum libraries, if anyone has any questions.
The problem with this peano arithmetic thing is that it only goes up to 88 https://upload.wikimedia.org/wikipedia/commons/b/bd/D274.jpg
Doing First Grade Math in Rust's Type System
31–40 of 43 posts
Re: Doing First Grade Math in Rust's Type System
#32Reading this I realize that I know nothing about Rust's type system, despite using the language daily.
When I use Rust, I feel like I'm just a dude mopping the floors of the nuclear silo.
Re: Doing First Grade Math in Rust's Type System
#33For complicated runtime behavior, we have various tools for stepping through the evaluations as they unfold. E.g., debuggers, print statements, etc.
But I haven't come across anything similar for these type-based evaluations. Usually the best I get is a compiler warning or error, or even worse, an unexpected successful compilation.
Are there any efforts to help with this, for e.g. C++ compilation?
Re: Doing First Grade Math in Rust's Type System
#34I'm uncomfortable with programs that rely on complicated compile-time evaluation within the type system. For complicated runtime behavior, we have various tools for stepping through the evaluations as they unfold. E.g., debuggers, print statements, etc. But I haven't come across anything similar for these type-based evaluations. Usually the best I get is a compiler warning or error, or even worse, an unexpected succe…
Re: Doing First Grade Math in Rust's Type System
#35I'm uncomfortable with programs that rely on complicated compile-time evaluation within the type system. For complicated runtime behavior, we have various tools for stepping through the evaluations as they unfold. E.g., debuggers, print statements, etc. But I haven't come across anything similar for these type-based evaluations. Usually the best I get is a compiler warning or error, or even worse, an unexpected succe…
Lisp is dynamically typed, so it's not the same as C++ templates or the Rust type system, but to me, it seems like there isn't a reason in principle why you couldn't make a stepper for pure C++ template metaprogramming, like this Peano arithmetic implementation: https://gist.github.com/vladris/2dc4f5a47d003da002a70f0c0184...
Particularly for "using" declarations, like this (taken from the gist that I linked):
// A few numbers...
using one = succ;
using two = succ;
using three = succ;
using four = succ;
using five = succ;
Also, the clangd language server expands C preprocessor macros, but that's less useful because the C preprocessor doesn't allow recursive macros.Re: Doing First Grade Math in Rust's Type System
#36Earlier quoted context omitted.
When I use Rust, I feel like I'm just a dude mopping the floors of the nuclear silo.
Imagine doing C++. It's like being the new guy who has to manually take Geiger readings of the warhead.
C++ is by far the most Wild West, the most gotcha, the most “do as I say but not as I do”, the most “yes, except if” language ever. From 98-today, it’s just gotten more and more bloated with alternative pathways and acid pits.
I’m hopeful for Rust. Equally so for Zig. My opinions mean shit and in the end, the Rust team will evolve Rust beyond what they originally intended, capturing dev attention and pushing Rustic concepts outwards. Such as they all have the last 15 years.
Re: Doing First Grade Math in Rust's Type System
#37Earlier quoted context omitted.
Imagine doing C++. It's like being the new guy who has to manually take Geiger readings of the warhead.
Basic modern C++ is easier than Rust at this point. It’s not as safe (std::shared_ptr is not your friend), but it’s easier to get going vs dealing with lifetimes and Rustic syntax. I feel like at this point Rust has inherited all the syntax diarrhea of C++ and makes me adverse to using it. I don’t want to wrestle type system crap when I’m trying to wrestle app features. Some things I love. A few things I hate. Those…
Rust can be easy enough to get going if you know to use .clone(), Rc> and the like. Yes it's a bit heavy on boilerplate but that's about it. Also the boilerplate is helpful since it can guide a refactoring effort to make the code a bit more efficient. With Rust, "clean" code is usually fast and safe code which is not as true in other languages.
Re: Doing First Grade Math in Rust's Type System
#38Earlier quoted context omitted.
Basic modern C++ is easier than Rust at this point. It’s not as safe (std::shared_ptr is not your friend), but it’s easier to get going vs dealing with lifetimes and Rustic syntax. I feel like at this point Rust has inherited all the syntax diarrhea of C++ and makes me adverse to using it. I don’t want to wrestle type system crap when I’m trying to wrestle app features. Some things I love. A few things I hate. Those…
> It’s not as safe (std::shared_ptr is not your friend), but it’s easier to get going vs dealing with lifetimes and Rustic syntax. Rust can be easy enough to get going if you know to use .clone(), Rc > and the like. Yes it's a bit heavy on boilerplate but that's about it. Also the boilerplate is helpful since it can guide a refactoring effort to make the code a bit more efficient. With Rust, "clean" code is usually f…
Re: Doing First Grade Math in Rust's Type System
#39Earlier quoted context omitted.
> It’s not as safe (std::shared_ptr is not your friend), but it’s easier to get going vs dealing with lifetimes and Rustic syntax. Rust can be easy enough to get going if you know to use .clone(), Rc > and the like. Yes it's a bit heavy on boilerplate but that's about it. Also the boilerplate is helpful since it can guide a refactoring effort to make the code a bit more efficient. With Rust, "clean" code is usually f…
Less divergent code does not make better code. Rc > is a prime example of "Do as we say, not as we do" in Rust that has made its way in from C++. I thought the borrow-checker was gospel and yet, here we are on the cusp of circumventing that with dynamic memory allocation checking (or lack thereof, just that it's the same size).