c2hs icon indicating copy to clipboard operation
c2hs copied to clipboard

Automatically generate Storable instances for enums

Open poscat0x04 opened this issue 5 years ago • 0 comments

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.

poscat0x04 avatar Feb 21 '20 19:02 poscat0x04