Re: Storable tuples and what is 'alignment'?
Redirected to ffi@haskell.org
1) Why aren't there built in Storable instances for tuples? Writing my own is a pain and in keeping with the 'up to 7tuple' limit, I think built in instances would be nice
Probably because we've no idea why you'd want to do it. The usual deal is that you want to interface to a C struct like this: struct pt { int x; int y; }; and want to access it from Haskell so you write something like: type Pt = (CInt,CInt) instance Storable Pt where alignment = #const alignOf(struct pt) sizeOf = #const sizeof(struct pt) peek p = do x <- peek (p + #const(offsetOf(struct pt, x))) y <- peek (p + #const(offsetOf(struct pt, y))) return (x,y) poke ... = ... That is, for each C type you encounter, you write a custom instance. An important thing about this is that you're definitely using the right offset to access the field - there's nothing in the C standard that requires the obvious relationship between alignment/size and offset to hold. So what are you doing that needs Storable instances for arbitrary tuples? -- Alastair Reid alastair@reid-consulting-uk.ltd.uk Reid Consulting (UK) Limited http://www.reid-consulting-uk.ltd.uk/alastair/
Probably because we've no idea why you'd want to do it.
That's a pretty good reason :).
That is, for each C type you encounter, you write a custom instance.
Ah, here's the problem. There is no corresponding C type :). I'm using hMPI and need to pass around an array of arrays of int,double pairs. What I'll do is basically flatten everything out and pass the int side in one pass and the double side in another pass... Nevermind then, I was just tyring to avoid more work :) - Hal
participants (2)
-
Alastair Reid -
Hal Daume III