Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAllow `type` to create an alias for several trait bounds #8634
Comments
This comment has been minimized.
This comment has been minimized.
|
This is a subset of GHC's ConstraintKinds extension, and so also related to higher-kinded generics. |
This comment has been minimized.
This comment has been minimized.
|
It is, but only very weakly; the proposal here is literally just a synonym to make code shorter/nicer, so this could even be implemented via textual substitution, modulo scoping concerns (although this obviously shouldn't be the actual implementation). |
This comment has been minimized.
This comment has been minimized.
|
If you write |
This comment has been minimized.
This comment has been minimized.
|
The syntax could easily be something like trait FooBar: Foo + Bar {}
impl<T: Foo + Bar> FooBar for T {}other than the fact that these generic impls are slightly buggy. I guess a macro that expands to the above (assuming that pattern works) would be a solution. (And the kind "inference" could just be checking that |
This comment has been minimized.
This comment has been minimized.
|
In Haskell the two are indeed equivalent. (Modulo ability to partially apply them which is another higher-kinded generics thing Rust doesn't have.) |
This comment has been minimized.
This comment has been minimized.
|
reusing the type keyword for this would be confusing, as it's not a type at all. perhaps we could have a kind keyword. |
This comment has been minimized.
This comment has been minimized.
|
It is a type, just of a different kind ;), which is not first-class in Rust. Anyway I think the nicest syntax would be:
(but if generic impl bugs can be worked out there's probably not a pressing need) |
This comment has been minimized.
This comment has been minimized.
|
I don't see a compelling need for this, since you can just declare another empty trait that inherits from both. I realize it's somewhat more concise if you have the additional syntax, but it just doesn't seem to add enough value to justify adding a new feature. Closing. |
catamorphism
closed this
Nov 12, 2013
This comment has been minimized.
This comment has been minimized.
|
@catamorphism I think this would be handy for traits that have a number of type parameters i.e. type InputNode = AudioNode<OutputBuffer, OutputSample>;With this I imagine you could write impl InputNode for Synth {}whereas simply deriving from I'm not sure about using the trait InputNode = AudioNode<OutputBuffer, OutputSample>; |
This comment has been minimized.
This comment has been minimized.
|
I also would love to be able to write: pub trait DuktapeEncodable = Encodable<Encoder, DuktapeError>;The workaround is simple enough, fortunately: pub trait DuktapeEncodable: Encodable<Encoder, DuktapeError> {}
impl<T: Encodable<Encoder, DuktapeError>> DuktapeEncodable for T {} |
This comment has been minimized.
This comment has been minimized.
jonysy
commented
Mar 21, 2017
•
|
Similar to @emk's case, I'd love to be able to write: pub trait Blas = Vector<f32> + Vector<f64> + MatrixVector<f32> ...instead of: pub trait Blas: Vector<f32> + Vector<f64> + MatrixVector<f32> ... { }
impl<I: Vector<f32> + Vector<f64> + MatrixVector<f32> ...> Blas for I { } The first example is clear. The second, not so much.. @catamorphism will you consider reopening this issue? |
This comment has been minimized.
This comment has been minimized.
jonysy
commented
Mar 21, 2017
This comment has been minimized.
This comment has been minimized.
jonysy
commented
Mar 21, 2017
|
Ignore my comments. RFC#1733 is moving in this direction. |
huonw commentedAug 20, 2013
e.g.
This is similar to defining a trait inheriting from both (
trait Alias: Foo + Bar {}) but it's purely a synonym and doesn't have to beimpl'd separately.