Haskell Platform proposal: Add the vector package

Johan Tibell johan.tibell at gmail.com
Tue Jun 19 01:03:30 CEST 2012


On Mon, Jun 18, 2012 at 3:53 PM, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> Slicing is done by directly updating the pointer in the ForeignPtr:
>
> {-# INLINE basicUnsafeSlice #-}
> basicUnsafeSlice i n (Vector _ fp) =
>     Vector n (updPtr (`advancePtr` i) fp)
>
> {-# INLINE updPtr #-}
> updPtr :: (Ptr a -> Ptr a) -> ForeignPtr a -> ForeignPtr a
> updPtr f (ForeignPtr p c) =
>     case f (Ptr p) of { Ptr q -> ForeignPtr q c }
>
> This saves an Int.

(This is off-topic as far as the proposal.)

ByteString has an extra Ptr field so that accessing the data is fast,
given that ForeignPtrs can't be unpacked.

-- Johan



More information about the Libraries mailing list