Hey, thanks for the reply!

(minor correction for myself, I meant to say submatrix rather than cofactor)

Using Peano numbers is quite an interesting solution..

The point of it would be to make arbitrarily sized matrices that will
detect as
many errors as possible at compile time..

However. With Peano numbers you can really only add numbers right? Which
makes it problematic in the case of submatrix, where you actually end up
with
a matrix that has one row and one column less than the original.

I guess you could work around it somehow by adding a Prev type or something
but then you run in to issues when you compare types that got to the same
dimension
through different ways. So you'd have to like make a complicated macro or
something
to find what the number represented by the Peano ish number is..



On Sun, May 25, 2014 at 7:37 PM, Matthieu Monrocq <
[email protected]> wrote:

> It's been discussed, but there is still discussion on the best way to
> achieve this.
>
> At the moment, you should be able to get around it using Peano numbers [1]:
>
> struct Zero;
>
> struct Succ<T>;
>
> struct Matrix<T, M, N> {
>     data: Vec<T>,
> }
>
> fn cofactor<T, M, N>(
>     m: Matrix<T, Succ<M>, Succ<N>>,
>     row: int,
>     col: int
> ) -> Matrix<T, M, N>
> {
>     Matrix::<T, M, N>{ data: vec!() }
> }
>
>
> Of course, I would dread seeing the error message should you need more
> than a couple rows/columns...
>
> [1] http://www.haskell.org/haskellwiki/Peano_numbers
>
>
> On Sun, May 25, 2014 at 7:25 PM, Isak Andersson <[email protected]>wrote:
>
>> Hello!
>>
>> I was asking in IRC if something like this:
>>
>> fn cofactor(m: Matrix<T, R, C>, row, col: int) -> Matrix<T, R-1, C-1>
>> {...}
>>
>> was possible. I quickly got the response that generics doesn't work with
>> integers. So my question is, is there anyway to achieve something similar?
>>
>> Or would it be possible in the future to do generic instantiation based
>> on more
>> than just types.
>>
>> Thanks!
>>
>> _______________________________________________
>> 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

Reply via email to