-
Notifications
You must be signed in to change notification settings - Fork 22
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
Deprecate places where seq
can be omitted e.g. { 1.. 5 }
#1033
Comments
Too much of a special case. If |
I believe you misunderstood the request. In both Also worth noting that |
Oh, |
I think I like this, since it's pretty confusing that you don't need to do |
TBH I think I'd rather force the addition of There are three cases
Only (1) allows you to omit However I do like that The reasons I like
As an aside (really a different issue) we should consider |
seq
can be omitted e.g. { 1.. 5 }
Approving the variation described here: #1033 (comment) |
@edgarfgp & @vzarytovskii regarding dotnet/fsharp#17772 and #1033 (comment): TL;DRIt seems like #1086 (which, incidentally, Don opened after #1033 (comment)) would obviate the need for enabling My understanding of #1033 (comment) is that, if anything, we should deprecate/discourage bare Long answerThis part of #1033 (comment) —
— seems like it would be effectively subsumed by #1086 instead. #1086 would enable let xs : Set<_> = [ x; y ] and let f (xs : Set<_>) = …
f [ x; y ] and let f (xs : Set<_>) = …
let xs = [ x; y ]
f xs That would make it less compelling to enable the omission of let xs = set { x; y } since Don implies in
that we would not enable let f (xs : Set<_>) = …
f { x; y } or let f (xs : _ seq) = …
let xs = { x; y }
f xs and would instead still require
So #1086 would let us address more scenarios more consistently than would allowing the omission of Side noteIt is worth remembering that #1086 would still require explicit let xs : _ seq = seq { x; y } and let f (xs : _ seq) = … in f (seq { x; y }) as mentioned in #1086 (comment):
That is, let xs : _ seq = [ x; y ] or let f (xs : _ seq) = …
f [ x; y ] would still need to eagerly produce a Edit: AddendumWe should also consider what directions we might take with #1044 and #1116 (see also #1317 (comment) and #1317 (comment)). For example, depending on how far we went in treating The syntax let f start finish = for x in start..finish do ignore (float x ** float x) let f start finish = for x in { start..finish } do ignore (float x ** float x) But if (and I'm not saying we necessarily would or should) we went as far as C# does and supported first-class ranges — let range = start..finish — it would seem to be all the more desirable to deprecate Footnotes
|
@brianrourkeboll i do agree that we should work towards type directed user defined collections before any other work on them. Sorry, can't give extended comment right now, mostly reading those from phone, but great analysis and comments, thanks for that! |
@brianrourkeboll Thanks, this is exactly the context I was looking for trying to understand what to do here 👍🏻. Looking at the long term plan I agree in that we should deprecate/discourage bare { start..finish } even we pass to collections.
@vzarytovskii is your comment suggesting to not implement this until #1086 is done ? |
Some examples of existing code that would be affected by warning on Versus ~3.5k public files with https://github.com/search?q=%2Fseq\s*\{\s*-%3F\w%2B\s*\.\.%2F+language%3AF%23+&type=code |
Redefining let (..) _ _ = "lol"
let lol1 = { 1..10 } // val lol1: string = "lol"
let lol2 = seq { 1..10 } // val lol2: char seq = "lol" let (..) _ _ = 99
let lol1 = { 1..10 } // val lol1: int = 99
let lol2 = seq { 1..10 } // error FS0001: The type 'int' is not compatible with the type ''a seq' I think that's all the more reason to deprecate bare
Footnotes
|
In ideal world - yes. But the feature is very big, I think it's fine to meanwhile work on things like this (allow omitting seq when passed to collections constructors). |
Hmm. I wasn't sure whether Don's comment #1033 (comment) really implied that that should be enabled (I guess we really need clarification from him), but that would actually be problematic now with dotnet/fsharp#17387 / #632 in place: type Class () = class end
let objExpr = { new Class () } // Class
let seqExpr = seq { new Class () } // Class seq |
I think it was:
|
I guess it depends exactly what this means:
Does that mean "passed into a collection type's constructor," like I think this part of Don's comment is important:
There's no way for the compiler to know whether a given constructor or function "immediately consumes the sequence eagerly," or whether the return type of a given constructor or function constitutes an eager collection type. |
I think only collection "constructors" - set, dict, list, array.
Yes, that's why if we want to do it now, it will have to be special cased. Which brings us back to the custom user defined collections syntax. |
I personally think we should not make an special case for @dsyme Could you please clarify if this is still applicable ?
As it would actually be problematic now with dotnet/fsharp#17387 / #632 type Class () = class end
let objExpr = { new Class () } // Class
let seqExpr = seq { new Class () } // Class seq Current implementation WIP |
It's not really an applicable comment, even back then - I guess I was saying "I could imagine places where So I think the comment can be largely ignored. It looks like consensus is to go ahead with requiring |
This is completed as per dotnet/fsharp#17387 |
I propose we make this consistent:
Now we don't have to allocate entire lists or arrays just to make sets.
The existing way of approaching this problem in F# is
Pros and Cons
The advantages of making this adjustment to F# are
The disadvantage of making this adjustment to F# is that this may cause confusion as
set
here isn't a computation expression. However, syntax can be quickly learnt.Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: