New Draft Tutorial on Polymorphic Variants

If there are details that may be intimidating but still offer a better understanding of how the rest works (or how it relates to PL theory concepts), maybe they could be in those kind of blocks that are hidden by default and you click to expand?

2 Likes

Hello @cuihtlauac,

Here’s my feedback. I started to loose motivation reading about 1/3 through. As has been already said, I think this is because too much emphasis was but on the what rather than the why.

Specifically, I would like to be presented at the start with a problem that can’t be solved easily with “simple variants”, and for which polymorphic variants are an elegant solution.

I would remove the sentence regarding the LLM chatbot because it feels a little off-subject.

Regarding the global documentation effort, I feel some comments are a little harsh. I would say it’s difficult to please everybody.

I was happy to learn what a domain/codomain are here. Maybe referencing prior articles would be useful when using precise but less common terminology.

2 Likes

I would directly introduce parametric polymorphism and structural polymorphism if these are the recognised terms

1 Like

I think the text hints at a limited usecase for polymorphic variants (PV) in the sections “Use-cases” and forward. This is not true, and I think newcomers should get an idea of their big potentials. Sadly this was also the idea I got from RWO once upon a time I read its chapter on them.

The nice ones I’m currently thinking of are:

  • library interfaces: easy-to-understand and expressive phantom types (vs GADTS)
  • using PVs internally in a self-recursive function, where the returned PV-value is a subtype of the internal one
  • using PVs as an alternative subtyping system for “entities” in e.g. a game - here it’s e.g. possible to express that only certain subtypes of the entities are able to collide - while you don’t need to downcast, or check for “isInstanceOf”, an entity as in OOP inheritance
  • having big PV-typed values that are incrementally narrowed throughout branches of the program
  • passing several invariant container-types containing polymorphic variants to operators on these container-types: e.g. for doing E.select in react (FRP) on a set of different events, where each event is mapped to a polymorphic variant
5 Likes

I certainly wouldn’t have been able to come up with most of the use-cases in your list having read the various introductory docs I’ve come across (but never used them).

I can see how more than one example in a tutorial probably wouldn’t be practical, but a link “for a fuller account of polymorphic variants and their uses see …” would be an excellent idea IMHO. I’d certainly enjoy seeing some of these examples.

1 Like