newbie - how to call a Haskell interpreter from C

Hi, I've been trying to find place to use Haskell at work, and I think a good opportunity will be to use it for our scripting language. To do that, I need to be able to invoke an interpreter directly from another language. I've investigated using HaskellScript (too web/ActiveX centric), but really I just want to compile ghci or hugs into my executable/library. It seems like this is something I should be able to figure out easily, but so far I've failed and have not found any reference to others succeeding. any advice? thanks in advance, Brock

The easiest way to run Haskell software from a C program is to give the
shell command:
runhaskell Foo.hs
This command is part of the GHC package.
A more advanced way is, to link Haskell libraries by means of the foreign
function interface (FFI) [1].
There are several tools to support FFI development [2]. I am sure my list
of URL's is not complete.
[1] http://www.cse.unsw.edu.au/~chak/haskell/ffi/
http://www.haskell.org/haskellwiki/FFI_Introduction
http://www.haskell.org/haskellwiki/FFI_cook_book
[2] http://www.haskell.org/haskellwiki/FFI_imports_packaging_utility
http://www.haskell.org/haskellwiki/HSFFIG
Met vriendelijke groet,
Henk-Jan van Tuyl
--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--
On Fri, 24 Aug 2007 01:12:56 +0200, Brock Peabody
I've been trying to find place to use Haskell at work, and I think a good opportunity will be to use it for our scripting language. To do that, I need to be able to invoke an interpreter directly from another language.
I've investigated using HaskellScript (too web/ActiveX centric), but really I just want to compile ghci or hugs into my executable/library. It seems like this is something I should be able to figure out easily, but so far I've failed and have not found any reference to others succeeding. --

On 8/25/07, Henk-Jan van Tuyl
The easiest way to run Haskell software from a C program is to give the shell command: runhaskell Foo.hs
I'm a newbie but not that new :) I really have to be able to interpret the Haskell from within the same process. A more advanced way is, to link Haskell libraries by means of the foreign
function interface (FFI) [1]. There are several tools to support FFI development [2]. I am sure my list of URL's is not complete.
[1] http://www.cse.unsw.edu.au/~chak/haskell/ffi/ http://www.cse.unsw.edu.au/%7Echak/haskell/ffi/ http://www.haskell.org/haskellwiki/FFI_Introduction http://www.haskell.org/haskellwiki/FFI_cook_book
[2] http://www.haskell.org/haskellwiki/FFI_imports_packaging_utility http://www.haskell.org/haskellwiki/HSFFIG
My understanding is that FFI helps you to call into other languages from Haskell and vice-versa. I will definitely need this, but what I can't figure out how to do is to invoke the ghci or hugs interpreter programmatically, in-process. I didn't see a way to do that in the links you listed, am I missing something? Much thanks, Brock Peabody

On Sat, Aug 25, 2007 at 12:34:45PM -0400, Brock Peabody wrote:
On 8/25/07, Henk-Jan van Tuyl
wrote: The easiest way to run Haskell software from a C program is to give the shell command: runhaskell Foo.hs
I'm a newbie but not that new :) I really have to be able to interpret the Haskell from within the same process.
A more advanced way is, to link Haskell libraries by means of the foreign function interface (FFI) [1]. There are several tools to support FFI development [2]. I am sure my list of URL's is not complete.
[1] http://www.cse.unsw.edu.au/~chak/haskell/ffi/ http://www.cse.unsw.edu.au/%7Echak/haskell/ffi/ http://www.haskell.org/haskellwiki/FFI_Introduction http://www.haskell.org/haskellwiki/FFI_cook_book
[2] http://www.haskell.org/haskellwiki/FFI_imports_packaging_utility http://www.haskell.org/haskellwiki/HSFFIG
My understanding is that FFI helps you to call into other languages from Haskell and vice-versa. I will definitely need this, but what I can't figure out how to do is to invoke the ghci or hugs interpreter programmatically, in-process. I didn't see a way to do that in the links you listed, am I missing something?
No, you're not missing anything, and there are no deliberately embeddable Haskell interpreters. Your options are: 1a. GHC, native code: Link libHSplugins.a into your program (compile Don's hs-plugins library). Then call the external functions described in http://www.cse.unsw.edu.au/~dons/hs-plugins/hs-plugins-Z-H-4.html#node_sec_7..., Pro: Full GHC runtime speed Con: Full GHC compile-time sloth As big as GHC (20mbytes file size) Leaks memory 1b. GHC, bytecode: Write a binding to the GHC-API runStmt function. foreign export it. Pro: As fast as GHCi No leaks Con: Still huge Slow runtime 2. Hugs Link Hugs. Study the source code to runhugs. Pro: Much faster loading Much smaller footprint Con: Less polished Slow runtime Stefan
participants (3)
-
Brock Peabody
-
Henk-Jan van Tuyl
-
Stefan O'Rear