Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pattern matching and algebraic datatypes in native C++?

3 views
Skip to first unread message

Asger K. Alstrup Nielsen

unread,
May 1, 2000, 3:00:00 AM5/1/00
to
Hi,

Recently, I asked for lambda expressions in C++, and was pointed to

http://lambda.cs.utu.fi/

which is cool. I found an alternative at

http://www.fz-juelich.de/zam/FACT/

which uses a different syntax for the lambda expressions, which I prefer.

Now to complete the functional feel, I want algebraic types and pattern
matching. I know of several preprocessor solutions:

http://www.cs.nyu.edu/leunga/prop.html
http://www.primenet.com/~georgen/app.html
http://www.cs.sunysb.edu/~lhungda/cse526/report.htm

If any of those is insufficient for some reason, it's relatively easy to
roll your own with OpenC++:

http://www.softlab.is.tsukuba.ac.jp/~chiba/openc%2B%2B.html

since that gives you the parser for free.

However, a preprocessor solution is not satisfactory because it complicates
the build process, and it's slower.
Also, depending on the preprocessor, it might not be portable.

A different approach is to employ design patterns and write the
stuff in C++ yourself:

http://www1.bell-labs.com/user/cope/Patterns/C%2b%2bIdioms/EuroPLoP98.html

However, that does not give us the nice syntax from the preprocessor
solutions, and you are required to do all the bookkeeping yourself.

My question is: Would it be possible to solve this problem directly in C++?
I.e. get some nice syntax and hide all the boring details, but without the
preprocessor?

The Lambda Library does limited pattern matching on tuples, but is it
possible to generalize this in a C++ setting?

Here's some general research on more advanced pattern matching:

http://dalila.sip.ucm.es/funcional/publicaciones/ICFP-96.ps

It includes references to traditional theory of pattern matching.

Greets,

Asger Alstrup

[ Send an empty e-mail to c++-...@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]


0 new messages