Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator dispatch: T op 1.0 works, but 1.0 op T doesn't #19035

Closed
japaric opened this issue Nov 17, 2014 · 2 comments
Closed

Operator dispatch: T op 1.0 works, but 1.0 op T doesn't #19035

japaric opened this issue Nov 17, 2014 · 2 comments
Labels
A-type-system Area: Type system

Comments

@japaric
Copy link
Member

japaric commented Nov 17, 2014

STR

Given the proper (commutative) Add/Mul implementations. (See this playpen link)

const I: Complex<f32> = Complex { re: 0., im: 1. };

let z = I * 3.;  // OK
let z = I + 3.;  // OK
let z = 3. * I;  // Err
let z = 3. + I;  // Err

Output

error: mismatched types: expected `_`, found `Complex<f32>` (expected floating-point variable, found struct Complex)

@nikomatsakis Could this work in the future? It would be great if could type 3. + 4. * I instead of I * 4. + 3., the former feels more natural.

japaric pushed a commit to japaric-archived/complex.rs that referenced this issue Nov 17, 2014
@nikomatsakis
Copy link
Contributor

Hmm. Yeah, I think we can make this work without too much difficulty, I kind of didn't realize it wouldn't work already, but I can see why it doesn't. It's (I believe) specific to the builtin types like int/float/etc.

@japaric
Copy link
Member Author

japaric commented Nov 17, 2014

@nikomatsakis awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
3 participants