Lurker News
I know there are classics that get posted every time this question comes around, so bias them towards more recent ones :)

Comments (192) 77 threads

Show all comments

Showing thread 7 of 77

chrisdone2 replies#
A paper that profoundly influenced my language design: “Programming with Polymorphic Variants” https://caml.inria.fr/pub/papers/garrigue-polymorphic_varian...

And the earlier paper “A Polymorphic Type System for Extensible Records and Variants” https://web.cecs.pdx.edu/~mpj/pubs/96-3.pdf
Row types are magically good: they serve either records or variants (aka sum types aka enums) equally well and both polymorphically. They’re duals. Here’s a diagram.

              Construction                Inspection

    Records   {x:1} : {x:Int}             r.x — r : {x:Int|r}
              [closed]                    [open; note the row variable r]

    Variants  ‘Just 1 :       case v of ‘Just 0 -> ...
              [open; note the row var v]  v :
                                          [closed]
Neither have to be declared ahead of time, making them a perfect fit in the balance between play and serious work on my programming language.
anchpop#
I love polymorphic records/variants. Variants particularly are amazing for error propagation. Records of course are useful in many of the same places tuples and structs are. The main reluctance I have is whether to allow duplicate entries in records. If you allow them, many things become much easier, but they make records inherently ordered when they weren’t previously