On Sun, Dec 6, 2009 at 12:31 PM, John Reppy <span dir="ltr"><<a href="mailto:jhr@cs.uchicago.edu">jhr@cs.uchicago.edu</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Because MLton doesn't provide a way to dynamically define callbacks, I need to manage<br>
the a mapping from C pointers to ML functions. I'd like to use a hash table to do<br>
this, but there isn't an easy way to compute hash keys from pointers. I'd like<br>
to see a function<br>
<br>
val hash : t -> word<br>
<br>
added to the MLTON_POINTER signature.<br></blockquote><div><br>If you believe that the C address is unique enough to be a hash key, doesn't<br> val hash = fn p => MLton.Pointer.diff(MLton.Pointer.null, p)<br>suffice as a hashing function? In any case, I think any hashing of a pointer would start with its address, so you can do a mixing function from there if you don't think the distribution of C addresses suffice as a hashing key. Admittedly, this is in terms of Word.word, which defaults to a 32-bit value; MLton.Pointer.diff performs the difference computation at the target pointer size, and then does a low-bits projection to a 32-bit word. Still, that ought to be decent for a hash function. Perhaps all of the MLton.Pointer functions should be in terms of LargeWord.word.<br>
<br>Also,<br> val MLton.hash : 'a -> Word32.word<br>is a polymorphic hash function that works with any ML value.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
As a more long-term request, it would be nice to have something like the GHC notion<br>
of stable pointers that would allow ML values to be passed to C code for later supply<br>
as arguments to callbacks.<br></blockquote><div><br>Yes, some notion of registering an exported ML value would be desirable.<br><br>-Matthew <br></div></div><br>