Suggestions for #defines with FFI

Hi, I'm writing a Haskell interface to a library that #defines about 100 constants corresponding to numeric exit codes. It also defines hundreds of contants, over the same numbering ranges, for other purposes. The exit codes are non-contiguous as well. So my question is: is there a nice way I can represent this in Haskell, preferably without having to key in all 100 constants? Or will I just have to list all the options and give up type checking to differentiate one purpose of a constant from another? Thanks, -- John

On Wed, Jul 27, 2005 at 01:28:38PM -0500, John Goerzen wrote:
I'm writing a Haskell interface to a library that #defines about 100 constants corresponding to numeric exit codes. It also defines hundreds of contants, over the same numbering ranges, for other purposes. The exit codes are non-contiguous as well.
So my question is: is there a nice way I can represent this in Haskell, preferably without having to key in all 100 constants?
Did you consider hsc2hs? Best regards Tomasz

On Wed, Jul 27, 2005 at 10:52:41PM +0200, Tomasz Zielonka wrote:
On Wed, Jul 27, 2005 at 01:28:38PM -0500, John Goerzen wrote:
I'm writing a Haskell interface to a library that #defines about 100 constants corresponding to numeric exit codes. It also defines hundreds of contants, over the same numbering ranges, for other purposes. The exit codes are non-contiguous as well.
So my question is: is there a nice way I can represent this in Haskell, preferably without having to key in all 100 constants?
Did you consider hsc2hs?
Yes. That's what I'm using now. It does pull in the values for the consts, but that's about it. I still have to key everything in manually. -- John

John Goerzen
On Wed, Jul 27, 2005 at 10:52:41PM +0200, Tomasz Zielonka wrote:
On Wed, Jul 27, 2005 at 01:28:38PM -0500, John Goerzen wrote:
I'm writing a Haskell interface to a library that #defines about 100 constants corresponding to numeric exit codes. It also defines hundreds of contants, over the same numbering ranges, for other purposes. The exit codes are non-contiguous as well.
So my question is: is there a nice way I can represent this in Haskell, preferably without having to key in all 100 constants?
Did you consider hsc2hs?
Yes. That's what I'm using now. It does pull in the values for the consts, but that's about it. I still have to key everything in manually.
I don't know whether this will be a helpful suggestion or not, because it still requires to key in all constants, but nhc98 uses the following configuration technique to grab the "errno.h" constants into an enumerated Haskell datatype, with instances of Eq, Ord, and Enum. There is a little haskell program, GenerateErrNo.hs, which is run to generate a C program, which is then run to generate the Haskell module I require. The source code is attached. Maybe you can adapt it for your purposes. Another suggestion for an FFI tool specifically designed for this kind of problem is c2hs: http://www.cse.unsw.edu.au/~chak/haskell/c2hs/ Regards, Malcolm
participants (3)
-
John Goerzen
-
Malcolm Wallace
-
Tomasz Zielonka