Re: [rust-dev] Parametrizing traits by integers (or equivalent behavior)

2013-02-18 Thread Patrick Walton

On 2/18/13 9:56 PM, Ashish Myles wrote:

As traits are not parametrized by integers, and macros don't seem to be
the right tool for this, is there some other language feature that could
help me get a similar effect?


You need to use macros right now. There has been quite a bit of 
discussion of GHC-like type-level numeric literals (or just traits 
parameterized by constants) in the past, and that feature might make it 
in at some point. It's certainly a common feature request.


Patrick

___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


[rust-dev] Parametrizing traits by integers (or equivalent behavior)

2013-02-18 Thread Ashish Myles
Firstly, as this seems to be the only discussion mailing list for rust, I
presumed that this might be a good place to ask newbie-ish questions.
Please correct me if I am wrong.  (I have previously played around with D,
which has separate mailing lists for learners.)
I am particularly interested in implementing and porting little utilities
to try to get a better understanding of how well the type system supports
(or gets in the way) of practical problems. I do understand rust is well in
the alpha stage and I don't have any problems with rust modifications
breaking my code.


Secondly, I was wondering how one would go about writing a rust equivalent
of the following C++ class for creating static-sized arrays interpreted as
vectors.

template 
class Vector {
public:
enum { N = _N };

private:
T m_v[N];
};

As traits are not parametrized by integers, and macros don't seem to be the
right tool for this, is there some other language feature that could help
me get a similar effect?

Thanks.
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev