2 ms·
Sure, I've played with Haskell-to-C FFI before (a very tiny bit). I'm curious if there are some complications with C->Haskell->C, but maybe not. I'm strongly t
by geofft 12y ago
Sure, I've played with Haskell-to-C FFI before (a very tiny bit). I'm curious if there are some complications with C->Haskell->C, but maybe not.
I'm strongly thinking that Haskell has an advantage here because "well, what if the Haskell function fails" or "well, what if the C function fails" is well-defined by the type system....
Can you return a pointer/reference to a Haskell object to C on one thread, and then call Haskell functions on it from another C thread?
- mietek 12y agoYes. You can use stable pointers for this purpose. A stable pointer is a reference to a Haskell expression that is guaranteed not to be affected by garbage collection, i.e., it will neither be deallocated nor will the value of the stable pointer itself change during garbage collection (ordinary references may be relocated during garbage collection). Consequently, stable pointers can be passed to foreign code, which can treat it as an opaque reference to a Haskell value. https://hackage.haskell.org/package/base-4.7.0.1/docs/Foreign-StablePtr.html https://hackage.haskell.org/package/base-4.7.0.1/docs/Foreig...