The problem is FFI wrapping a C-Type that requires two environment variables for initialization and de-allocation with a ForeignPtr
More concretely I want to wrap
void gr_mpoly_init(gr_mpoly_t A, const mpoly_ctx_t mctx, gr_ctx_t cctx)
and
void gr_mpoly_clear(gr_mpoly_t A, const mpoly_ctx_t mctx, gr_ctx_t cctx)
for a Haskell type GRMPoly ... .
So the question is how to define something like
addForeignPtrFinalizerEnv2 myfinalizer mypointer env1 env2
I looked at the source of of addForeignPtrFinalizerEnv
in ForeignPtr.ForeignPtr
but that seems to require an understanding of the underlying "magic" (include #).
So what are "elegant" alternatives?
The simplest solution I could come up with was defining a container for the two pointers including the extra infrastructure for allocating and deallocation and wrapping in Haskell.
I would expect a simpler, more elegant solution ...