Proposal: let's call polymorphic variants 'hash variants'

I can’t be the only one getting tired of repeatedly typing out ‘polymorphic variants’. Since ReScript is doing its own thing, and controls its own docs, how about calling them ‘hash variants’ instead? I think it’s succinct, easy to type and say, descriptive of what the variants look like, and last but not least, anything with the word ‘hash’ sounds cooler. Hashtag hash variants?


In the docs, we shortcut them to “poly variants”, which has the same character count as “hash variants”. IMO hash sounds confusing, bc I would kinda think they are related to things like hash maps?


I like hash variants! Yes, I agree it might be confusing with regards to hash maps etc, but it does summarize the syntax really well (it’s a variant… with a hash… :smile:).

it is a good idea.
I suggest the name: structural variant, it is structural instead of nominal.
Unlike native, there is no hash involved. poly variant is a bit confusing as well, since normal variant is polymorphic too.


That’s a great suggestion too. I like it all :laughing:

I like the idea of making the concept more typing friendly, but I would rather avoid the hash term, because it would raise some (unnecessary) questions to new users:

  • Hashing is performed at compile time or at runtime?
  • Is it possible to get hash collisions between variants?
  • Using variants impacts compile/run time because of hashing?

Obviously none of these questions make really sense in this context, but they are legitimate doubts when hashing algorithms are involved. And even if the actual implementation could rely on hashing to discriminate variants, it should not be necessary to expose the implementation method with the name of the feature.

That’s basically the “sophisticated” thought process that went into using # =P. Jordan was a huge champion of this triple analogy, and now we finally got to do it in the syntax.

Believe it or not, yes, and that’s was the perfect combination of rare and obscure compiler stuff that made us pull out the hashing part. Nowadays though if we go with hash variant, it’d designate the look more so than the semantics. Which is kinda fine too.

Structural variant is the most proper name, though it’s as hard to write. If we can find a nice synonym or shorthand for it then yeah we can consider mass changing the docs (let’s not do this too often though please) and nudge all userland ReScript-only libs to update. Benefits of the control indeed.


How about open (structural) vs closed (nominal) variants?

1 Like

I think that might be confusing as the structural variants (look, I used it!) can be “open and closed” (probably not the exact right terminology, but at least my mental model) themselves, ie [> #some | #thing] vs [ #some | #thing].


“Hash variant” also has the advantage of being intuitive to search for. If someone encounters #foo for the first time and wants to learn what it is, searching the docs (or Google) for “hash” will yield the correct results more easily.

I personally don’t mind “polymorphic variant,” since I just call them “polyvars” most of the time, but I admit that both terms aren’t easy to learn or discover for a newcomer.


Though I prefer any of “poly” (as a contraction), “hash”, or “structural”, I feel compelled to point out that “duck” (as in “duck typing”) also has 4 letters and is widely understood in this context to mean the same as “structural”.

Duck variants?