Calling Haskell from other languages?

Is there a way to call Haskell code from other languages? I have looked on the wiki, and as far as I can see, it only talks about the other way round (when Haskell is the main program). -- Colin Adams Preston Lancashire

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Nov 11, 2008, at 10:45 AM, Colin Paul Adams wrote:
Is there a way to call Haskell code from other languages? I have looked on the wiki, and as far as I can see, it only talks about the other way round (when Haskell is the main program).
http://www.haskell.org/haskellwiki/GHC/Using_the_FFI#Calling_Haskell_from_C -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkkZuCkACgkQye5hVyvIUKk1pwCfRbVnERADZPygCNX2wjNkdQOC FXMAoKodV1TitVzr5ZJF/AUSmCXuRuKY =BUkK -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Actually, that's not the whole story. I didn't realize until I sent it. There does exist good documentation for this, I promise. - - Jake -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkkZuHoACgkQye5hVyvIUKnGeACfZN+9nNy+nGvQHDsG1FrI4Puu Zw0AmgKK0WOYTjWWeQX93rrnSJApG0pa =Vazy -----END PGP SIGNATURE-----

"Jake" == Jake Mcarthur
writes:
Jake> Actually, that's not the whole story. I didn't realize until Jake> I sent it. There does exist good documentation for this, I Jake> promise. Good. Let me know where it is when you track it down. The link you pointed me too doesn't seem to address my question directly. Also, it only talks about C. If I want to call Haskell (and I do, perhaps) from another garbage-collected language (Eiffel, in particular) using C as the mutually understood language, am I not going to run into big problems? -- Colin Adams Preston Lancashire

Hello Colin, Tuesday, November 11, 2008, 8:09:09 PM, you wrote:
If I want to call Haskell (and I do, perhaps) from another garbage-collected language (Eiffel, in particular) using C as the mutually understood language, am I not going to run into big problems?
of course not. there will be two independent heaps. of course you can't directly send pointers to gc-collected structures between two languages, they should be converted through buffers in C world (i.e. malloced ones) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On Tue, 2008-11-11 at 17:09 +0000, Colin Paul Adams wrote:
"Jake" == Jake Mcarthur
writes: Jake> Actually, that's not the whole story. I didn't realize until Jake> I sent it. There does exist good documentation for this, I Jake> promise.
Good. Let me know where it is when you track it down.
The link you pointed me too doesn't seem to address my question directly. Also, it only talks about C.
If I want to call Haskell (and I do, perhaps) from another garbage-collected language (Eiffel, in particular) using C as the mutually understood language, am I not going to run into big problems?
Read the FFI Report. It is relatively readable and comprehensive. http://www.cse.unsw.edu.au/~chak/haskell/ffi/ And yes, you will have to use C as an intermediary, though you may not have to actually write any C. You simply expose the Haskell functions in whatever form the other language expects. You'll almost certainly have to write marshalling code of some sort.

On Tue, Nov 11, 2008 at 12:35:05PM -0600, Derek Elkins wrote:
On Tue, 2008-11-11 at 17:09 +0000, Colin Paul Adams wrote:
> "Jake" == Jake Mcarthur
writes: Jake> Actually, that's not the whole story. I didn't realize until Jake> I sent it. There does exist good documentation for this, I Jake> promise.
Good. Let me know where it is when you track it down.
The link you pointed me too doesn't seem to address my question directly. Also, it only talks about C.
If I want to call Haskell (and I do, perhaps) from another garbage-collected language (Eiffel, in particular) using C as the mutually understood language, am I not going to run into big problems?
Read the FFI Report. It is relatively readable and comprehensive. http://www.cse.unsw.edu.au/~chak/haskell/ffi/
And yes, you will have to use C as an intermediary, though you may not have to actually write any C. You simply expose the Haskell functions in whatever form the other language expects. You'll almost certainly have to write marshalling code of some sort.
I often like to look at these situations as an opportunity to introduce modularity and piping. Do you really need them running in the same address space?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

"John" == John Goerzen
writes:
>> Read the FFI Report. It is relatively readable and >> comprehensive. http://www.cse.unsw.edu.au/~chak/haskell/ffi/ >> >> And yes, you will have to use C as an intermediary, though you >> may not have to actually write any C. You simply expose the >> Haskell functions in whatever form the other language expects. >> You'll almost certainly have to write marshalling code of some >> sort. John> I often like to look at these situations as an opportunity John> to introduce modularity and piping. Do you really need them John> running in the same address space? Good point. And thanks everyone for your help. I have enough to go on now. -- Colin Adams Preston Lancashire

"Colin" == Colin Paul Adams
writes:
Colin> And thanks everyone for your help. I have enough to go on Colin> now. I followed the example at http://www.haskell.org/haskellwiki/Calling_Haskell_from_C (and renamed the files from A* to fib1*, as I want to pursue this further). But I get: fib1.o: In function `main': fib1.c:(.text+0x0): multiple definition of `main' fib1.o:fib1.c:(.text+0x0): first defined here fib1_stub.o: In function `stginit_export_Safe_zdffibonaccizuhszuaDN': fib1_stub.c:(.text+0x5): undefined reference to `Safe_zdffibonaccizuhszuaDN_closure' fib1_stub.o: In function `fibonacci_hs': fib1_stub.c:(.text+0x32): undefined reference to `Safe_zdffibonaccizuhszuaDN_closure' collect2: ld returned 1 exit status -- Colin Adams Preston Lancashire

colin:
"Colin" == Colin Paul Adams
writes: Colin> And thanks everyone for your help. I have enough to go on Colin> now.
I followed the example at http://www.haskell.org/haskellwiki/Calling_Haskell_from_C
(and renamed the files from A* to fib1*, as I want to pursue this further).
But I get:
fib1.o: In function `main': fib1.c:(.text+0x0): multiple definition of `main' fib1.o:fib1.c:(.text+0x0): first defined here fib1_stub.o: In function `stginit_export_Safe_zdffibonaccizuhszuaDN': fib1_stub.c:(.text+0x5): undefined reference to `Safe_zdffibonaccizuhszuaDN_closure' fib1_stub.o: In function `fibonacci_hs': fib1_stub.c:(.text+0x32): undefined reference to `Safe_zdffibonaccizuhszuaDN_closure' collect2: ld returned 1 exit status
Not linking in the 'Safe' module on the command line? -- Don

"Colin" == Colin Paul Adams
writes:
"Don" == Don Stewart
writes: Don> Not linking in the 'Safe' module on the command line?
Colin> Could be - I don't know any of this stuff. I was just Colin> following the instructions on the wiki page. Got it working now. It seemed to be some case dependency on the file name. -- Colin Adams Preston Lancashire

colin:
"Jake" == Jake Mcarthur
writes: Jake> Actually, that's not the whole story. I didn't realize until Jake> I sent it. There does exist good documentation for this, I Jake> promise.
Good. Let me know where it is when you track it down.
The link you pointed me too doesn't seem to address my question directly. Also, it only talks about C.
If I want to call Haskell (and I do, perhaps) from another garbage-collected language (Eiffel, in particular) using C as the mutually understood language, am I not going to run into big problems?
No, you can manage objects via e.g. ForeignPtr's. The community has a whole has done bridges between Haskell and pretty much anything you care to name, via the C FFI. Just depends on how well you understand the memory management models of both players. -- Don

I had a proof of concept lying around a couple of years ago in which a
big complicated Ada program called a big complicated Haskell program
and vice versa. The tricky bit from memory was making it link, and
satisfying their rumtime initialisation requirements. No explicit C
was required I think.
Fraser
On 11 nov 2008, at 18:09, Colin Paul Adams
"Jake" == Jake Mcarthur
writes: Jake> Actually, that's not the whole story. I didn't realize until Jake> I sent it. There does exist good documentation for this, I Jake> promise.
Good. Let me know where it is when you track it down.
The link you pointed me too doesn't seem to address my question directly. Also, it only talks about C.
If I want to call Haskell (and I do, perhaps) from another garbage-collected language (Eiffel, in particular) using C as the mutually understood language, am I not going to run into big problems? -- Colin Adams Preston Lancashire _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

colin:
Is there a way to call Haskell code from other languages? I have looked on the wiki, and as far as I can see, it only talks about the other way round (when Haskell is the main program).
http://haskell.org/haskellwiki/Calling_Haskell_from_C Cheers, Don

Hi Colin As an alternative you may consider using Thrift: http://incubator.apache.org/thrift/ Cheers, Dave On Tue, 2008-11-11 at 16:45 +0000, Colin Paul Adams wrote:
Is there a way to call Haskell code from other languages? I have looked on the wiki, and as far as I can see, it only talks about the other way round (when Haskell is the main program).
participants (8)
-
Bulat Ziganshin
-
Colin Paul Adams
-
Dave Tapley
-
Derek Elkins
-
Don Stewart
-
Fraser Wilson
-
Jake Mcarthur
-
John Goerzen