<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 1/24/13 9:31 AM, Daniel Díaz
Casanueva wrote:<br>
</div>
<blockquote
cite="mid:CAJFXAQjpUisGERhm2=7i-rg7N27KxuDDD2EzM31+_=GqCbObwA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div><br>
</div>
<div><span style="font-family:courier new,monospace">import
Control.Monad<br>
</span></div>
<span style="font-family:courier new,monospace">import
qualified Data.Sequence as Seq<br>
<br>
</span></div>
<div><span style="font-family:courier new,monospace">type Seq =
Seq.Seq<br>
</span></div>
<div><span style="font-family:courier new,monospace"><br>
</span></div>
<div><span style="font-family:courier new,monospace">f :: Monad
m => Int -> m a -> m (Seq a)<br>
f n = fmap Seq.fromList . replicateM n<br>
<br>
</span></div>
<div><span style="font-family:courier new,monospace">g :: Monad
m => Int -> m a -> m (Seq a)<br>
</span></div>
<div><span style="font-family:courier new,monospace">g =
Seq.replicateM</span><br>
</div>
<div>
<div>
<div>
<div><br>
</div>
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.<br>
</div>
</div>
</div>
</div>
</blockquote>
<br>
Are you forcing the full sequence in both cases? In the former case,
you'll get all the actions, but have a thunk containing the result
of Seq.fromList. In the latter, you're performing the actions as you
build the sequence, so the resultant sequence will be fully
evaluated.<br>
<br>
I imagine that this is the reason that the former seems faster to
you.<br>
<br>
--g<br>
</body>
</html>