[racket] Defining a typed language

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Tue Oct 28 07:53:41 EDT 2014

E. Moran writes:

 > Yep...  Your version was very nearly correct, and I wouldn't have been able
 > to find a working solution if I hadn't seen that first.  The missing piece
 > is basically dealing with macro hygiene:
 > 
 >   http://docs.racket-lang.org/guide/pattern-macros.html#(part._.Lexical_.Scope)
...
 > Personally, I tend to think of macro hygiene as being like conservation
 > of energy---sort of a "conservation of identifiers."  A macro can't
 > output an identifier that it didn't take in as input.  (Unless we
 > explicitly override, like we're doing above.)

I didn't think about hygiene in this context, but as you describe it,
it makes sense. (require ...) can indeed be considered a non-hygienic
macro, since it injects bindings into a module that are not explicitly
named.

 > Eli Barzilay's paper also helped a lot:
 > 
 >   http://barzilay.org/misc/stxparam.pdf

Thanks for the pointer, that really looks interesting.


I have added lots of comments to my minimalistic typed language
implementation, in the hope that future language definers will
be able to pick up from there:

   http://github.com/khinsen/racket-typed-lang


Sam Tobin-Hochstadt writes:

 > I think what happens here is that the `require` that Konrad added was
 > getting the correct state initialized, but because of hygiene wasn't
 > the `require` that was binding the references to `foo`. Then Evan's
 > changes meant that the state and the binding were coming from the
 > correct place, and it works.
 > 
 > At least that's what I think is going on -- the interaction of the
 > language position and syntax-time state still confuses me sometimes.

That's reassuring, I feel less alone ;-)

I figured out by now that Typed Racket is a stress test for the macro
system. And I am confident that in a couple of years the macro system will
evolve to make all this more transparent.

Konrad.

Posted on the users mailing list.