Calling Haskell from Python / C++
Jonathan Holt
jony42us@yahoo.com
Wed, 13 Nov 2002 03:41:41 -0800 (PST)
--- Simon Peyton-Jones <simonpj@microsoft.com> wrote:
> | So here is what I envision: I write the main
> | application in Python. I write a (hopefully) small
> | Haskell module that:
> | a) Calls back to the main Python app for reading
> the
> | text to be parsed, preferably using laziness.
> | b) Parses the text, and maybe processes a bit.
> | c) Returns the parsed data-structure. (This may be
> | tricky, but I think I know how to do it).
>
> If Python uses C's calling convention, it might be
> easy; just use
> 'foreign import' and 'foreign export' (see the FFI
> spec at haskell.org).
>
> If it doesn't, someone would have to add the Python
> calling convention
> to the various implementations.
Unfortunately, Python does not support calling
arbitrary C functions. In order to call C functions
from Python, you have to write a “Python extension
module”. (This restriction is actually a direct result
of Python being interpreted, rather than compiled.)
But I do have another idea: If I was working only on
Windows, I could have used HaskellDirect to wrap the
Haskell code as a COM component, and since Python
seems to have good COM support (though I never used
it) this would have solved my problem neatly.
However, I need Linux portability, which rules out
using COM. But there is a good COM alternative for
Linux: XPCOM from the Mozilla project. This is a
cross-platform and somewhat improved COM, which has
C++, Java, JavaScript, Perl, and Python bindings. And
this brings me to my next question: How difficult
would it be to extend HaskellDirect to support XPCOM?
Thanks,
-JH
__________________________________________________
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2