Rscc is a dialect of ML

At its core, rscc can be viewed as a dialect of ML. To get an idea of the meaning of that statement, consider the following simple language of booleans as it might be implemented in rscc:

expr: "true"
expr: "false"
expr: "if" expr "then" expr "else" expr

C code may manipulate this language using pattern-matching destructors and restructors:

if(ast ~ expr{true}) {
} else if(ast ~ expr{if \a then \b else \c}) {

ast = `expr{if true then true else false}

The same concepts can be implemented in ML using the following constructs:

datatype expr = True
              | False
              | If of expr*expr*expr

match ast with
| True -> ...
| If(a,b,c) -> ...

let ast = If(True,True,False)

These are exactly the same syntactic elements, except that rscc has unified the language syntax and the meta-language syntax. Very cool. We should take advantage of this property whenever possible. Some possibilities:

Other similarities

It has been noted that pattern-matching ast ~ expr{\a + 1} creates an ambiguous parse for the slot \a (should it be an expr slot or a num slot?). Rscc uses the shallowest parse, and this is exactly what ML does. In the example below, a will match an expr type (not a num type):

datatype expr = Add of expr*expr
              | Num of num
datatype num = int

match ast with
| Add(a, Num 5) -> ...

ML-like Extensions

I've proposed two extensions which steal ideas from ML. Their goal is to make extension writing easier.

Pattern-matching visitors

Pattern-matching switch


[1]"Shape inference" and "type inference" are really the same thing. I use "shape inference" to talk about the type of ASTs themselves (and not the type sytem of the modeled language). So in a sense, "shape" is a meta-type.