-
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
Compiler should infer union case names from known type information #1074
Comments
This is related to several other quirks, often when mixing unions and modules with the same name. Definitely in favor of this. |
I suspect there are cases where this could be a breaking change, at least we'd need to be very careful An example is where active patterns are in scope, but the union cases are not: module M =
type U = A of int | B
let (|A|_|) (x: M.U) = Some 3
let f (x: M.U) =
match x with
| A v -> v
| _ -> 4
f (M.A 5) Today this returns |
Very much in favor of this. Currently using Fable.React is annoying because of duplicated case names across HTMLAttr, CSSProp, and SVGAttr. |
This feature would be a tremendous win for domain driven design situations where union types are treated as sets. In such cases elements of the sets have the same name. Naturally one typically writes many functions that cast between the sets. Currently such code is overly verbose and not F#-like. Perhaps there is a way to add the feature while retaining the backwards compatibility. |
@Happypig375 Very much agree with you, but I believe both mechanisms are important. In certain cases I prefer DUs to curb the chaos. The two RFCs would be a TREMENDOUS step forward. Wondering if you have ideas on how we could increase their visibility? |
Perhaps this could be solved by making type-directed resolution the tiebreaker, when name-directed resolution is found to be ambiguous. Here's another potential corner case showing that it would be more nuanced than just giving active patterns "higher precedence:" type IFoo = interface end
let (|A|_|) (x: IFoo) = Some 3
type U =
| A of int | B
interface IFoo
let f (x: U) =
match x with
| A v -> v
| _ -> 4
f (A 5) |
I propose we enable the compiler to infer the proper union case name in a
match
statement from known type information.The existing way of approaching this problem in F# is that the compiler uses the last type that is declared. It's confusing b/c it can also matter which order your
open
statements are in.Below is an example of code that should compile:
Pros and Cons
The advantages of making this adjustment to F# are:
The disadvantages of making this adjustment to F# are ...
I'm not sure
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M
Related suggestions: (put links to related suggestions here)
I filed this issue: dotnet/fsharp#12131
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: