morganstanley / hobbes

A language and an embedded JIT compiler

Home Page:http://hobbes.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why can I define a record with numeric field ids?

adam-antonik opened this issue · comments

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.

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.