[Haskell-cafe] FFI - Approaches to C/C++

Ertugrul Söylemez es at ertes.de
Thu Jan 31 09:23:56 CET 2013


Casey Basichis <caseybasichis at gmail.com> wrote:

> I'm not entirely sure what you mean.
>
> I'm intending on using Ogre for GUI - for which there is the Hogre
> bindings, but after emailing the DEV about it, I didn't get the
> impression from his advice that I should be using it for production
> code.  Here is what he suggested:
>
> "It depends, really. Hogre is good for running Ogre from within
> Haskell, but it has its limitations. The number one thing people have
> been struggling with is handling input with hogre - there's Hois
> (Haskell wrapper for OIS) but it's not perfect (it misses input
> events), and the other option is having to write some C++ glue. Hogre
> is a solid proof of concept and you can do some demos with it, but if
> you're e.g. writing a game it might be a bit of a struggle. In the end
> it's about how much you value being able to write code in Haskell (or
> how allergic to C++ you are)."
>
> I'm on iOS so I imagine those difficulties are compounded.
>
> I am using several other C++ libraries for which there are no existing
> bindings and no Haskell alternative packages that are even remotely
> close.
>
> Are you suggesting it would be better to write all my own FFI bindings
> for all the needed libraries?

That's not what I'm suggesting.  It was just too little information to
properly judge the difficulty of doing everything in Haskell.

Binding to Ogre (or C++ in general) is indeed difficult.  If Hogre
doesn't work or is too limited, your best option might be to write a C
wrapper around the Hogre functionality you need.  Another option is to
use SDL/OpenGL directly, which may be easier or harder depending on your
application.

However, if you can build the bridge between your rendering library and
Haskell, then Haskell is certainly the better choice.


> Everything I read suggests that Haskells strengths are in
> transformation and that interaction is not its strong suit.
>
> I am interested in your thoughts and I am open to whatever, but you
> are the first to suggest that the mix is a bad idea.

That used to be true, but the reason has nothing to do with the
language.  The problem was that the libraries weren't there.  Nowadays
you can write all sorts of interactive applications in Haskell,
including GUIs, TUIs, games, simulations and web applications.  However,
I've long been waiting for useful bindings to Ogre or Irrlicht, but I'm
afraid that it's not going to happen any time soon.

Ultimately it's your choice.  Let me summarize the possiblities:

  * C wrapper around Ogre.  Easy integration, but need to write the
    rendering code in C/C++.

  * Full FFI bindings to Ogre.  Difficult integration, but you can write
    your rendering code in Haskell.

  * Partial FFI bindings to Ogre.  Integration may be somewhat easy, if
    you do the initialization in Haskell and the actual rendering in
    C/C++.  However, this again requires to write the rendering in
    C/C++.

  * Using SDL/OpenGL directly:  Everything available for Haskell.  May
    be difficult, because you need to write OpenGL code.

I hope, this helps.


Greets,
Ertugrul

-- 
Key-ID: E5DD8D11 "Ertugrul Soeylemez <es at ertes.de>"
FPrint: BD28 3E3F BE63 BADD 4157  9134 D56A 37FA E5DD 8D11
Keysrv: hkp://subkeys.pgp.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130131/54bad965/attachment.pgp>


More information about the Haskell-Cafe mailing list