24 Jan 15:31 2013

## Data.Sequence and replicateM

Daniel Díaz Casanueva <dhelta.diaz <at> gmail.com>

2013-01-24 14:31:10 GMT

2013-01-24 14:31:10 GMT

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 Seqtype Seq = Seq.Seq

f :: Monad m => Int -> m a -> m (Seq a)

f n = fmap Seq.fromList . replicateM n

f n = fmap Seq.fromList . replicateM n

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

g = Seq.replicateM

Regards,

Daniel Díaz.

--

E-mail sent by Daniel Díaz Casanueva

let f x = x in x

_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe <at> haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe