[Haskell-cafe] Re: calling haskell from C++

Max Vasin max-appolo at mail.ru
Tue May 23 11:04:07 EDT 2006

>>>>> "Vladimir" == Vladimir Portnykh <vportnykh at hotmail.com> writes:

Vladimir> Hello ALL, I am very new to Haskell and my question might
Vladimir> appear very basic sorry about it in advance.  I have a C++
Vladimir> application and I would like to be able to launch Haskell
Vladimir> interpreter (lets say GHC) supplying the Haskell code (in a
ghci - not ghc.

Vladimir> file ) to be interpreted from it. The Haskell program
Vladimir> generates some output and I would like to use this output in
Vladimir> my C++ program.  Do you have any simple example to help me,
Vladimir> please? 
Hmm. That depends on what the output of the haskell program is. If I understand
you corrrectly the output of the program is what it writes to the stdout.
In this case you'll can do the job using popen(2) (or whatever is available
in your OS) - you create process to run 'runhaskell file.hs' and redirect
its stdout to a pipe.

There is also an FFI which allows you to call functions written in Haskell
from other languages. In this case your Haskell program must export C-level API
to be used from C++.

Or, and of cause you can use IPC to connect your programs.

Max Vasin.


More information about the Haskell-Cafe mailing list