4 ms·
"is much faster and the one you should probably use in practice" Where is this useful in practice? Exercises maybe. Like doing planks for example. I have never
by amne 3y ago
"is much faster and the one you should probably use in practice" Where is this useful in practice? Exercises maybe. Like doing planks for example. I have never needed to plank "in practice" other than to exercise.
- ReleaseCandidat 3y agoAs I've already said, nowadays there are const generics which do (almost) the same. But before them, these were the only way to use integer values in generics. They came with 1.51: https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html
- bicepjai 3y agoLike Object Oriented Programming, Type State Programming is a design paradigm. Using them in appropriate scenarios are very powerful. I am a wannabe Rustacean.
- wiseowise 3y ago> Like doing planks for example. I have never needed to plank "in practice" other than to exercise. You need it every day to, you know, hold that meat on your carcass.
- orlp 3y agoOne practical use case is for dimensional analysis. A type is then a k-tuple of type-level integers where k is the number of primitive units, e.g. (kg, m, s). Then m^2 / kg would be the tuple (-1, 2, 0). Multiplying two quantities adds the tuples elementwise. For example multiplying the above type by a quantity of type kg / m / s (corresponding to (1, -1, -1)) would give (0, 1 -1), which is the correct m / s. Addition would only be allowed if the types are equal.
- ReleaseCandidat 3y agoThis doesn't work with dimensionless numbers, as they would need to have e.g. the type `(0, 0, 0)` for multiplication but `(-1, 2, 0)` or `(0, 1 -1)` for addition. Edit: I've just realised that that's actually correct ;)
- queuebert 3y agoThis could be fine, because in science we rarely add dimensionless numbers. Usually they are a scaling factor (i.e. multiplicative).