Mercerenies / tfactor

0 stars 0 forks source link

Record Syntax Sugar #10

Closed Mercerenies closed 4 years ago

Mercerenies commented 4 years ago

With the new module / type system that gave us the solution to #4, we lost our syntax sugar for record types. I'd like to get that back. The syntax will be basically the same, and it will desugar directly to a module with a type declaration inside of it.

As before, when you make a record type, you'll get a module for free which contains helper functions. That module will contain a constructor function and an accessor for each field. The module itself will not be the type (as conflating the two was causing several internal issues), so instead you'll automatically get a type t inside the module (possibly with customizable name). Also, you'll get a fold function *t (again, perhaps customizable). Folds on a product type are slightly less interesting than on general sum-of-product types, but they can still be handy.

Mercerenies commented 4 years ago

Record syntax sugar is back, as of abd1cda. The semantics are as described above. The syntax is identical to before, with the additional restriction that the record constructor must be unique (this, incidentally, also closes #3).