On Thu, Feb 21, 2013 at 7:50 PM, Ashish Myles <[email protected]> wrote:
> Well, I eventually figured out how to get things compiling, but it was
> highly non-obvious. I would appreciate it if someone could shed some light
> on why things behave this way so that I may learn to visually "see" the
> error.
>
> Say we have the following struct
> pub struct Vector3<T> {
> priv mut m_v: [T * 3]
> }
>
> 1. The following fails because it says it can't find <T> in the second
> line.
> pub pure fn foo<T : Zero>() -> Vector3<T> {
> Vector3<T> { mut m_v: [Zero::zero(), Zero::zero(), Zero::zero()] }
> }
> Changing it to
> pub pure fn foo<T : Zero>() -> Vector3<T> {
> Vector3 { mut m_v: [Zero::zero(), Zero::zero(), Zero::zero()] }
> }
> works. I had compared against core::DVec to avoid strange errors, but I
> seemed to have overlooked the lack of type in the constructor there. Why
> is the redundant inclusion of <T> bad? If anything it would allow the
> compiler to point out an error if the types didn't come out to be as
> intended.
>
You need to write it as Vector3::<T>. Most of the time you don't actually
need to specify as it can be inferred. And actually, the error message is
still the same when I tried with and without the ::<T> for mismatched types.
>
> 2. Most of my other issues were multiple cases of this error. The
> following invocation of the function above fails with "unresolved name: int"
> let v = foo<int>();
> Removing the explicit type specialization works, but requires an explicit
> type declaration to be unambiguous.
> let v : Vector3<int> = foo();
> Why could I not be specific with the type parameter to the function? Is
> there an alternative meaning with which it clashed?
Same as above, so you'd write:
let v = foo::<int>();
>
>
> Ashish
>
>
> _______________________________________________
> 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