Why Nostr? What is Njump?
2025-03-24 16:44:08

Grégoire Locqueville on Nostr: I'm trying my hand at writing #haskell bindings to a C library! It's definitely a ...

I'm trying my hand at writing #haskell bindings to a C library! It's definitely a little rough but I'm making good progress 😅

Question:

The C library has functions that produce an array but expect you to manage memory by yourself — so basically, you allocate an array, give the pointer (as well as some other arguments) to the C library function, and the function writes into the array and returns nothing.

In Haskell, this translates to a function `SomeArguments -> Ptr CDouble -> IO ()`. I would like to use that function to define a higher-level binding to that function, in the form of a function of type `SomeArguments -> Vector Double`. What's the best way to do that? This seems like a common enough idiom in C that I assume someone has had to deal with the same thing before, maybe there are some examples out there?
Author Public Key
npub1mghlhx2z6vnmvhhxdu2j66dyylc3ff9y9a56fkdc32uu4wtr8xust94dr4