Calling Haskell from Python / C++

Hi, I've just recently learned about Haskell, and I'm impressed by the abstractions and expressiveness that it affords. I'm particularly interested in it for a small parser project that I'm planning. However, my main programming languages are Python and C++, and for various reasons switching entirely to Haskell is completely out of the question (no flame-bait intended!). 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). This all seems quite cool. And it can also be very useful in a wide veriety of other circumstances, i.e. whenever a complex computation can be "outsourced" from Python/C++ to Haskell. But I can't find any way to interface Python and Haskell in this way. The FFI seems to allow for this, but there arn't any tools to actually do it... So my question is: How would one do such a thing? Thanks in advance, -JH __________________________________________________ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2

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).
You might be able to get away with running the Haskell program as a separate process, communicating via pipes. Look at Posix.popen (not available in the new libraries yet):
http://www.haskell.org/ghc/docs/latest/html/hslibs/popen.html
This is probably easier to achieve than trying to link the programs together, but it does limit you to bytestream communication both ways.
--KW 8-)
--
Keith Wansbrough

G'day all. On Thu, Nov 14, 2002 at 05:17:49PM +0000, Keith Wansbrough wrote:
You might be able to get away with running the Haskell program as a separate process, communicating via pipes.
IMO, this is almost never the right thing to do. Unless your programs are really stream processors, or you want to fork a child, wait for it to finish and use its output, it's almost always better to use a true RPC or distributed object mechanism rather than trying to simulate it over pipes. HaskellDirect for the Win32/COM world has already been mentioned. There's also this, if you're in the Unix/CORBA world: http://haskell-corba.sourceforge.net/ Cheers, Andrew Bromage
participants (3)
-
Andrew J Bromage
-
Jonathan Holt
-
Keith Wansbrough