brownplt/pyret-lang — pull request #91 by dbp (2013-10-28 00:43:06+00:00)
Title: Adding `datatype` primitive to language, desugar `data` to datatype.

I'm opening this as a pull request because it is quite a big change, and want to be able to incorporate any feedback in before putting it on master.

What this does is add a `datatype` syntactic form, which follows what I proposed on the mailing list:

datatype Foo:
| foo(flda,fldb) with constructor(self): self.{x: 10} end
| bar with constructor(self): self end
end

Right now, the `with constructor` part is required, but that could obviously be made optional. The runtime semantics are that when you construct a `foo`, a record with flda and fldb is created, it is then passed to the constructor, and the result is branded with the foo and Foo brands.

What this means practically is that the desugaring of data is now split into two halves - all the mixin, with, and shared parts are desugared in `desugar` to be in the constructor for a `datatype`. Then in a new pass, `types-compile`, `datatype` is compiled into calls to runtime branders, etc. This means that the runtime semantics of all existing code should be unchanged, but there is now a language level that has `datatype` in it. Of course, our entire test suite (plus some new ones) is passing.