Wednesday, 31 January 2007

Macros for Haskell? Done.

Why is Lisp special? Because of macros. This changes today.

For the last three month, I have been working on Liskell, a language extension for GHC. Some people might be tempted to call it a new language because of documents talking about language definition. But in fact, it is just a new dress for something we already embosomed: Haskell.

Liskell brings symbolic expression (aka Lisp syntax) to Haskell. This is no Lisp interpreter written in Haskell, but GHC itself becomes the part that processes Lisp like syntax. After parsing, the Liskell extension transforms this sexp parse tree into a regular Haskell parse tree, as it would result from any regular Haskell file. From then it takes the regular path through type inference, desugaring, compiling core. So, if there was not another important thing, this would just be a new syntax for Haskell.

Within Liskell, we get parse tree transformers, a generalization of macros. Before the conversion to the Haskell parse tree takes place, you are free to do any arbitrary manipulation to the Lisp-styled parse tree of sexps by injecting your own parse tree transformers into the compiler. The possibilities with such a facility ranges from minor syntactic sugar transformations such as field syntax, 'deriving' syntax or another do-notation expansion, to more grave extensions to Liskell, such as embedded sub-languages. An example for the latter is my embedded Prolog version, that can be seen in a little appetizer (Flash Video, 99mb, direct, torrent (preferred). To play mplayer, for Windows especially: FLV Player.).

The official page is The material I release for the moment is my darcs repository of GHC containing Liskell and a modified testsuite containing a small set of regression tests and the Liskell Prelude. The Liskell Prelude defines a lot of syntax sugar, so this might be the first place to look for reasonable first-steps examples into meta-programming. But before jumping into meta-programming, you might want to look at the basic language first. The Liskell page contains a draft for a Liskell paper submitted for ILC07 and it also features a 15 minute tour of Liskell

How fast the documentation grows, depends on the community reaction and your feedback. For the moment, please be content with the basics, I hope to introduce you to meta-programming in a more systematic way next week.

No comments: