Re: Using Functional Programming in C/C++ Compilers (Torben AEgidius Mogensen)
5 Apr 2000 22:25:26 -0400

          From comp.compilers

Related articles
Using Functional Programming in C/C++ Compilers (Kees & Annette van der Bent) (2000-04-03)
Re: Using Functional Programming in C/C++ Compilers (2000-04-05)
Re: Using Functional Programming in C/C++ Compilers (Dave MacQueen) (2000-04-05)
Re: Using Functional Programming in C/C++ Compilers (Joachim Durchholz) (2000-04-14)
| List of all articles for this month |

From: (Torben AEgidius Mogensen)
Newsgroups: comp.compilers
Date: 5 Apr 2000 22:25:26 -0400
Organization: Department of Computer Science, U of Copenhagen
References: 00-04-036
Keywords: functional

Kees & Annette van der Bent <> writes:

>Who is willing to share his/her opinions on using functional
>programming languages for developing C/C++ compilers/linkers/...?

>* What language(s) and why?
>* What part(s) best done in FP?
>* Combining FP language and C/C++?
>* Performance issues?
>* Sofware engineering issues (maintenance, teaching C/C++ developers, ...)
>* ...
>* References?

There is a tool called "ckit"
( which
is basically a parser for C written in SML. The output is a
representation of the abstract syntac tree. If I was to write a C
compiler today, I would start from this.

SML has several features that makes it very well suited for writing

  1) Recursive datatypes with pattern matching.

  2) Automatic memory management (GC).

  3) A good module system.

  4) A type system that catches many errors at compile-time that would
        not be caught at all by C.

  5) Exceptions.

  6) A wide range of compilers, so you can develop on a fast compiler
        and run your final code through an optimizing compiler.

You can see Andrew Appel's book "Modern Compiler Implementation in ML"
for examples of compiler-code written in SML. You can even compare
with how the same things are done in C or Java by also looking at
"Modern Compiler Implementation in C" and "Modern Compiler
Implementation in Java" by the same author.

As for maintenance, the module system and the type system are really
aids for maintenance. Most ML implementations have some kind of
intelligent recompilation scheme.

In all, the major problem may be social: C/C++ programmers may be
reluctant to learn a new (and radically different) language. The
language itself is fairly easy to learn (we teach it as the first
language at DIKU) but it takes a while for a programmer who thinks in
objects and state to wrap his mind around a different way of
expressing things.

Torben Mogensen (

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.