Macros for Haskell? Done. Wed Jan 31 14:41:00 CET 2007
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 http://clemens.endorphin.org/liskell.
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.
Posted by
clemens
|
Permalink
| Categories:
Liskell
hoogle.el Tue Jan 9 09:57:26 CET 2007
Here comes a short emacs helper for Haskell coders. It allows you to
hoogle lookup the symbol currently under your cursor. Drop hoogle.el into your ~/.(x)emacs dir, and add
(require 'hoogle)
(define-key haskell-mode-map [?\C-c ?h] 'hoogle-lookup)
to your
init.el.
For educational purposes, here is the function that does all the (pretty-simple) magic.
(defun hoogle-lookup (p)
(interactive "p")
(let ((symbol-name (thing-at-point 'symbol)))
(unless (and (= 1 p) (stringp symbol-name))
(setq symbol-name (read-from-minibuffer "Hoogle lookup name: " ""
nil nil 'hoogle-history)))
(browse-url (concat hoogle-url-base symbol-name))))
Posted by
clemens
|
Permalink