Skip to main content

Posts

Showing posts from February, 2007

Liskell docs, finally

As the ACM SIGPLAN template gave my Latex document much more space, I decided — instead of writing a separate piece of documentation — to enrich my ILC07 submission with more interesting chapters about meta-programming and the Liskell prelude. This paper is much richer in content as the original (about half the content is new) and it finally starts to explain the mechanisms behind defmacro and how you can use them in the Haskell/Liskell world. So if you are interested in Liskell, the revised paper certainly deserves a second look.

Pattern guards in Liskell

Yes, I'm working on documentation this very moment, but after seeing A missing Haskell feature on Planet Haskell, I was unable to resist. I need my daily dosage of coding.Here is working Liskell syntax sugar for pattern guards as described by Neil Mitchell. (defmacro (~= pts) `(let (((comp ,pts) True) ((comp _) False)) comp))
It can be used right-away as in: (all (~= Star _) ([] (Star "x") (Atom))) -> False
(all (~= Star _) ([] (Star "x") (Star "foo"))) -> True To give you a brief idea why this works: The function body of defmacro is called with a list (called pts) that is bound to ([] (PSym "Star") (PSym "_"))> which is equivalent to [PSym "Star", PSym "_"] written in Haskell syntax. This parse tree part is substituted into the backquoted code template at ,pts, resulting in the parse tree: (let (((comp (Star _) True)) | let comp (Star _) = True
((comp _) False)) …