-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Generic impl selfs don't really work #814
Comments
script;
struct DoubleIdentity<T, F> {
first: T,
second: F
}
fn double_identity<T, F>(x: T, y: F) -> DoubleIdentity<T, F> {
DoubleIdentity {
first: x,
second: y
}
}
fn main() -> bool {
let double_a = double_identity(true, true);
let double_b = double_identity(10u32, 43u64);
// for testing annotations
let double_a: DoubleIdentity<bool, bool> = double_identity(true, true);
let double_b: DoubleIdentity<u32, u64> = double_identity(10u32, 43u64);
double_a.first
}
impl DoubleIdentity<T, F> {
fn test(a: T) { }
} |
An even simpler example seems to have the same problem: script;
struct DoubleIdentity<T> {
first: T,
}
impl DoubleIdentity<T> {
fn test(a: T) { }
}
fn main() {
} |
Are we wanting this syntax:
or this syntax (what Rust does):
CC @adlerjohn @sezna |
We discussed this briefly and I think the simpler syntax is sufficient for us, although I think we should discuss it. |
Personally I feel that this syntax: impl<T, F> DoubleIdentity<T, F> {
fn test(a: T) { }
} would be a preferable developer experience on Sway. Users will either 1) recognize the syntax coming over from Rust, or will 2) not realize and just acknowledge it as slightly cumbersome at worst. What I want to avoid is a situation in which a Rust person is using Sway and the language constructs for Sway generics diverts their expectations. I feel that if the implementation and use-case for Sway generics is the same as for Rust generics, then the syntax should be the same. |
I was wondering why there is this redundancy. From the book:
So it's to ensure that |
Is this a similar issue? script;
struct Wrapper<T> {
value: T,
}
impl Wrapper<T> {
fn foo(self) {
}
}
fn main() {
let f: Wrapper<bool> = Wrapper { value: true };
f.foo()
}
There's no error if you pass |
Yes, monomorphizing on structs and enums was not finished. It was only fully implemented for functions. I'm wrapping that up on my branch right now: #625 |
title
The text was updated successfully, but these errors were encountered: