[Haskell-cafe] Calling Haskell from other languages?

Donn Cave donn at avvanta.com
Tue Nov 11 11:59:21 EST 2008


Quoth Colin Paul Adams <colin at colina.demon.co.uk>:

| 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).

There sure is a way to call from other languages - cf. "foreign export" -
but don't know how hard it would be to make Haskell live without its "main",
which performs a lot of runtime initialization.

For me (with nhc98) it's a lot easier to use a Haskell "main" that's just
a brief wrapper:

  module Main (main) where
  import NHC.FFI

  foreign import ccall "cmain" cmain :: IO ()

  main = cmain

(... where "cmain" is an external entry point in the C code, which can
then call Haskell as required.)

	Donn


More information about the Haskell-Cafe mailing list