Lambda the Ultimate

inactiveTopic Template metaprogramming for Haskell
started 8/3/2002; 4:59:59 AM - last post 8/11/2002; 12:27:11 PM
Ehud Lamm - Template metaprogramming for Haskell  blueArrow
8/3/2002; 4:59:59 AM (reads: 2866, responses: 5)
Template metaprogramming for Haskell
Template metaprogramming for Haskell. Tim Sheard and Simon Peyton Jones. 16 pages, May 2002. Submitted to the Haskell Workshop 2002.

We propose a new extension to the purely functional programming language Haskell that supports compile-time meta-programming. The purpose of the system is to support the algorithmic construction of programs at compile-time.

While the previous post was about working with generic data, this is about compile time generic code (I use generic in the Ada sense of the word).

Detailed comparison with Scheme macros is provided as well as a discussion of the differences between the presented approach and MetaML (staging). Even C++ templates are mentioned.

Typing in a compile time meta-system like Template Haskell is done on two levels (see section 7): First the template invocation must be checked. Next, after template expansion, the resulting object-language code (pure Haskell) is type checked.

Template Haskell is strongly typed.

The usuall macrology topics of scoping, quotation and quasiquoutation are there, of course, too.


Posted to functional by Ehud Lamm on 8/3/02; 5:13:57 AM

Ehud Lamm - Re: Template metaprogramming for Haskell  blueArrow
8/10/2002; 2:09:55 PM (reads: 1221, responses: 0)
One of the nice things about macros is that they can be used for a variety of purposes. Macros can be used to achieve delayed evalutation (something that is less important in a lazy language like Haskell). They can also be used when you have to flex the type system (something that may be unnecessary in a dynamically typed language).

Any examples of a dynamically typed lazy language with macros?

Frank Atanassow - Re: Template metaprogramming for Haskell  blueArrow
8/11/2002; 10:43:40 AM (reads: 1185, responses: 2)
Maybe you should ask first: "are there any examples of a dynamically typed lazy language", period. :) I don't know of any. (Though I'm sure somebody somewhere has written a lazy variant of Scheme or something.)

At the risk of sounding a bit acidic (and OT), my own hypothesis about this is that most of the people who are not sophisticated enough to "get" static typing, are also not sophisticated enough to "get" laziness. I mean, the set of people who feel they are overly constricted by static typing (because of all those ingeniously original algorithms they must have which just cannot be expressed in an ML-like language!), and the set of people who feel they cannot put up with the idea of being one step further from the "bare metal" because of laziness probably has a large degree of overlap.

Not that I am a fierce proponent of laziness, BTW.

Frank Atanassow - Re: Template metaprogramming for Haskell  blueArrow
8/11/2002; 11:01:50 AM (reads: 1254, responses: 0)
On rereading my post, I see that I was unclear about something which I wish hereby to explain. I implied that users of dynamically typed languages like to program close to the metal, i.e., that DTLs are somehow low-level languages. That sounds patently false, since DTLs are usually less efficient than archetypal low-level languages like C.

But I tend to think of DTLs as low-level in the sense that they are untyped, since assembly/machine language is also an archetypal example of an untyped language. When you start working with statically typed languages, you have to think about an artificial structure on memory which partitions it into a set of fields indexed by types, though, so I consider statically typed languages more "high-level" in that respect.

Maybe I should have written something like, "I believe there is a large overlap between people who reject static typing, and people who reject non-von Neumann models of computation," because, while it is not so hard to see how a call-by-value (eager) language is implemented, the mapping to hardware of a call-by-need (lazy) language is considerably more subtle.

Ehud Lamm - Re: Template metaprogramming for Haskell  blueArrow
8/11/2002; 12:25:15 PM (reads: 1257, responses: 0)
Maybe you should ask first: "are there any examples of a dynamically typed lazy language", period. :) I don't know of any.

I agree on both points (I guess I rephrased my original post one time too many...)

Ehud Lamm - Re: Template metaprogramming for Haskell  blueArrow
8/11/2002; 12:27:11 PM (reads: 1172, responses: 0)
On rereading my post, I see that I was unclear about something which I wish hereby to explain. I implied that users of dynamically typed languages like to program close to the metal, i.e., that DTLs are somehow low-level languages.

I tend to agree with your observation.

The way I see it typing is essentially an abstraction tool, and thus are "higher level" concepts.