Compile Time Programming, why not Compile Time Functional Language?

Compile Time Programming, why not Compile Time Functional Language?

Post by eddeighto » Sun, 03 Jul 2005 11:02:47


I am currently reading "Modern C++ Design" and have aspirations of
eventually reading the Vandervorde book which currently takes pride of
place on my desk at work to strike a chill of terror into my friends...

Something however that I feel is left un-answered and even un-addressed
by the peers of c++.

Why doesnt compile time programming for c++ utilise a proper
programming language in itself? For instance imagine being able to
manipulate the abstract syntax tree of a c++ program using a Haskell
like language. Wouldn't the degree by which people could utilise the
techniques of meta programming be greatly increased? Generating clever
code to encapsulate things wouldn't incur trying to see how to do it
with templates, you could just manipulate the code itself.

I guess at the heart of this is the matter of constructing a model of
what a program is that itself can be manipulated. It seems like a
critical calculus that is yet to be discovered to me.

Ed Deighton.


[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
 
 

Compile Time Programming, why not Compile Time Functional Language?

Post by Tommaso Ga » Mon, 04 Jul 2005 19:20:22


< XXXX@XXXXX.COM > wrote


I have a feeling that you are reading the two books the other way round!
I would first read "C++ Templates, the complete guide"
(Vandevoorde/Josuttis) and then when you have learnt templates I would read
"Modern C++ Design" (Alexandrescu). The first book is easy to read in most
of its parts and it is a tutorial and reference for C++ templates. Some
topics are a bit more difficult but overall it teaches you the subject and
later on when you need a reference it's a perfect one. The section called
"the basics is a very nice and easy read", the other sections require a bit
more thoughts.
Modern C++ Design instead applies many of the concepts you have learnt about
in the C++ Templates book.

Tommaso



[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

 
 
 

Compile Time Programming, why not Compile Time Functional Language?

Post by borg » Thu, 07 Jul 2005 21:31:14

Great question and I'm surprised this topic hasn't received more
replies. Extensive compile-time programs accomplished via template
metaprogramming seem to go well beyond the original intent of C++
templates (which is great and a tribute to the original design of the
templates), but I feel that the language would benefit considerably
from a fresh look at this by the language design experts now that we
can see how metaprogramming is being used. Questions I'd ask are:

1. Should the metaprogramming language stick to current C++ syntax, or
should it be an entirely new language?

2. Is a metaprogramming language limited to being a functional
language?

3. Can we learn anything in this area from Lisp?

4. What would be some good model languages to look at for inspiration
and additional real-world experience? OCaml, ML, Haskel, Lisp?

5. Should we formalize a model of the C++ AST made available to the
language?

I guess this is a very complex area still needing considerable
research, but interesting nonetheless.

Cheers,
Adrian


[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
 
 

Compile Time Programming, why not Compile Time Functional Language?

Post by Larry Evan » Fri, 08 Jul 2005 07:08:30


I'd like to see someone relate c++ metaprogramming to something like
"dependent types", as in Nuprl:

http://www.yqcomputer.com/

(BTW, "function and dependent product constructors" in that file
should be "dependent function and product constructors").

There's also mention of "dependent types" in Pierce's recent _Advanced
Topics in Types And Programming Languages_ (ATTAPL) . In particular,
I'm fascintated by the way Nuprl defines record as a "dependent
function"; yet, ATTAPL calls this (p. 46) a "dependent product".
OTOH, Nuprl what Nuprl calls a "dependent product", ATTAPL calls
a "dependent sum" (p. 61). The reason this is relevant to c++
template metaprogramming is that there *appears* to be a close
correspondence between Numprl's expression of the "dependent function":

x:A->B

where B has x as a free variable and hence is a function from
elements of a type, A, to elements of the U_k, for some k=1...,
and where U_k is "universe of types at level k:

http://www.yqcomputer.com/ #1785

This close correspondence is illustrated by file,
tuple_nested_enum_test.cpp, at:

http://www.yqcomputer.com/

where the comments after enum_map<NestingLevel>::field_map describe the
correspondence.

I'm wondering if someone could maybe use the concepts in Nuprl or
Benjamin's book to give a more formal description of template
metaprograming and this might provide more insight and ideas.

[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]