by eru · 14y ago · 0 comments
iPhone Monad, anyone?
http://www.haskell.org/haskellwiki/FFICookBook#Working_with_...
I used the following references:
http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/ffi-g...
http://weblog.haskell.cz/pivnik/building-a-shared-library-in...
I have just put up a small-ish example using my approx-rand-test package (which implements approximate randomization tests):
https://github.com/danieldk/haskell-library-example/
Is the gain rom Haskell worth the impedance mismatch of cross communication?
I guess it depends on how much you love Haskell ;), and the usage scenario. I think using Haskell's FFI in this direction is especially attractive if you prefer to write most code in Haskell, but need some functionality that does not map naturally to a pure functional language (such as GUIs in Cocoa). If you want to mix a lot of imperative and functional code seamlessly, F#/C# or Scala/Java are probably better options.
Historically, C was used to implement many (functional) programming languages because it provided a convenient compiler back end and a well-defined intermediate representation between the front end and the back end. Not because you could compile to C and use your code from C.
- Using the FFI one can specify foreign exports.
- The runtime and garbage collector can be initialized/deinitialized by adding an object file that uses gcc's constructor/destructor attributes.
- Multiple calls to hs_init (one for each library) are allowed, as long as they are balanced by hs_exits.
- It's ok to have multiple root modules.