[Haskell-cafe] Data.Sequence and replicateM

Daniel Díaz Casanueva dhelta.diaz at gmail.com
Thu Jan 24 15:31:10 CET 2013

Hi Cafe,

I was coding this morning when I suddenly found something that surprised
me. It's been a short time since I am really caring about the performance
of my programs. Before, I was just caring about their correctness. So I am
trying different things and profiling to see differences. One difference I
have found surprising is that the function f is MUCH faster and less space
consuming than the function g:

import Control.Monad
import qualified Data.Sequence as Seq

type Seq = Seq.Seq

f :: Monad m => Int -> m a -> m (Seq a)
f n = fmap Seq.fromList . replicateM n

g :: Monad m => Int -> m a -> m (Seq a)
g = Seq.replicateM

Maybe is just in my test case, where the Int argument is big and the
monadic action short, but it looks to me that Data.Sequence.replicateM can
be faster than it is right now.

Daniel Díaz.

E-mail sent by Daniel Díaz Casanueva

let f x = x in x
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130124/99964110/attachment.htm>

More information about the Haskell-Cafe mailing list