Boxed foreign prim
ekmett at gmail.com
Fri Mar 9 05:12:37 CET 2012
I'm currently working with a lot of very short arrays of fixed length and
as a thought experiment I thought I would try to play with fast numeric
In particular, I'd like to use something like foreign prim to do something
> foreign import prim "cmm_getField" unsafeField# :: a -> Int# -> b
> unsafeField :: a -> Int -> b
> unsafeField a (I# i) = a' `pseq` unsafeField# a' i -- the pseq could be
moved into the prim, I suppose.
> where a' = unsafeCoerce a
> fst :: (a,b) -> a
> fst = unsafeField 0
> snd :: (a,b) -> b
> snd = unsafeField 1
This becomes more reasonable to consider when you are forced to make
> data V4 a = V4 a a a a
> unsafeIndex (V4 a _ _ _) 0 = a
> unsafeIndex (V4 _ b _ _) 1 = b
> unsafeIndex (V4 _ _ c _) 2 = c
> unsafeIndex (V4 _ _ _ d) 3 = d
> unsafeIndex :: V4 a -> Int -> a
> unsafeIndex = unsafeField
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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Glasgow-haskell-users