|
|
|
|
|
by nyanpasu64
1897 days ago
|
|
Functions and types can take integers as monomorphization-time template parameters (const generics). It would be nice if you could pass (n, t) where n is supplied at runtime, the type of t depends on the value of n, and the compiler only lets you use t if your code is valid for all reachable values of n. eg. fn(n: usize, arr1: &[i32; n], arr2: &[i32, n]) allowed the function body to assume the two slices can be zipped without losing elements. Note that i don't have enough experience with either dependent types, zz, or wuffs to explain much further. |
|
Const generics aren't dependent types though; you're still dealing with known constants at compile time. For it to be dependent types, you need something like in your latter example, where a type is dependent on an actual _value_ passed to a function at runtime.