c2hs
c2hs copied to clipboard
Automatically generate Storable instances for enums
Enums are CInts in memory so this should work for all types
instance Storable SomeType where
sizeOf _ = 4
alignment _ = 4
peek ptr = do
val <- peek (castPtr ptr)
return $ toEnum $ fromEnum (val :: CInt)
poke ptr v = poke (castPtr ptr) (toEnum $ fromEnum v :: CInt)
It would be nice if we add syntactic sugar for automatically generating storables instances.