[Haskell-cafe] How to write fast for loops
jwlato at gmail.com
Sun Apr 27 23:22:26 UTC 2014
On Sun, Apr 27, 2014 at 3:37 PM, Niklas Hambüchen <mail at nh2.me> wrote:
> On 27/04/14 23:18, John Lato wrote:> Hmm. Are you using regular vectors
> or unboxed? Also what sort of crash?
> > Is it a stack space overflow or are you on a 32-bit platform?
> I'm using regular Data.Vector as V.
Are unboxed vectors faster? My rule of thumb is to use them over
Data.Vector whenever possible.
> It's just eating my 8GB and then I kill it (or let my ulimit do it). It
> can't be the stack space since I'm on 7.6 where stack space is limited
> by default.
> It's on 64 bit Linux.
I would expect it's because you never force the argument. With
`enumFromTo` the argument is forced because it needs to be checked for
termination, but `enumFromN` is probably building up a big chain of thunks.
I guess for this case `enumFromN` has no benefit over `enumFromTo` because
the intention is to create a single loop instead of actually allocating the
vector, so the warning in the documentation doesn't necessarily apply.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe