On Mon, Mar 12, 2012 at 6:45 AM, Simon Marlow <span dir="ltr">&lt;<a href="mailto:marlowsd@gmail.com">marlowsd@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">But I can only pass unboxed types to foreign prim.<br>
<br>
Is this an intrinsic limitation or just an artifact of the use cases<br>
that have presented themselves to date?<br>
</blockquote>
<br></div></div>
It&#39;s an intrinsic limitation - the I# box is handled entirely at the Haskell level, primitives only deal with primitive types.<br></blockquote><div><br></div><div>Ah. I was reasoning by comparison to atomicModifyMutVar#, which deals with unboxed polymorphic types, and even lies with a too general return type. Though the result there is returned in an unboxed tuple, the argument is passed unboxed.</div>
<div><br></div><div>Is that implemented specially?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
But anyway, I suspect your first definition of unsafeIndex will be faster than the one using foreign import prim, because calling out-of-line to do the indexing is slow.  </blockquote><div><br></div><div>Sure though, I suppose that balance of may shift as the side of the short vector grows. (e.g. with Johan it&#39;d probably be 16 items).</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Also pseq is slow - use seq instead.<br></blockquote><div><br></div><div>Of course. I was being paranoid at the time and trying to get it to work at all. ;)</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
what you really want is built-in support for unsafeField#, which is certainly do-able.  It&#39;s very similar to dataToTag# in the way that the argument is required to be evaluated - this is the main fragility, unfortunately GHC doesn&#39;t have a way to talk about things that are unlifted (except for the primitive unlifted types).  But it just about works if you make sure there&#39;s a seq in the right place.</blockquote>
<div><br></div><div>I&#39;d be happy even if I had to seq the argument myself before applying it, as I was trying above.</div><div> </div></div><div>-Edward</div>