Boxed foreign prim

Johan Tibell johan.tibell at gmail.com
Fri Mar 9 05:19:23 CET 2012


On Thu, Mar 8, 2012 at 8:12 PM, Edward Kmett <ekmett at gmail.com> wrote:
> 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 field
> accessors
>
> ...
>
> This becomes more reasonable to consider when you are forced to make
> something like
>
>> data V4 a = V4 a a a a
>
> using
>
>> unsafeIndex (V4 a _ _ _) 0 = a
>> unsafeIndex (V4 _ b _ _) 1 = b
>> unsafeIndex (V4 _ _ c _) 2 = c
>> unsafeIndex (V4 _ _ _ d) 3 = d
>
> rather than
>
>> unsafeIndex :: V4 a -> Int -> a
>> unsafeIndex = unsafeField

I'm dealing with exactly this problem in unordered-containers. I'm
dealing with small (16) element arrays that I need 1) index into and
2) update a single element off. I use Array# and MutableArray# for
this, but they aren't optimal, mostly because they are optimized for
the case of larger arrays (e.g. they use card tables and out-of-line
allocation.)

-- Johan



More information about the Glasgow-haskell-users mailing list