Heap representation evil

Brandon Moore brandonm at yahoo-inc.com
Tue Oct 24 01:13:52 EDT 2006


John Meacham wrote:

> I am not sure if you can't use them for some reason, but this sounds
> like exactly the problem that stable pointers are meant to solve:
> 
> http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-StablePtr.html

Which problem? Mostly, I noticed that evaluated Haskell values greatly resemble
a header word plus a C struct, and was thinking this could be (ab)used for working
with C code, and might make it easier to manipulate values on the Haskell side.
Plus, it was fun figuring out how use unsafeCoerce# and Box to manufacture
a Ptr to an ordinary Haskell value.

Stable pointers might help with the GC relocating things, except I don't think
having a stable pointer guarantees that the object won't be moved around, just
that the stable pointer won't be invalidated by GC.

> On Mon, Oct 23, 2006 at 06:43:26PM -0700, Brandon Moore wrote:
>   
>> A different and in all likelihood saner approach is building up more 
>> tools for manipulating pointers to C data from Haskell, perhaps along 
>> the lines of cmucl's support for "Alien Objects".
>> http://www.math.sunysb.edu/~sorin/online-docs/cmucl/aliens.html
>>     
>
> sorry to respond twice to the same mail, but have you seen hsc2hs? it
> can let you access arbitrary components of structures defined in C, or
> have haskell values that map to unknown c integral types in a portable
> way. 
>
> hsc2hs is nice. it is the minimum needed to write portable haskell ffi
> using code.
Thanks, I've seen related things in c2hs, but I didn't realize
hsc2hs came with GHC.

Brandon


More information about the Glasgow-haskell-users mailing list