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

Why can I define a record with numeric field ids? #354

Open
adam-antonik opened this issue May 19, 2020 · 1 comment
Open

Why can I define a record with numeric field ids? #354

adam-antonik opened this issue May 19, 2020 · 1 comment
Assignees

Comments

@adam-antonik
Copy link
Contributor

I just discovered that intV's are allowed as labels to records. So I can write

> {0=0, 1=1}
(0,1)

However doing anything else than exactly creating a tuple, e.g. {1=0, 0=1} or {10=1, x=0} makes things break; generic functions over these objects seem to fail, and :t {10=1, x=0} is reported as (int * )

Is there some reason for this construction? As it stands it can only see it introducing a difficult to track down bug.

@kthielen
Copy link
Contributor

I think that the only reason that this is allowed is because both field projection and construction go through the recfieldname grammar term. Tuple indexing looks like p.3 because tuples can have any size and the Haskell naming convention of fst, snd, thd doesn't scale (what's the name for the 9,237th tuple field?).

Maybe the right way to do this is to validate record construction (rejecting constructions like {1=e, 0=e}).

As you probably guessed, the runtime memory layout of tuples and records is the same, so we settled on using records as the canonical form because that way we don't lose field names.

@kthielen kthielen self-assigned this May 20, 2020
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