[Haskell-beginners] Re: A Comparison of Haskell and Scheme

Benjamin L.Russell DekuDekuplex at Yahoo.com
Tue Feb 10 05:03:31 EST 2009

On Tue, 10 Feb 2009 00:30:40 -0800, Albert Krewinkel
<krewinkel at gmx.net> wrote:

>Of what I've seen so far, I'm very fascinated by the power and elegance
>of Haskell.  I read a few short introductions on Monads, getting a
>glimps of easy DSL developing in Haskell.  In Lisp, one would use the
>macro system to achive this.  Even though the concepts seem
>fundamentally different, I was wondering if there are any parallels?

Lisp-style macros enable one to extend Lisp syntax.  They take Lisp
code as input, and return Lisp code as output.  This behavior is
closely related to reflection (see
http://en.wikipedia.org/wiki/Reflection_(computer_science)), in which
a computer program observes and modifies its own structure and

In a related thread on Haskell-Cafe (see "[Haskell-cafe] Re: Monad
explanation" at
I recently asked about reflection in Haskell:

>On Wed, 4 Feb 2009 21:43:04 -0800, Max Rabkin <max.rabkin at gmail.com>
>>On Wed, Feb 4, 2009 at 9:38 PM, Benjamin L. Russell
>><DekuDekuplex at yahoo.com> wrote:
>>> Is it possible to write a self-referential function in Haskell that
>>> modifies itself?
>>Is it possible to write *any* kind of function in Haskell that
>>modifies *anything*?
>While trying to research this issue, I came across a relevant archived
>thread in Haskell-Cafe, entitled "[Haskell-cafe] haskell and
>reflection," started by Greg Meredith, dated "Tue, 11 Sep 2007
>07:09:22 -0700" (see
>which at first had me worried.  Specifically, Greg wrote as follows:
>>Am i wrong in my assessment that the vast majority of reflective machinery
>>is missing from Haskell? Specifically,
>>   - there is no runtime representation of type available for
>>   programmatic representation
>>   - there is no runtime representation of the type-inferencing or
>>   checking machinery
>>   - there is no runtime representation of the evaluation machinery
>>   - there is no runtime representation of the lexical or parsing
>>   machinery

In fact, Haskell does offer a somewhat similar parallel to macros in
Lisp:  Template Haskell (see
http://www.haskell.org/haskellwiki/Template_Haskell).  To continue:

>>Op 11-sep-2007, om 18:43 heeft Greg Meredith het volgende geschreven:
>>Template Haskell [1] is a system that lets you write programs that get 
>>executed at *compile time*, and that produce parts of the Haskell program 
>>to be compiled by manipulating a representation of the program as structured 
>>data. It's a form of reflection restricted to compile time, if you'd ask me.
>>[1] http://www.haskell.org/haskellwiki/Template_Haskell
>According to the site referenced by the above-mentioned link,
>>Template Haskell is an extension to Haskell 98 that allows you to do type-safe 
>>compile-time meta-programming, with Haskell both as the manipulating language 
>>and the language being manipulated.

There is also a related thread on this issue:

Explanation of macros; Haskell macros

The above-referenced paper also references the following related paper
discussing this topic in more detail:

Template Meta-programming for Haskell
by Tim Sheard and Simon Peyton Jones

>Also, could someone point me to a gentle introduction to syntax,
>semantics and type systems?  I understand that lisp-like macros do not
>exist in Haskell since they would break the type system and could give
>rise to unclear semantics.  I'd like to understand what's going on, so
>pointers to books or tutorials would be highly appreciated.

One book that is often mentioned in this context is the following:

Types and Programming Languages
by Benjamin C. Pierce

Hope this helps....

-- Benjamin L. Russell
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
"Furuike ya, kawazu tobikomu mizu no oto." 
-- Matsuo Basho^ 

More information about the Beginners mailing list