-
Notifications
You must be signed in to change notification settings - Fork 15
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
Tagged Unions #751
Comments
Tagged Unions + (As Is) EnumsAfter some thinking I've decided that
The last point is questionable depending on how this will affect match/switch functionality. If having only unions with their "tags-only" will allow to dramatically simplify their implementation or end-user API, then maybe we will go full Rust approach. Anyway, here are some examples. Suppose you have
And you wanna have type
It's not perfect due to lack of
Props and Cons:
Implementation Tips
Last step will allow to implement pattern matching on tagged unions (not sure what's the API and implementation for that though) |
Just an example of perfectly designed pattern matching on tagged union via
Match looks similarly
|
Related to #747 #726 #725 and #749
Problem
Current way of dealing with unions is by checking their actual structure at runtime. TypeScript does the same thing (a pattern of adding
kind
/tag
field manually for exactly that is somewhat common), but TS compiler has rather powerful type-inference (see e.g. type-guard feature), which isn't the case in Nevalang (original goal was to make it closer to Go in terms of simplicity). At the end of the day we 1) cannot follow Rust/Haskell like approach with pattern matching on unions because they are untagged (we don't know at runtime what union member it is) and 2) it's not clear if TS-way of doing things will work out for us.Proposal
Proposal is to add some more type information to runtime. Specifically make unions tagged, so it's possible to use
match
/switch
to do branching on union messages.The text was updated successfully, but these errors were encountered: