The Binding Generator C->Haskell : Implementation of Haskell Binding Modules : Enumeration Hooks
Previous: Sizeof Hooks
Next: Call Hooks

2.5. Enumeration Hooks

{#enum cid [as hsid] {alias1 , ... , aliasn} [with prefix = pref] [deriving (clid1 , ... , clidn)]#}

Rewrite the C enumeration called cid into a Haskell data type declaration, which is made an instance of Enum such that the ordinals match those of the enumeration values in C. This takes explicit enumeration values in the C definitions into account. If hsid is given, this is the name of the Haskell data type. The identifiers clid1 to clidn are added to the deriving clause of the Haskell type.

By default, the names of the C enumeration are used for the constructors in Haskell. If alias1 is underscoreToCase, the original C names are capitalised and the use of underscores is rewritten to caps. If it is upcaseFirstLetter or downcaseFirstLetter, the first letter of the original C name changes case correspondingly. It is also possible to combine underscoreToCase with one of upcaseFirstLetter or downcaseFirstLetter. Moreover, alias1 to aliasn may be aliases of the form cid as hsid, which map individual C names to Haskell names. Instead of the global prefix introduced by a context hook, a local prefix pref can optionally be specified.

As an example, consider

{#enum WindowType {underscoreToCase} deriving (Eq)#}

Note: The enum define hooks described in the C->Haskell paper are not implemented yet.


The Binding Generator C->Haskell : Implementation of Haskell Binding Modules : Enumeration Hooks
Previous: Sizeof Hooks
Next: Call Hooks