The future of Haskell discussion

Marcin 'Qrczak' Kowalczyk
14 Sep 2001 09:52:30 GMT

Fri, 14 Sep 2001 02:09:21 -0700, Julian Seward (Intl Vendor) <> pisze:

> The lack of any way to interface to C++ is a problem, IMO.
> I would love to be able to write Haskell programs using Qt
> and ultimately the KDE libraries, both of which are C++, but
> I can't, at the mo.

I think it should be easy to add support for C++, except exceptions.

There are two approaches: call C++ functions directly (it requires
implementing name mangling by the Haskell compiler; there are several
name mangling schemes and gcc changed its scheme in version 3.0)
or write C wrappers (this is inconvenient but is doable now without
compiler support).

An annoyance is that templates can't be called directly but each
instance must be imported separately.

On Linux it works when main() of a mixed C/C++ program is written in C.
AFAIK it doesn't work everywhere. Nevertheless an example I've now
made worked.

hsc2hs and ghc need to be extended to make it work smoothly. hsc2hs
produces a file with extension .c and ghc compiles these files by
passing -x c options to the C compiler, so even if a C++ compiler is
substituted, it is compiled as C. There should be a switch in hsc2hs
to let it produce C++ and ghc should recognize .cc extension, or
in some other way ghc should be informed that the .c file is really
C++. Option -pgmlg++ causes ghc to link using g++; option -lstdc++
instead also works. And hsc2hs should be taught about extern "C".

 __("<  Marcin Kowalczyk *
  ^^                      SYGNATURA ZASTĘPCZA