Sesterl icon indicating copy to clipboard operation
Sesterl copied to clipboard

Polymorphic variants

Open michallepicki opened this issue 4 years ago • 1 comments

Are polymorphic variants planned? They are quite useful for error handling. I understand they complicate type checking, and can lead to degraded performance and poor error messages

michallepicki avatar Oct 28 '21 07:10 michallepicki

Although they may well be worth supporting in the future, I don’t have a plan to introduce polymorphic variants now. As you note, polymorphic variants have the following pros/cons compared to (ordinary) variants:

  • Pros:
    • They have extensibility especially useful for representing errors.
  • Cons:
    • They tend to complicate type error messages.

(As to some compiler targets, using polymorphic variants degrade performance. As long as compiling to Erlang, however, probably it does not matter; they can be represented by atoms and tuples as ordinary variants are in the Sesterl compiler.)

In my experience so far, in many cases, error handling can be achieved by using ordinary variants and data abstraction. This may be partly because in Erlang errors are likely to be uniformly handled as anomalies, not as values that should be used for recovery. Thus I’m not so keen on supporting polymorphic variants currently.

If we decide to introduce polymorphic variants in the future, the following row-based theory can probably be used for reference:

The row-based records introduced by #39 is based on this theory.

gfngfn avatar Oct 31 '21 02:10 gfngfn