Skip to main content

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 know: 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 syntax.

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.


Popular posts from this blog

Liskell standalone

Some time has passed since I last blogged about Liskell. It is not dead nor have I changed my mind that Haskell needs a proper meta-programming facility not to mention a better syntax.Liskell was a branch of GHC once. Now it sits on top of the GHC API, or I should rather say sneaks behind its back as it creates its own API as the original one is not suitable for the stunts I'm interested in. If Liskell sticks with GHC as its soil, I will definitely send patches upstream to refine the GHC API in the areas where it needs more flexibility for Liskell. However for the moment, my main target was to get something out that compiles with a stable version of GHC.You can grab it with the usual: darcs get This version has been tested with ghc 6.10.1 and should install like: ./Setup.lhs configure ./Setup.lhs build ./Setup.lhs install cd LskPrelude make install-inplace Optionally you can run make tests in the testsuite subdirectory. Thanks to community.haskell…

Is the new post-money SAFE mathematically sound?

Y-Combinator published a new set of documents for their SAFE, short for "Simple Agreement for Future Equity". The new version takes the document from a pre-money investment to a post-money investment. But for those of you that know neither versions, a SAFE is a legal document signed by the SAFE investor and a startup, so that the startup gets cash to build their product and the investor gets equity in the company. How much equity the SAFE investor gets is not spelled out in numbers but in the form of a set of equations that should compute this number at a later stage. "Later" usually means at the next funding round called Series A, where a larger investor injects more cash into an already working prototype of the product. At the point of Series A, it is much more clear on how the product performs and whether there is a market. The Series A investment usually happens a year after the SAFE investment. The assumption here is that it is fair to both the startup and th…

XMonad GridSelect

Personally, I not just need a window manager, I need a focus manager. I tend to think of windows as TODO items, and as there are many TODOs in life there are many windows on my workspaces. Usually a fraction of that can't be closed or worked on immediately, so they linger around on my desktop, cluttering my workspace.I used to use the Tabbed layout. But Tabbed isn't the answer when you are a guy who reports bugs such as "XMonad 0.6 with Tabbed dies when firefox-session-restore slams 40 windows at once on the desktop". In other words, I use a lot of windows. The workspaces concept isn't particularly useful to me either. My mind just doesn't work with mental boxes. So the result is, that I have too few workspaces with too much windows on them, so that Tabbed has trouble displaying useful window titles, and navigating through them is slow and cumbersome (mostly because tab switching generates a lot of useless X Expose events).GridSelect is my answer to that. It…