Re: [rust-dev] parameterizing types and functions by integers
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 dotT: Ring, N: uint(a: [T, ..N], b: [T, ..N]) - T { … } or // Forgive me if I get these dimensions around the wrong way! fn mul_matT: Ring, M: uint, N: uint, O: uint(a: [[T, ..N], ..M], b: [[T, ..O], ..M]) - [[T, ..N],..O] { … } fn transposeT: Ring, M: uint, N: uint(a: [[T, ..N], ..M]) - [[T, ..M], ..N] { … } ~Brendan On 23/08/2013, at 3:22 PM, Geoffrey Irving irv...@naml.us wrote: Does rust have compile time sized arrays, equivalent to the following C++ definition? templateint 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 concatT,a,b(x : arraya,T, y : arrayb,T) - arraya+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 Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
[rust-dev] parameterizing types and functions by integers
Does rust have compile time sized arrays, equivalent to the following C++ definition? templateint 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 concatT,a,b(x : arraya,T, y : arrayb,T) - arraya+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 Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev
Re: [rust-dev] parameterizing types and functions by integers
Thanks for the quick reply (also adding back the list). Geoffrey On Thu, Aug 22, 2013 at 10:28 PM, John jmgro...@gmail.com wrote: For the moment, no, that's not possible. On Aug 22, 2013 10:23 PM, Geoffrey Irving irv...@naml.us wrote: Does rust have compile time sized arrays, equivalent to the following C++ definition? templateint 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 concatT,a,b(x : arraya,T, y : arrayb,T) - arraya+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 Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev ___ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev