[Haskell-cafe] Suggestions for #defines with FFI

John Goerzen jgoerzen at complete.org
Wed Jul 27 16:52:38 EDT 2005


On Wed, Jul 27, 2005 at 03:01:18PM -0400, Dimitry Golubovsky wrote:
> John,
> 
> Could you please give an example of such constant definitions? Is it
> possible to look at the include file?

Incidentally, I looked at hsffig.  There were a couple issues with using
it for this:

1) It didn't declare types for the imported constants, so Haddock
wouldn't generate a list over it.

2) It included all sorts of other #defined items, from other headers
(stdio.h maybe), making it unsuitable to re-export directly to the user.
(I'd have to re-key everything anyway)

3) It tried to list some of the GCC internal conditionals as constants,
making the .hsc not compile unless I manually removed some of them.

I really like the idea, though.  Autodetecting these is great, since
they could vary somewhat from implementation to implementation.

Right now, I'm using hsc2hs, and writing something like this:

#enum LDAPInt, , LDAP_PORT, LDAPS_PORT, LDAP_API_VERSION, LDAP_VENDOR_NAME, \
      LDAP_OPT_API_INFO, LDAP_OPT_DESC, LDAP_OPT_DEREF, \
      LDAP_OPT_SIZELIMIT, LDAP_OPT_TIMELIMIT, LDAP_OPT_REFERRALS, \
      LDAP_OPT_RESTART, LDAP_OPT_PROTOCOL_VERSION, LDAP_OPT_SERVER_CONTROLS, \

That boils down to this:

ldapPort :: LDAPInt
ldapPort =  389
ldapsPort :: LDAPInt
ldapsPort =  636

So I still lack typechecking, and have to manually key in all the
identifiers, but at least the system pulls their values and types in for
me.

-- John


More information about the Haskell-Cafe mailing list