[C2hs] Feature request: #pointer should add Storable instance

Björn Bringert bringert at cs.chalmers.se
Sat Jun 2 12:31:48 EDT 2007

I'll just keep spamming this list with features I'm missing. I use 
#pointer to create newtypes, but I'm missing Storable instances for the 
produced newtypes. It's very nice to be able to use alloca, peek etc for 
passing pointers around.

Even GHC can't derive Storable since the type is recursive, but it's 
easy to write the instance. Here's what I do now:

{#pointer *SWIrecRecognizer as RecRecognizer newtype #}

instance Storable RecRecognizer where
     sizeOf (RecRecognizer r) = sizeOf r
     alignment (RecRecognizer r) = alignment r
     peek p = fmap RecRecognizer (peek (castPtr p))
     poke p (RecRecognizer r) = poke (castPtr p) r

c2hs could easily produce that Storable instance, and I can't see any 
reason not to.


More information about the C2hs mailing list