I am looking for a nice way to define values of Haskell syntax in Haskell.
-
This is the Template Haskell syntax. Its advantage is that its values can be built with fancy brackets, like so:
⟦x + 1⟧ ∷ IO Exp
. - This is the internal Haskell syntax of GHC. Its advantage is that it is complete. For example, the Template Haskell syntax is unaware of imports and exports but the internal Haskell syntax of GHC is of course aware of them.
It seems it would be ideal to have an inlay of the Template Haskell syntax into the internal Haskell syntax of GHC.
Has anyone defined such an inlay already?
One possible definition would be to print a value of the Template Haskell syntax and then parse it with GHC. But parsing stuff with GHC is hard. Also, it will introduce spurious partiality: we know that the Template Haskell syntax is a subset of the internal Haskell Syntax of GHC, so it will always be parsed successfully, but this knowledge is lost when we print and then parse.