mapM_ for bytestring

Shachaf Ben-Kiki shachaf at
Sun Sep 1 18:44:17 CEST 2013

On Sun, Sep 1, 2013 at 6:16 AM, Henning Thielemann
<lemming at> wrote:
>>     mapM  :: Monad m => (Word8 -> m Word8) -> ByteString -> m ByteString
> This one can become very inefficient. Think of m = [], then many ByteStrings
> have to be constructed by repreated ByteString.cons which requires a lot of
> copying. For lists "cons" aka (:) is efficient because the tails are shared.

You don't need to cons -- you can allocate one ByteString and write
into it unsafely (just like map does). See


More information about the Libraries mailing list