-
Notifications
You must be signed in to change notification settings - Fork 309
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
[Proposal] Nestable union types? #2858
Comments
Thanks @cannorin! This looks like a good solution so we don't need to set an arbitrary limit for TS unions. It's a bit more cumbersome but I guess that's ok if it's mainly intended for auto-generated code. What do you think @MangelMaxime @Booksbaum? |
Accessing a nested value is then quite laborious: let a8 : UMore<int, unit, UMore<int, unit, UMore<int, string, unit>>> = !^ "foo"
match a8 with
| CaseMore (CaseMore (Case2 str)) ->
printfn "got %s" str
| _ -> () -> must track how deep nested the Case is (and what actual Case in final nesting) instead of just what index it has. But way better than One consideration is probably how fast RFC 1092 gets implemented -> solves problem without need for nested unions One issue I found: deeply nested unions: let a9 : UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, UMore<int, unit, string>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> = !^ "foo" (repl) -> Compilation takes forever (or cannot resolve at all?). I terminated comilation after a couple of minutes. Unlikely to have such intense union (especially when you only nest after 8 prev values). But possible from a tool like ts2fable. That's going to be a funny debugging session of why the F# compiler doesn't come to an end.... |
Removing arbitrary limitation is always a good thing. Only thing is that the code to access the value is not really easy to read/understand. But like @Booksbaum said, it is probably better than let value = unbox<string> myComplexNestedUnionValue
// to avoid stuff like:
let value =
match a8 with
| CaseMore (CaseMore (Case2 str)) ->
str
| _ -> failwith "unexpected" |
Regarding the problem on creating
Regarding the problem on consuming
|
Since Fable only supports up to 8-union,
ts2fable
has to emitobj
when it encounters 9-union or more.I was experimenting around and got this (live):
So I found that nestable union types are possible even with Fable's limited support to trait (SRTP) calls.
Should we do this? (Modifying
U8
would break the existing codes, so I would addU9
with nest support)The text was updated successfully, but these errors were encountered: