[wg-camlp4] My uses of syntax extension

Leo White lpw25 at cam.ac.uk
Mon Jan 28 18:25:40 GMT 2013


>I suggest that you might think twice before you think it's a viable option
>---------------------------
>2. *Copy and paste, creating two new versions of the parser. *One
>version will directly return Haskell abstract syntax for a Haskell
>pattern, and the other will return Haskell abstract syntax for an
>expression.
>*This is potentially a maintenance nightmare.*

This part is referring to needing two parsing functions: one for the when 
the quotation is used as a pattern and one for when it is used as an 
expression. I don't think that needing two parsing functions is really a 
"maintenance nightmare". Also, with GADTs they don't need to be two 
separate functions anyway.

>Furthermore, we lose a lot of the benefits of the type checker:
>a value of type TH.ExpQ is Haskell abstract syntax for an
>expression, but knowing this tells us nothing about the type of
>the Haskell expression represented by the abstract syntax. This
>expression could be an Integer, a String or have any other
>type—we know only that it is syntactically correct, not that it is
>type correct.

This is a fair criticism: parsing to a value and then converting that into 
an AST fragment may catch some potential errors in a parser. However, this 
safety could also be obtained by creating the value and the AST in 
parallel, and simply discarding the data structure when parsing is 
finished. This may not be as "neat" as deriving the AST from the value, but 
it is also requires no special support.





More information about the wg-camlp4 mailing list