[Haskell-cafe] Re: How do I avoid stack overflows?

DavidA polyomino at f2s.com
Sat Mar 17 04:01:49 EDT 2007


Thanks for the suggestions. A few more questions.

The (<<*>>) function is just one of a number of lazy matrix arithmetic 
functions that I have. If I need them to be evaluated strictly, is it best to 
modify the matrix code, or the code that's calling it?

In this case, it looks like I can fix the problem by modifying the calling 
code. For example:

test3 = iterate' (\m -> sum (map last m) `seq` m <<*>> id3) id3 !! 1000000

This works fine with the *unmodified* version of (<<*>>). However, note that 
I've had to do some unnecessary work - sum (map last m). Is there a better way?

Or, is it better to modify the matrix code itself? Perhaps there's an argument 
that matrix arithmetic should be strict - after all, integer arithmetic is 
strict. But it seems potentially useful to have at least (<<+>>) as lazy, so 
that I can add together infinite matrices.

Which is best?

Thanks in advance.

More information about the Haskell-Cafe mailing list