[Haskell-cafe] C++ interface with Haskell

Isaac Dupree isaacdupree at charter.net
Wed Apr 16 21:16:38 EDT 2008


perhaps

haskell:
foreign export "foo_func" foo :: Int -> IO Int
-- I forget the rest of the syntax here

C++:

extern "C" {
int foo_func(int i);
}

int some_cplusplus_function() {
   int bat = 3;
   int blah = foo_func(bat);
   return blah;
}


Is that all you need to do?


Miguel Lordelo wrote:
> Hi all,
> 
> Well...somehow I'm a beginner in Haskell. But actually my interest in
> Haskell will increase if it is possible to call a haskell function in C++.
> Something like GreenCard ( http://www.haskell.org/greencard/ ) simplifying
> the task of interfacing Haskell programs to external libraries (usually).
> But is there also a task to interface a foreign language with Haskell, but
> calling Haskell functions. Or c2hs which is an interface generator that
> simplifies the development of Haskell bindings to C libraries.
> 
> I want to know this, because in my company some guys are doing some testing
> with Frotran and MatLab and I want to show them the power of haskell and the
> software which we are using is implemented in C++ (there is the reason to
> make Haskel -> C++).
> 
> I read somewhere that the only way for C++ calling a haskell function is to
> create a binding between Haskell and C and from C to C++, but a easy "Hello
> World" example was not there.
> Unfortunatelly I couldn't found anything usefull, like an complete example,
> or how to compile the code from haskell to C to C++.
> 
> Can sombody help me, please :P
> 
> Chears,
> Miguel Lordelo.
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list