This would be amazing. At the moment the [T,..n] types are pretty damn useless
when it comes to generics.
Mathematics, science and units of measure libs would find constant
parametrisation most useful.
I could imagine something like:
fn dot<T: Ring, N: uint>(a: [T, ..N], b: [T, ..N]) -> T { … }
or
// Forgive me if I get these dimensions around the wrong way!
fn mul_mat<T: Ring, M: uint, N: uint, O: uint>(a: &[[T, ..N], ..M], b: &[[T,
..O], ..M]) -> [[T, ..N],..O] { … }
fn transpose<T: Ring, M: uint, N: uint>(a: &[[T, ..N], ..M]) -> [[T, ..M],
..N] { … }
~Brendan
On 23/08/2013, at 3:22 PM, Geoffrey Irving <[email protected]> wrote:
> Does rust have compile time sized arrays, equivalent to the following C++
> definition?
>
> template<int d,class T> struct array {
> T x[d];
> };
>
> More generally, is it possible to parameterize types by integers, so that
> types like the above can be built up?
>
> Finally, is it possible to parameterize functions over integers, as in
>
> fn concat<T,a,b>(x : array<a,T>, y : array<b,T>) -> array<a+b,T> { ... }
>
> If integer type arguments aren't built in, is it possible to type the concat
> function using a type-based encoding of naturals?
>
> Thanks!
> Geoffrey
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev