-
Notifications
You must be signed in to change notification settings - Fork 797
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
WIP: Prototyping Erased Union types #10566
WIP: Prototyping Erased Union types #10566
Conversation
One thing that is bit bugging me, atm is how to support pattern matching on erased union since the I'll do a few more experimentation how this could be supported. |
…rce as current F# spec
…e order while pretty print
…Solver.fs? Fix minor issue in type relation
@Swoorup There's a lot of good foundational work here. As I mentioned on twitter this will interact with widening, for example to get
to widen both
to work. Plus there is the question of subtyping - which you've made a start on - used in member calls and explicit coercions for example, e.g.
These three things actually use slightly different mechanisms and all three need to be adjusted. The second is actually the hardest because it introduces constrained type variables to represent the flexibility in the use of For (1), in the branch https://github.com/dotnet/fsharp/tree/experiment/widen-literals I started looking at our treatment of widening w.r.t. branching constructs. I'll take a look at resurrecting that. |
@Swoorup I have pushed a set of changes that incorporates feature/auto-widen into this PR and checked that the two features play nicely together. I'm really happy with how this is looking - much more testing is needed of course. If you'd like to hammer on this that would be great. I'll also need to start work on an RFC for feature/auto-widen. Here is a set of working examples: let f1 (x : (int|string|int64)) = printfn "x = %A" x
f1 1
f1 1L
f1 "z"
let f2 (x : (int|string)) = f1 x
f2 1
f2 "z"
let data : (int|string)[] = [| 1; "a"; 4; |]
printfn "data = %A" data
let v = (1 : (int | string))
let v2 : (int | string) = 1
let f() : (int | string) = Unchecked.defaultof<int>
let data2 : (string * (int|string))[] = [| ("a", 1); ("b", ("a" : (int | string)) ) |]
printfn "data2 = %A" data2 |
@Swoorup I added a language feature flag so you will need |
@Swoorup I'd like to suggest we open a new PR from a feature branch |
I agree. Liking how the progress on this has ramped up so quickly. It does seem straightforward. 😄 |
Closing in favour of #10896 Work will now be on feature/erased-unions |
RFC https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1092-anonymous-type-tagged-unions.md
I am currently experimenting hacking the compiler to support union types. I'll admit I don't have much knowledge of the F# compiler and this is a merely an exploration to see if the features would fit well within F#.
What currently works:
type A = (int | (int64 | int16)
is same as((int | int64) | int16)
type C = (int | string)
same as(string | int)
What doesn't:
Would be nice not to have:> _
every time to convert to union type.Links: