[Haskell-cafe] Suggestion: "Sizable" super class for Storable

Roman Cheplyaka roma at ro-che.info
Thu May 14 12:12:45 UTC 2015


On 14/05/15 11:50, jones.noamle at gmail.com wrote:
> Storable instances have a size, given by sizeOf.
> 
> In many cases, we're not interested in peeking/poking data but only
> passing it opaquely via the FFI. A common use case is when the C API
> offers an "init" function such as:
> 
>     void mycontext_init(mycontext *context);
> 
> For these cases it would be useful to know the size of "mycontext", so
> we could malloc it and pass a pointer to mycontext_init. 
> 
> Also, it allows Haskell-side code to decide how it wants to allocate the
> data, perhaps using some other (external) mechanism not related to the
> specific API that the FFI bindings are wrapping.
> 
> c2hs would benefit by allowing users to use the '+' notation in function
> parameters (which generate  malloc-and-pass style code), without having
> to guess the size of the structure. Instead, it could simply use the
> Sizable (TM) instance to get the size, and the user will define Sizable
> in any way they want (for example, using the {#sizeof#} macro, which is
> somewhat unreliable, or by hard-coding or manually entering the size or
> by some other method).
> 
> 
> Your thoughts are much appreciated!

+1, I've needed this in the past. How about 'Sized' instead of 'Sizable'?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150514/786f80c8/attachment.sig>


More information about the Haskell-Cafe mailing list