Skip to content
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

Declaration/syntax for sum types/union arrays? #237

Open
jpivarski opened this issue Jul 9, 2019 · 1 comment
Open

Declaration/syntax for sum types/union arrays? #237

jpivarski opened this issue Jul 9, 2019 · 1 comment

Comments

@jpivarski
Copy link

The flip-side of record types (product types), in which each element has an instance of all fields, are tagged union types (sum types), in which each element has an instance of exactly one type from a list of possible types. For example,

union[int32, string]                                     ->   [1, 2, "three"]
union[int32, var * int32]                                ->   [1, 2, [3, 4], [], 5]
union[tuple[int32, int32], tuple[int32, int32, int32]]   ->   [(1, 2), (3, 4, 5)]

This can be implemented, for instance, with an array of tags (types), optional indexes (offsets), and an array for each type. See, for example, the Arrow implementation.

Are there any plans to support specifications of this kind of data?

@nugend
Copy link

nugend commented Aug 13, 2019

Expressing and dealing with variants cogently is an important element of most data processing from messy sources.

I'd like to add that it's important to be able to represent exhaustive and non-exhaustive versions of this as well. The non-exhaustive version is probably sufficient to represent with something like, "I couldn't handle this, so here's the byte sequence that was observed."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants