Short syntax for impl generic params #2945
spapinistarkware
started this conversation in
General
Replies: 2 comments 2 replies
-
I would suggest making Copy/Drop implementations implicitly generated if needed. Other suggestions: fn foo<T: Copy + Print>(...)
// or
fn foo<T: Copy<T> + Print<T>>(...)
// Can also be used like
fn foo<T: Copy<Option<T>> + Print<Option<T>>>(...)
// For naming:
fn foo<T: TCopy(Copy<T>) + TPrint(Print<T>)>(...) Rust-like 'where' syntax: fn foo<T>(a: T)
where Option<T>: Copy + Impl The where syntax in particular easily supports naming things (example syntax here): trait MyTrait {
fn foo<T>(a: T)
where Option<T>: Copy + Impl
}
impl MyImpl of MyTrait {
fn foo<T>(a: T)
where NamedTC(Option<T>): Copy + Impl
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
For functions a hybrid of rust can be used (because Cairo doesn't have implicit self we must be explicit anyways) fn foo<T>(a: SomeTrait<T> + Copy<T>, b: Option<T>) {} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Today we have this syntax:
It's not very ergonomic. We have a few suggestion for additional syntax to reduce it.
Here, if the generic param is a path with generics, then it is considered as an unnamed impl generic param.
A caveat of this is that traits with no generic will have to be specified like this:
MyTrait<>
, unless using the longer syntaxSame as the previous, but add
impl
before:It's a bit more explicit but less ergonomic. And also avoide the
MyTrait<>
issue.Somehow separate impls from other thing:
This suggestion is kind of vague, sinec we are no certain about the concrete syntax in this suggestion. It does need to hold these requirements though:
i. Be able to specifiy the generic arguments explicitly when needed.
ii. Be able to name them when making an impl function for a trait function:
Other suggestion are welcome.
Beta Was this translation helpful? Give feedback.
All reactions