[Haskell-cafe] C++ interface with Haskell

2008-04-16 Thread Miguel Lordelo
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 (usuall

Re: [Haskell-cafe] C++ interface with Haskell

2008-04-16 Thread Dan Mead
write the C wrapper that calls haskell, then link that to your C++ objects I think what you're really asking is how to call C from C++ -Dan 2008/4/16 Miguel Lordelo <[EMAIL PROTECTED]>: > Hi all, > > Well...somehow I'm a beginner in Haskell. But actually my interest in > Haskell will increase i

Re: [Haskell-cafe] C++ interface with Haskell

2008-04-16 Thread Isaac Dupree
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

Re: [Haskell-cafe] C++ interface with Haskell

2008-04-17 Thread Miguel Lordelo
Well Isaac...I became now a little bit smarter then yesterday!!! I show you the example that I found and on which I´m working with. File: foo.hs module Foo where foreign export ccall foo :: Int -> IO Int foo :: Int -> IO Int foo n = return (length (f n)) f :: Int -> [Int] f 0 = [] f n = n:(f (

Re: [Haskell-cafe] C++ interface with Haskell

2008-04-18 Thread Alfonso Acosta
Although you could use gcc to link the code I wouldn't recommend it (mainly for the problems you are currently having) SImply call GHC to compile both the C and Haskell code. It will take care of finding the headers and supplying the necessary linker arguments. ghc -ffi -c foo.hs myfoo_c.c BTW

Re: [Haskell-cafe] C++ interface with Haskell

2008-04-18 Thread Miguel Lordelo
Thanks, I found on one site how to compile after creating the stub files with GHC: First step: *ghc -c -ffi haskell_file.hs* Second step - here it is important to know and write where are the ghc libraries: *gcc -I /usr/local/lib/ghc-5.04.3/include -c C_file.c * After that it is important to link

Re: [Haskell-cafe] C++ interface with Haskell

2008-04-18 Thread Isaac Dupree
if you'd normally be linking using g++, you'll need (IIRC) -lstdc++ added to linking-ghc's command line Alfonso Acosta wrote: Although you could use gcc to link the code I wouldn't recommend it (mainly for the problems you are currently having) SImply call GHC to compile both the C and Haskell

Re: [Haskell-cafe] C++ interface with Haskell

2008-04-19 Thread Isaac Dupree
Evan Laforge wrote: To threadjack a little bit, I've been interfacing haskell with c++. It gets awkward when the c++ structures use STL types like string and vector. Of course those are too complex for haskell to marshal to. What I've been doing is defining an XMarshal variant of the X c++ clas

Re: [Haskell-cafe] C++ interface with Haskell

2008-04-19 Thread Evan Laforge
> you mean, you hack around with the internal representation of those > structures? Well, if you want to avoid double-copying, C++ can't access > Haskell sequences, and Haskell can't access C++ sequences, I guess I don't > see an alternative. I don't really mind double copying, but having to dec

Re: [Haskell-cafe] C++ interface with Haskell

2008-04-19 Thread Isaac Dupree
you could write a C++ function to marshal a Sequence (or any Container IIRC, maybe Forward Container) to a vector (or whatever you wanted -- there are choices), and then okay let's see if I remember C++ well enough This design has extra copying. but anyway template std::vector container_to_

Re[2]: [Haskell-cafe] C++ interface with Haskell

2008-04-18 Thread Bulat Ziganshin
Hello Miguel, Friday, April 18, 2008, 7:06:07 PM, you wrote: you may look into my freearc.org project overall, nothing complex as far as you got it :) i use ghc -c c_file.cpp ghc --make main.hs c_file.o in order to call from C++ to Haskell or vice versa you should define function in C++ as hav

Re[2]: [Haskell-cafe] C++ interface with Haskell

2008-04-18 Thread Bulat Ziganshin
Hello Isaac, Friday, April 18, 2008, 7:27:56 PM, you wrote: absolutely true! it's required if you use new/delete and other things supported by c++ RTS > if you'd normally be linking using g++, you'll need (IIRC) -lstdc++ > added to linking-ghc's command line > Alfonso Acosta wrote: >> Although

Re[4]: [Haskell-cafe] C++ interface with Haskell

2008-04-20 Thread Bulat Ziganshin
Hello Don, Saturday, April 19, 2008, 12:08:11 AM, you wrote: > Would someone like to summarise the current approaches > to combining Haskell & C++ on the Haskell wiki, even if just in bullet > points? started at http://haskell.org/haskellwiki/IO_inside#Interfacing_with_foreign_evil -- Best re

Re: Re[2]: [Haskell-cafe] C++ interface with Haskell

2008-04-18 Thread Evan Laforge
To threadjack a little bit, I've been interfacing haskell with c++. It gets awkward when the c++ structures use STL types like string and vector. Of course those are too complex for haskell to marshal to. What I've been doing is defining an XMarshal variant of the X c++ class, that uses plain c a

Re: Re[2]: [Haskell-cafe] C++ interface with Haskell

2008-04-18 Thread Don Stewart
qdunkan: > To threadjack a little bit, I've been interfacing haskell with c++. > It gets awkward when the c++ structures use STL types like string and > vector. Of course those are too complex for haskell to marshal to. > > What I've been doing is defining an XMarshal variant of the X c++ > class