News for hackers. Stuff that matters.
Re:Doing First Grade Math in Rust's Type System by SkiFire13 on Saturday January 13, 2024 @06:31AM (#38979050)
As others mentioned, nowadays const generics replace this technique for most problems. This technique however is still useful if you need something like `[T; A+B]` (an array whose length is the sum of two generic constants), which is not yet possible with const generics.
Re:Doing First Grade Math in Rust's Type System by ReleaseCandidat on Saturday January 13, 2024 @06:59AM (#38979194)
How do you prove to the type-checker that e.g. `append(v: [T, N], w: [T, M]) -> [T, N + M]`? Or, to make it easier, that just `append(v: [T, N], x: T]) -> [T, N + 1]`?
Re:Doing First Grade Math in Rust's Type System by madsbuch on Saturday January 13, 2024 @07:41AM (#38979433)
you implement the function recursively and let the compiler derive a proof by induction.