[Haskell-cafe] How to write fast for loops

Carter Schonwald carter.schonwald at gmail.com
Sun Apr 27 03:20:54 UTC 2014

John, can't a careful use of the identity monad or the like prevent that
CSE? (i'm a bit fuzzy on that piece of ghc lore)

On Sat, Apr 26, 2014 at 10:28 PM, John Lato <jwlato at gmail.com> wrote:

> Hi Niklas,
> No, I mean this:
> > V.forM_ (V.enumFromN 1 n)
> I agree it's less elegant.  And like Daniel points out with lists, you
> definitely don't want the "enumFromN" to be shared.  But one of the biggest
> warts of Haskell IMHO is that it's still very difficult to get really
> high-performance code without an intimate understanding of the optimizer.
> John L.
> On Sat, Apr 26, 2014 at 6:16 PM, Niklas Hambüchen <mail at nh2.me> wrote:
>> Hey John,
>> do you mean something along the lines of `V.forM_ (fromList [1..n])`?
>> I guess GHC wouldn't mash away the list in this case and I'd have to
>> use the new OverloadedLists with `V.forM_ [1..n]` (indeed that looks
>> quite sweet).
>> However, would that actually be fast? Judging from how list syntax is
>> desugared, I guess that would use `V.enumFromTo` then, whose docs claim
>> "WARNING: This operation can be very inefficient. If at all possible,
>> use enumFromN instead".
>> Does anybody know  wonder if "vector literals" desugar enumFromN, or
>> what "can be very inefficient" means?
>> Niklas
>> On Sun 27 Apr 2014 01:13:52 BST, John Lato wrote:
>> > I usually use a manually written loop, but you can use Data.Vector for
>> > this and it should fuse.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140426/24416c55/attachment.html>

More information about the Haskell-Cafe mailing list