by pyrale · 2y ago · 0 comments
With your solution, if too modules define traits with identical type signatures but different implementations, it would be impossible for the compiler to decide which impl to use.
When calling a function, compiler would check separately for existence of each function defined in the trait. That is a trait would be just like any other type alias so that you do not need to repeating complex function names everywhere:
You could write:
trait Iterator = fn next<T>(&mut self) -> Option<T> + fn len(&self) -> usize
fn filter(iter: impl Iterator)
but that would be just syntactic sugar for this: fn filter(iter: fn next<T>(&mut self) -> Option<T> + fn len(&self) -> usize)
Basically removing traits alltogether, just relying on functions.If a type A defined in module_a doesn’t have the functions defined in its module, should it still be filterable?
If the required function is defined in a module_b should A be filterable?