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

Typeclass/interface implementation #1227

Closed
jwise opened this issue Nov 30, 2011 · 11 comments
Closed

Typeclass/interface implementation #1227

jwise opened this issue Nov 30, 2011 · 11 comments

Comments

@jwise
Copy link
Contributor

jwise commented Nov 30, 2011

This is a stub bug, tracking @marijnh's efforts in implementing typeclasses. Created so that I could link to it from another bug.

More detail: https://mail.mozilla.org/pipermail/rust-dev/2011-November/001010.html

@jwise
Copy link
Contributor Author

jwise commented Nov 30, 2011

Oops, tagged the wrong Marijn. Now tagging @marijnh.

@marijnh
Copy link
Contributor

marijnh commented Nov 30, 2011

@boggle
Copy link
Contributor

boggle commented Dec 1, 2011

I like the direction this is taking, especially the unification of static type classes and the proposal for boxed existentials (interface, value).

Have added an idea on how to add delegation to the wiki.

@ghost ghost assigned marijnh Dec 15, 2011
marijnh added a commit that referenced this issue Dec 16, 2011
marijnh added a commit that referenced this issue Dec 16, 2011
No conflict resolution or polymorphism yet.

Issue #1227
marijnh added a commit that referenced this issue Dec 16, 2011
Get rid of expr_self_call, introduces def_self. `self` is now,
syntactically, simply a variable. A method implicitly brings a `self`
binding into scope.

Issue #1227
marijnh added a commit that referenced this issue Dec 16, 2011
marijnh added a commit that referenced this issue Dec 16, 2011
Something will still have to be done to the AST to make it possible to
say `x.foo::<int>()`, since currently field access never allows type
parameters.

Issue #1227
marijnh added a commit that referenced this issue Dec 16, 2011
(No one is actually reading it yet.)

Issue #1227
marijnh added a commit that referenced this issue Dec 18, 2011
And fix a bug where importing anything from an external module would
import all impls in the module.

Issue #1227
marijnh added a commit that referenced this issue Dec 18, 2011
We should probalby warn when defining a method foo on {foo: int} etc.

This should reduce the amount of useless typevars that are allocated.

Issue #1227
marijnh added a commit that referenced this issue Dec 19, 2011
This way, you can explicitly provide type parameters when calling a
generic method.

Issue #1227
marijnh added a commit that referenced this issue Dec 19, 2011
The parameters of the impl weren't being combined in the right way
with the parameters of the methods. The test worked only by accident.

Issue #1227
marijnh added a commit that referenced this issue Jan 2, 2012
Extern interfaces still don't get recognized.

Issue #1227
marijnh added a commit that referenced this issue Jan 2, 2012
@kud1ing
Copy link

kud1ing commented Jan 3, 2012

I am not sure, does the current approach/plan include default implementations?
For example the interface

iface seq<T> {
    fn len() -> uint;
    fn iter(block(T));
}

could implement a function any() like vec::any() and it would be available to all sequences like list, string etc.

@marijnh
Copy link
Contributor

marijnh commented Jan 3, 2012

Not in the first iteration. They're probably useful enough to be included at some later point.

marijnh added a commit that referenced this issue Jan 3, 2012
Reached a point where simple uses of interfaces without bounds work.

Issue #1227
marijnh added a commit that referenced this issue Jan 3, 2012
The trick of interpreting parameters to the iface type as parameters
to the impl was just too magical.

Issue #1227
@marijnh
Copy link
Contributor

marijnh commented Jan 3, 2012

@kud1ing
Copy link

kud1ing commented Jan 3, 2012

Very nice.
I catch myself thinking "this should be implemented using type classes / interfaces" very often recently.

@kud1ing
Copy link

kud1ing commented Jan 3, 2012

I wonder whether we should drop "of":

impl of to_str for int

vs

impl to_str for int

The latter contains less words and characters to mentally process, but has no diminished clearness to me.
Or is necessary syntax-wise?

@marijnh
Copy link
Contributor

marijnh commented Jan 3, 2012

We can't drop of, it is needed to allow forms where a specific name for the impl is given, and for impls without an explicit interface.

marijnh added a commit that referenced this issue Jan 4, 2012
Aligning the type parameters of the ifaces, impls, and methods
correctly in typeck is almost brain surgery. Seems to work now for
everything I threw at it, but might still break in other corner cases.

Issue #1227
marijnh added a commit that referenced this issue Jan 4, 2012
I.e. fn foo<T: seq<T>>(...). This leads to weird circularities that seem to
never make any sense, so it seems prudent to forbid it.

Issue #1227
marijnh added a commit that referenced this issue Jan 4, 2012
marijnh added a commit that referenced this issue Jan 5, 2012
Also, move checking of ifaces into the collect phase of typeck
to give further passes some guarantees.

Issue #1227
marijnh added a commit that referenced this issue Jan 5, 2012
@marijnh
Copy link
Contributor

marijnh commented Jan 5, 2012

The basics are working now. I've split off the remaining work into #1436 #1437 #1438 and #1439 . Closing this.

@marijnh marijnh closed this as completed Jan 5, 2012
@kud1ing
Copy link

kud1ing commented Jan 6, 2012

Have you found that naming implementations is strictly necessary?
For importing/exporting i'd think we could just import/export the implemented functions, can't we?

bjorn3 added a commit to bjorn3/rust that referenced this issue May 15, 2022
Only enable JIT tests on x86_64
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
* Improve mem::swap test to cover more types

* Remove the mem::swap() hook
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

4 participants