[Haskell-cafe] Data.Sequence and replicateM

Daniel Díaz Casanueva dhelta.diaz at gmail.com
Thu Jan 24 18:41:17 CET 2013


Good point. However, I forced the result to evaluate using `deepseq` and I
still got similar results.


On Thu, Jan 24, 2013 at 11:41 AM, Gershom Bazerman <gershomb at gmail.com>wrote:

>  On 1/24/13 9:31 AM, Daniel Díaz Casanueva wrote:
>
>
>  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.
>
>
> 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.
>
> I imagine that this is the reason that the former seems faster to you.
>
> --g
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


-- 
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/c23e10fb/attachment.htm>


More information about the Haskell-Cafe mailing list