You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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".
typeregularVariant = {
| CaseOne of argOne argTwo
| CaseTwo};typesomeHashTags = {
| #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 literallyhashedtags. 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.
The text was updated successfully, but these errors were encountered:
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.
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.
myVar = (
HeyThere,Goodbye);
without any type definition.Now, much later on, I would also later suggest the following: Change the back tick to
#
and introduce them as "hash tags".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.
The text was updated successfully, but these errors were encountered: