[Haskell-cafe] How to write fast for loops
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sun Apr 27 07:47:32 UTC 2014
On Sun, Apr 27, 2014 at 03:32:12AM +0200, Daniel Fischer wrote:
> On Saturday 26 April 2014, 22:40:50, Niklas Hambüchen wrote:
> > As you probably now, `forM_ [1..n]` is incredibly slow in Haskell due to
> > lack of list fusion ;
> It's not the lack of list fusion per se. If you have a
> forM_ [a .. b] $ \n -> do stuff
> where the type is Int, GHC is perfectly capable of eliminating the list and
> rewriting it to a loop (usually on par with a hand-written loop, although the
> core you get from a hand-written loop often is smaller and nicer to look at).
> The problem is that you use the same list multiple times, and GHC thinks "hey,
> let me re-use that", so it gets floated to the top-level
If this is the case, does -fno-full-laziness help?
More information about the Haskell-Cafe