Feedback on Haskell FFI

f#, ffi, haskell

Solution

How robust is Haskell FFI for passing large arrays of structures?

Everything must be marshalled/unmarshalled at the language barrier. It's common to make large data structures be opaque to one language or the other. That is, if there's a large C data structure, simply keep a pointer to it in Haskell-land and import C functions that do the operations you need; likewise, if there's a large Haskell data structure, expose the Haskell functions that munge it to C-land.

How robust is Haskell FFI for C callbacks?

It is easy and common to turn Haskell closures into C-style function pointers.

Do I use the State monad to retain the large data set in memory between the function calls into the Haskell DLL?

This depends a lot on the API you design. In many cases (e.g. most UI libraries) this is not really feasible, because the main loop is in C, not Haskell; one instead uses `IORef` or similar.

That said: if this is your first Haskell project, I strongly recommend avoiding manual FFI efforts, especially making an attempt to mix Haskell and C++ via the FFI. There's plenty of difficult stuff to get accustomed to without throwing that into the mix. If the only thing you were planning to use it for was UI, then take advantage of others' hard work: there are Haskell bindings to the biggest UI toolkits available on Hackage.

Problem

I am new to functional programming (a C++ / C# programmer mostly) and I am about to start a new project. There are no strict deadlines, and at this point there are no restrictions on which technologies can be used. The core of the project is to parse (relatively) large CSV files and to populate Excel and Word templates. I am considering two approaches, Qt/C++ - Haskell doing the CSV parsing, calculations and such, and C# for UI with F# doing the heavy lifting. I want to start with C++/ Haskell since it is more challenging. My primary concerns are FFI and state in Haskell. How robust is Haskell FFI for passing large arrays of structures and C callbacks? Do I use the State monad to retain the large data set in memory between the function calls into the Haskell DLL? I am new to Haskell :)

Original source