
On 09/01/2013 04:32 PM, Brent Yorgey wrote:
In a perfect world, these constants would be defined as part of an enumeration type, correct? For example,
data WxId = WxIdCancel | WxIdNo | WxIdYes ... deriving (Enum)
in which case the original attempt would have succeeded since it would be matching on a constructor.
However, unless there are constants defined for 0,1,... this approach won't work automatically -- the derived Enum instance starts at zero and increments by one. The library would have to define a custom Enum instance and it would add a good bit of code.
In this case I wouldn't recommend making a custom Enum instance (because the Enum class makes all sorts of assumptions that would be hard to satisfy); I would just make a pair of functions
wxIdToCode :: WxId -> Int wxCodeToId :: Int -> Maybe WxId
Oh, I wasn't suggesting that the OP do this. I was wondering aloud whether or not there was a reason why wxHaskell doesn't define these constants as a separate data type rather than a series of Ints (maybe there's a good reason).