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

Syntax Proposal: Hash Tags - a way to think about polymorphic variants. #31

Open
jordwalke opened this issue Jan 3, 2016 · 1 comment
Labels
RFC For larger proposals/ideas that will need discussion

Comments

@jordwalke
Copy link
Member

Okay, this admittedly of little consequence because I wouldn't really encourage the use of polymorphic variants for anyone but experts, but it might be a good idea, so I'll write it down:

First, some background on polymorphic variants.

  1. Both regular variants and polymorphic variants are both considered "tagged variants". Their names are kind of like name tags, and this is well established terminology.
  2. Polymorphic variants do not require type definitions even though you can chose to define types for them. Otherwise, you are free to just start using them like myVar = (HeyThere, Goodbye); without any type definition.
  3. They are still checked against pattern matching just like regular variants, so they are very type safe.

Now, much later on, I would also later suggest the following: Change the back tick to # and introduce them as "hash tags".

type regularVariant = {
   | CaseOne of argOne argTwo
   | Case Two
};

type someHashTags = {
   | #Yolo
   | #NoFilter of url
};

Now hear me out. I'm genuinely not trolling you all, and it's not just a random cheeky topical reference to social media. The way polymorphic variants work, is that their runtime representation is literally a hash of their tag text - this enables efficient separate compilation among other things. But there is also a parallel to common notion of "hash tags" today. Here's a summary of my justification.

  • Polymorphic variants are literally hashed tags. On that basis alone, it would not be a horrible name for them.
  • The single backtick is troublesome because in github/phabricator source comments, you can't express a single backtick without googling the special convention (I had to in order to figure out how to give the backtick examples at the very top).
  • They do have a conceptual link and similarity to "Hash tags" as used in social media, in that they aren't things that need to be predefined anywhere - they're both symbols that gain meaning simply by the act of being expressed. The fact that there is a conceptual parallel to a familiar concept, as well as a familiar visual/syntactical style makes them easy to remember and easier to introduce to people.
@yunxing
Copy link
Contributor

yunxing commented Jan 3, 2016

I don't have a strong opinion about choosing between hashtag or backtick. I do like the consistent way of using { } to declare a variant type instead of using [ ] for polymorphic variant types -- [ `C of int ] is too much like declaring an array type.

@chenglou chenglou added the Syntax label May 5, 2016
@jaredly jaredly added RFC For larger proposals/ideas that will need discussion and removed Syntax labels Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC For larger proposals/ideas that will need discussion
Projects
None yet
Development

No branches or pull requests

4 participants