Let’s say charm.c has an enum key and a function get_key() that returns a key type value.
How can I expose a corresponding Haskell Key record and function getKey :: IO Key?
And how can I do this without manually specifying how every single enum value maps to a Haskell value?
For @KevinReid, here’s an example of how to do this with c2hs.
Given the enum
keyin the filecharm.h(I have no idea what’s in the enum, so I just filled in a few values)You can use c2hs’s enum hook like this:
To bind to a function, you can use either
callorfun.callis simpler, but doesn’t do any marshaling. Here are examples of both. The ffi-wrappedget_keywill return a CInt, so you need to either manually marshal it (if usingcall) or specify the marshaller (if usingfun). c2hs doesn’t include enum marshallers so I’ve written my own here:C2hs will generate the following Haskell from this (slightly cleaned up):