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

Open
syeerzy opened this issue Jul 2, 2019 · 8 comments

Comments

Projects
None yet
4 participants
@syeerzy
Copy link

commented Jul 2, 2019

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

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

This comment has been minimized.

Copy link
Contributor

commented Jul 2, 2019

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

@dsyme

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.