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

Primitive types should be able to implement traits #799

Open
EliasC opened this issue May 4, 2017 · 1 comment
Open

Primitive types should be able to implement traits #799

EliasC opened this issue May 4, 2017 · 1 comment

Comments

@EliasC
Copy link
Contributor

EliasC commented May 4, 2017

We use traits to be able to bound polymorphic types to certain interfaces. For example, you might want to write a function like the following

fun foo[t](x : Eq[t], y : Eq[t]) : bool
  x.eq(y)
end

Currently however, only classes can implement traits, so foo cannot be called with two integers. The smoothest way to implement this would be to have some way of allowing primitive types to implement a trait. One could go the way of Java and have boxed versions of all the primitives, but that would introduce overhead when using primitives in a polymorphic context. On the other hand, without boxing one would have to check dynamically if a polymorphic value is a reference type (which carries its own vtable) or a primitive (whose vtable would need to be stored elsewhere).

This is related to #797.

@supercooldave
Copy link

Isn't there something in @kaeluka's Iter PR for adding traits to existing classes (like Fut)?
Maybe this can be used.

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

No branches or pull requests

2 participants