deriving instances of Storable

mike V mivori at
Wed Feb 5 04:37:25 EST 2003

Is there any merit in the idea of allowing instances of Storable to be 
derived in a similar fashion to Show, providing that constituents are of 
class Storable.

for instance

(Int, Int)

two Ints would be marshalled into consecutive memory locations in their 
order of declaration.


an Int followed by a String

dealing with constructors
data X = X1 Int | X2   deriving Storable
data Y = Y1 | Y2 deriving Storable

three possible alternatives spring to mind

A) Indexing Constructors by position

X1 -> 0:Int
X2 -> 1

0, 1 represent the constructor indexes
":" represents that the data items are physically contiguous
"->" reads "marshalled as"

This has the disadvantage of being sensitive to the constructor order

B) using the constructor name as the index
X1 -> X1:Int
X2 -> X2

has the disadvantage of requiring a variable amount of memory for the

C) some other hash on the constructor name ?

I would think that implementation would be fairly straight forward?

The benefits would be significant - automatic marshalling of structures.

uses: storing to disk, passing over network etc etc..

MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.

More information about the FFI mailing list