4 ms·
Ok, that was harsh, but I was excited and wanted to get to the meat of the article but then it just ended. I was thinking, "that's not how I would design a C++
by actionfromafar 4y ago
Ok, that was harsh, but I was excited and wanted to get to the meat of the article but then it just ended.
I was thinking, "that's not how I would design a C++ interface". I still don't understand what these Rust types are good for, but I want to know.
I miss how in Ada you can define which values an int can have. Can you do that in Rust?
- deleted 4y ago[deleted]
- proto_lambda 4y ago> I miss how in Ada you can define which values an int can have. Can you do that in Rust? yes, kind of: https://crates.io/crates/deranged https://crates.io/crates/deranged It'll take another while until const generics on stable are advanced enough to make this properly usable, such that e.g. `RangedU32<3, 10> + RangedU32<5, 6> = RangedU32<8, 16>`.
- satvikpendem 4y agoYou're looking for dependent types and while Rust has a limited form, it doesn't have them fully. Idris does, on the other hand.
- lopatin 4y agoYeah there’s a serious lack of discussion of Idris in this thread. Probably the most fun, least used programming language ever.
- efnx 4y agoYou can do with a sum type (enum) that is represented by a u32 (repr(u32)), or converts into one. Though I don’t know Ada so can’t speak to how accurately I’m creating the analogy.
- pjmlp 4y agoIn Ada/Pascal/Modula-2/Modula-3/.... it would be something like, type Subrange = 56..100; Colors = (Red, Green, Blue); Pixel = array [Colors] of byte; With the plus that it is a compiler error if an invalid value is assigned, and can be validated at compile time (or it will be a range runtime error otherwise).