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

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Jun 4 06:39:40 EDT 2007

On Sat, 2007-06-02 at 18:31 +0200, Björn Bringert wrote:
> 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.

So this gives it a storable instance that interprets the newtype as a
pointer, but not as the thing pointed to? (which would be the usual
interpretation right?) I'm not sure I understand why you would want
this, and even if you did it'd prevent people doing the more normal
Storable instance for the thing pointed to. I'm clearly missing
something here.


More information about the C2hs mailing list