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

Make "->" works in all for-loop to replace "do yield" #764

Closed
5 tasks done
syeerzy opened this issue Jul 2, 2019 · 9 comments
Closed
5 tasks done

Make "->" works in all for-loop to replace "do yield" #764

syeerzy opened this issue Jul 2, 2019 · 9 comments

Comments

@syeerzy
Copy link

syeerzy commented Jul 2, 2019

I propose we should had the same way to use "->" in all for-loop segments

Now :
for X in XXX do yield YYY ======> for X in XXX -> YYY (OK)
for X=x to y do yield YYY ======> for X=x to y -> YYY (Syntax Error)
for X=x downto y do yield YYY ===> for X=x downto y -> YYY (Syntax Error)

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
  • I or my company would be willing to help implement and/or test this
@Happypig375
Copy link
Contributor

Those two loops are considered "legacy" and should be discouraged, though.

@dsyme
Copy link
Collaborator

dsyme commented Jul 2, 2019

Those two loops are considered "legacy" and should be discouraged, though.

Yes, though I suppose this means we should consider giving deprecation warnings too

@cartermp
Copy link
Member

cartermp commented Jul 2, 2019

I don't really see that as being too good of a route. I'm not sure it's uniformly accepted that the equivalent Array/List/etc combinators are the way forward. Those can also be a bit more annoying to type out since you have to play the game of aligning the ending parenthesis.

@cartermp
Copy link
Member

cartermp commented Jul 2, 2019

Generally I think this should be done for completeness' sake, even though we want people to use the collection functions instead.

@dsyme
Copy link
Collaborator

dsyme commented Jul 3, 2019

I don't really see that as being too good of a route. I'm not sure it's uniformly accepted that the equivalent Array/List/etc combinators are the way forward. Those can also be a bit more annoying to type out since you have to play the game of aligning the ending parenthesis.

The proposition is that these two forms:

for i=x to y do ...
for i=x downto y do ...

should be deprecated in favour of

for i in x .. y do...
for i in x .. -1 .. y do...

@cartermp
Copy link
Member

cartermp commented Jul 3, 2019

Where is this proposed? Also, this would represent a regression, since you can't have the index while you're doing that.

@dsyme
Copy link
Collaborator

dsyme commented Jul 4, 2019

Where is this proposed?

Oh that's what I'm suggesting - that this is the natural way to interpret/resolve/progress this suggestion.

I'm not really pushing it - I'm just saying it would be reasonable to completely remove the for i=x to y do ... and for i = x downto y from the language, since they are redundant (and the bug report is pointing out that these expression forms can't be used with -> in sequence expressions.

These two looping constructs

for i=x to y do ...
for i=x downto y do ...

are only in F# because of OCaml (Note for i in x .. y do ... is an F# invention - OCaml doesn't have it)

Also, this would represent a regression, since you can't have the index while you're doing that.

The loops for i in x .. y do and for i in x .. -1 .. y are still index loops over ranges of integers, the forms are equivalent. Also both are also optimized to C-style for-loops.

@cartermp
Copy link
Member

cartermp commented Jul 4, 2019

Hmmm. Okay, perhaps. I just feel like I'd rather focus on deprecating things that are problematic but possible (e.g, use mutable x = ...), not necessarily things that just feel like they have legacy.

@dsyme
Copy link
Collaborator

dsyme commented Apr 12, 2023

Given that yield is now no longer needed in most situations, I think this is no longer compelling, as you can just use do everywhere.

@dsyme dsyme closed this as completed Apr 12, 2023
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

4 participants