<p dir="ltr">I usually use a manually written loop, but you can use Data.Vector for this and it should fuse. </p>
<p dir="ltr">John L.</p>
<div class="gmail_quote">On Apr 26, 2014 2:41 PM, "Niklas Hambüchen" <<a href="mailto:mail@nh2.me">mail@nh2.me</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
As you probably now, `forM_ [1..n]` is incredibly slow in Haskell due to<br>
lack of list fusion [1]; a manually written loop is 10x faster.<br>
<br>
How do you people work around this?<br>
<br>
I keep defining myself something like<br>
<br>
  loop :: (Monad m) => Int -> (Int -> m ()) -> m ()<br>
  loop bex f = go 0<br>
    where<br>
      go !n | n == bex  = return ()<br>
            | otherwise = f n >> go (n+1)<br>
<br>
Is there a function for this somewhere already?<br>
Or do you have another way to deal with this problem?<br>
<br>
Thanks!<br>
<br>
<br>
[1]: <a href="https://ghc.haskell.org/trac/ghc/ticket/8763" target="_blank">https://ghc.haskell.org/trac/ghc/ticket/8763</a><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div>