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

Elliot Cameron elliot.cameron at covenanteyes.com
Thu May 14 12:37:42 UTC 2015


More specificity might be appropriate since there are many ways to "size" things: perhaps "ByteSized" in this context. 

Let the puns begin. 

-----Original Message-----
From: Haskell-Cafe [mailto:haskell-cafe-bounces at haskell.org] On Behalf Of Roman Cheplyaka
Sent: Thursday, May 14, 2015 8:13 AM
To: jones.noamle at gmail.com; haskell-cafe at haskell.org
Subject: Re: [Haskell-cafe] Suggestion: "Sizable" super class for Storable

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'?




More information about the Haskell-Cafe mailing list