On 11.08.2013 12:31, Matthieu Monrocq wrote:
I cannot comment on the difficulty of implementation, however I can only join Armin in wishing that if it ever takes off it would be better to make the declaration explicit rather than having to parse the definition of the function to suddenly realize that this is not a simple function but a full-blown generator.
As already mentioned in the response to Armin, Rust's requirement for explicitly declared return types will let you see already in the functions signature whether you are dealing with an iterator.

However, there is a small (technical) problem with writing a function signature like this:
fn generate() -> Iterator<int> {...}
since Iterator<T> is just a trait and can't be returned by value (because its concrete type is not known). We could still allow the above; but it could lead to some confusion as to why it sometimes is allowed to return a trait by value and most of the time it's not. A possible solution for this would be to use some special syntax for yielding functions, such as:
fn generate() -> yield int {...}
where the 'yield int' part could then be replaced with the concrete (generated) iterator type by the compiler. This would make it more explicit that something special is happening here, and it would make the python people happy at the same time :)

-Michael
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to