[RFC FS-1068 Discussion] Open static classes #352
Replies: 54 comments
-
I've recorded two TBD items for this RFC:
|
Beta Was this translation helpful? Give feedback.
-
Some discussion here too: fsharp/fslang-suggestions#383 |
Beta Was this translation helpful? Give feedback.
-
I notice C# lets you do this:
For some reason I thought it only let you open static classes, but it seems you can open any class. I don't quite like that. In F# I was planning this:
(note there is no The catch 22 is that if we go with the F# approach of naked If we go with the F# approach of naked My proposal is that
Do people agree with (1)? It will however mean that the feature doesn't have exact parity with C#.... |
Beta Was this translation helpful? Give feedback.
-
I think that's a reasonable step and gives the majority of the benefit overall. I imagine if the need for opening particular classes with static members is that great, the handling of |
Beta Was this translation helpful? Give feedback.
-
My fear is that we will indeed have to do that, because some important C# DSL API gets shipped without declaring a class So an alternative would be
but that is also kind of a weird position to end in, since auto-complete is not accurate. A final option is simply to allow |
Beta Was this translation helpful? Give feedback.
-
Going with 'open on all', filtering auto-complete is something that's entirely FCS-based? So in theory could be behind a toggle/config option? VS/FSAC/etc could ship with that filter-flag set to true and allow folks to opt-in to overloads if necessary. |
Beta Was this translation helpful? Give feedback.
-
Does autocomplete currently list all available entries? If so, is virtual scrolling / lazy loading an option? Or perhaps only showing the first 50 or so options, which would require typing additional chars to pare the list down. |
Beta Was this translation helpful? Give feedback.
-
What's the rationale for Let's not get fancy with completion. Its job should be to just suggest symbols that are in scope; not need to apply special rules atop the language semantics. |
Beta Was this translation helpful? Give feedback.
-
The rationale would indeed be interesting to know. Though I personally would skip the
Afaics IntelliSense is able to handle that due to its already existing filtering logic: Btw - on this occasion - IntelliSense suggests everything on the first character, even today: It doesn't seems to "disturb" anyone too much as nobody reported that afaik. @dsyme any particular reason why you think it would be a problem listing all types with at least one static member? Is it about non-VisualStudio editors? |
Beta Was this translation helpful? Give feedback.
-
I'm not totally opposed to I think my concern is that |
Beta Was this translation helpful? Give feedback.
-
A quick thought: perhaps |
Beta Was this translation helpful? Give feedback.
-
I'm for just |
Beta Was this translation helpful? Give feedback.
-
I've discussed this with @cartermp and we've decided to go with just plain "open", even though the intellisense lists may end up containing additional elements. |
Beta Was this translation helpful? Give feedback.
-
Just a random thought: I assume this feature makes |
Beta Was this translation helpful? Give feedback.
-
I guess we'll learn over time 🙂 |
Beta Was this translation helpful? Give feedback.
-
@TIHan note we must also do this:
|
Beta Was this translation helpful? Give feedback.
-
Makes sense, we will stop putting the nested types into scope. |
Beta Was this translation helpful? Give feedback.
-
@TIHan We should bring them into scope. I think "preview" is not doing this :-) |
Beta Was this translation helpful? Give feedback.
-
@TIHan The RFC also needs to be udpated to make it clear that method overload sets are not being combined. I think we adjsuted it to combine them and now need to revert that. |
Beta Was this translation helpful? Give feedback.
-
Thanks, that clarifies the resolution for generic members. Iirc this is the same rule as for other stuff in F#: last one wins. |
Beta Was this translation helpful? Give feedback.
-
@dsyme, we can presently extend a type locally (no warning) or elsewhere (warning). Will static types be following the same rules, or will extensions be prohibited? |
Beta Was this translation helpful? Give feedback.
-
Ah, oops. I read it backwards :) - Ok, that shouldn't be a problem. |
Beta Was this translation helpful? Give feedback.
-
I don't think we adjusted combining them yet. I had a PR that did allow it, but now we don't need it. |
Beta Was this translation helpful? Give feedback.
-
Extensions are permitted |
Beta Was this translation helpful? Give feedback.
-
Resolution of three design issues:
|
Beta Was this translation helpful? Give feedback.
-
Regarding 2. isn't the same case with global functions? I mean, if the type defined a I understand it is bad, but it might be that the whole feature is bad in general and it should be used carefully. |
Beta Was this translation helpful? Give feedback.
-
@gusty True, I don't quite understand the resolution since it's no different than any component that does this: module Beef =
let inline ( + ) x y = x - y
let inline ( - ) (x, y) = x = y
open Beef
printfn "%d" (1 + 2) // prints '-1' because '+' is resolved from the module
1 - 2 // error, doesn't resolve that way @dsyme @TIHan why treat operators different just for this feature? |
Beta Was this translation helpful? Give feedback.
-
FWIW I do not believe this quibble should keep us from merging this so we can flight it in previews |
Beta Was this translation helpful? Give feedback.
-
@cartermp @gusty The huge danger is that C# types with operators are designed for opening, but take no consideration that simply adding a If the C# feature isn't affecting the resolution of |
Beta Was this translation helpful? Give feedback.
-
I don't understand this: the example seems to talk about numeric unions, aka, enums, but the text, also in the rfc, seems to refer to F# unions, aka DU's (note that the rfc has an error in the examples here: it shows I can see why we bring DU cases into scope, but I don't see a good reason for bringing CLI enum fields into scope: it's long been a tradition that enums (not DU) must use qualified access. I fear that if we change this, it could cause compatibility issues, or confusion, if both a DU (no qualified access) and an enum (previously qualified access) are brought into scope. I propose to continue requiring qualified access for CLI enums, and only bring DU cases into scope if |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Discussion thread for https://github.com/fsharp/fslang-design/blob/master/FSharp-5.0/FS-1068-open-type-declaration.md
Beta Was this translation helpful? Give feedback.
All reactions