[Haskell-cafe] Data.Vector.Mutable.mapM

Ertugrul Soeylemez es at ertes.de
Thu Oct 20 23:10:56 CEST 2011


Joachim Breitner <mail at joachim-breitner.de> wrote:

> I’m consdering to change some performance critical code from Vector to
> MVector, hopefully avoiding a lot of copying and garbage collecting. But
> it seems that the Data.Vector.Mutable interface at
> http://hackage.haskell.org/packages/archive/vector/0.9/doc/html/Data-Vector-Mutable.html  is quite limited; e.g. I am missing simple functions having type
>         modifyM :: PrimMonad m => (a -> m a) -> MVector (PrimState m) a -> m ()
> that would do something with each element in the vector.
>
> Is this an indication that such use is actually not desired, or is it
> just the case that nobody has developed that yet?

In general you should try to work with immutable vectors as much as
possible.  Done properly you shouldn't lose much performance that way.

However, sometimes an operation is just much easier to express and
faster with the MVector interface.  In these cases you can escape to the
mutable interface using 'create', 'modify', 'thaw' and 'freeze'.  Don't
forget that you lose fusion that way, though.

In other words:  Don't use MVector exclusively.  Use it only when you
really need it.


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111020/b098fc3e/attachment.pgp>


More information about the Haskell-Cafe mailing list