[Haskell-cafe] Marshalling arrays without flakiness?

Ron de Bruijn ron at gamr7.com
Thu Oct 29 07:08:06 EDT 2009


Hi,

I would like to know whether there is a good way to marshal the following 
structure to C without using pointer arithmetic done by a programmer (as opposed 
to a tool).

typedef struct{
	double a[10];
	double b[10];
	double b[10];
} foo;

I don't need this functionality, but it would make Haskell -> C interfaces less 
flaky. Basically, writing Haskell -> C interfaces seem to be a very unpopular 
thing to do (as opposed to C -> Haskell interfaces).

For example, on Hackage (actually a checkout of a few months ago) there is only 
one package using pokeArray and it is not pretty; it uses pointer arithmetic and 
all other kinds of hard-coded addresses. If I change the order of the C fields 
it will break, if I change the length of the buffer they use, it breaks. Just 
look at it, and it will break ;)

If you are a bit creative, it is possible to make it work already, by using the 
best features of both hsc2hs and c2hs, but it is hardly elegant.

I suppose the real solution would be to extend c2hs with an offsetof function 
(for which patches already exist, btw), but it might be that I have missed some 
other solution.

-- 

Best Regards,
Ron de Bruijn,
Developer, Gamr7


More information about the Haskell-Cafe mailing list