On Mon, Mar 12, 2012 at 6:45 AM, Simon Marlow <marlowsd@gmail.com> wrote:
It's an intrinsic limitation - the I# box is handled entirely at the Haskell level, primitives only deal with primitive types.But I can only pass unboxed types to foreign prim.
Is this an intrinsic limitation or just an artifact of the use cases
that have presented themselves to date?
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.
Also pseq is slow - use seq instead.
what you really want is built-in support for unsafeField#, which is certainly do-able. It's very similar to dataToTag# in the way that the argument is required to be evaluated - this is the main fragility, unfortunately GHC doesn'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's a seq in the right place.