4 ms·
Speaking of replacements, this is my big complaint about Rust's type system - it has no replacement for templates. Instead, it has two ways of doing parametric
by t8sr 4y ago
Speaking of replacements, this is my big complaint about Rust's type system - it has no replacement for templates.
Instead, it has two ways of doing parametric types like matrices:
1. Using the type system, as seen in e.g. nalgebra (https://docs.rs/nalgebra/latest/nalgebra/base/struct.Matrix.html https://docs.rs/nalgebra/latest/nalgebra/base/struct.Matrix....)
2. Using macros for codegen, as seen in almost all other linear algebra crates, e.g. ultraviolet (https://crates.io/crates/ultraviolet https://crates.io/crates/ultraviolet)
The drawback of (1) is that it's hard to understand or extend, and the type errors are insane, and put Boost to shame. The drawback of (2) is that's just a macro. Of course (1) and (2) are not interoperable.
C++ templates are really underappreciated, because they are a single mechanism that gives you both powerful generics and macro-like codegen, while being easy to adopt gradually. (E.g. you can add concepts when it gets unwieldy, but you don't have to rewrite the whole thing.)
- zokier 4y agoRust has const generics these days that bring true type level numbers, so you can have stuff like this let result: Matrix<i32, 2, 2> = matrix_a * matrix_b; https://github.com/MayorMonty/mtrx https://github.com/MayorMonty/mtrx
- pjmlp 4y agoThey are still relatively limited versus the HKT from C++ templates.
- pjmlp 4y agoI also find that even though it is a language inside a language, it is much easier to keep track of, because it is uses the same C++ language features instead of a special set of macro operators and semantics.