Hacker News new | past | comments | ask | show | jobs | submit login

So for every variant case, you generate a unique integer tag, different from a tag of any other variant cases ever compiled in the future or the past? OCaml, for example, tries to do exactly that by hashing the names of cases in the polymorphic variants, and in case of hash collisions it just gives up [0].

[0] https://schu.be/til-ocaml-polymorphic-variant-hash-collision...




That's correct. No hashes; just string equality on the tag name. Everything gets collapsed to an integer. I'll have to read about why OCaml hashes things. Maybe separate compilation?

Edit: oh, it's unique per compilation and isn't meant to be shared around. The variants are shared with string names in flat scraps (small serialized ASTs)


Yes, separate compilation, and since your language, as I understand it, will support receiving and using scraps from wherever, you'll have to deal with it too unless you insist on strictly source-code sharing only.

You see, those are eternal (well, perennial) problems with distributed code management and every language/computing platform has to deal with them somehow, so that's why I'm interested in what your approach is, especially so since you aim to "solve the software sharability problem".


For the (slow) interpreter, it's just a string. For the compiler, we may end up just using a string in the end too, and interning, and then doing identity equality on the pointer. This is especially cheap because we have small/in-pointer/immediate strings.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: