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

Unify two Real types into one that is precise enough #30

Open
gnzlbg opened this issue Sep 18, 2017 · 2 comments
Open

Unify two Real types into one that is precise enough #30

gnzlbg opened this issue Sep 18, 2017 · 2 comments

Comments

@gnzlbg
Copy link

gnzlbg commented Sep 18, 2017

Given:

fn add<T: Real, U: Real>(x: T, y: U) -> ??? {
  x + y
}

I'd like to fill the ??? with either T or U, depending which one is wider. What's the alga way of unifying Reals in computations?

@sebcrozet
Copy link
Member

alga does not unify computations between two distinct types. Such unification rules would be very application-specific. So alga won't cover this use-case. Perhaps it will be supported in the future when specialization is possible in Rust in order to allow users to specialize their own unification rules whenever the default one provided by alga does not fit.

So right now your only option is to implement Add for your types and add a trait bound:

fn add<T: Real + Add<U>, U: Real>(x: T, y: U) -> T::Output {
  x + y
}

@WaDelma
Copy link
Contributor

WaDelma commented Sep 18, 2017

Or you can convert either x to U or y to U.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants