4 ms·
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+
by SkiFire13 3y ago
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.
- ReleaseCandidat 3y agoHow 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]`?
- madsbuch 3y agoyou implement the function recursively and let the compiler derive a proof by induction.