[Haskell-cafe] How to write fast for loops
jwlato at gmail.com
Sun Apr 27 00:13:52 UTC 2014
I usually use a manually written loop, but you can use Data.Vector for this
and it should fuse.
On Apr 26, 2014 2:41 PM, "Niklas Hambüchen" <mail at nh2.me> wrote:
> As you probably now, `forM_ [1..n]` is incredibly slow in Haskell due to
> lack of list fusion ; a manually written loop is 10x faster.
> How do you people work around this?
> I keep defining myself something like
> loop :: (Monad m) => Int -> (Int -> m ()) -> m ()
> loop bex f = go 0
> go !n | n == bex = return ()
> | otherwise = f n >> go (n+1)
> Is there a function for this somewhere already?
> Or do you have another way to deal with this problem?
> : https://ghc.haskell.org/trac/ghc/ticket/8763
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe