darcs patch: Data.List.sort: force elements from start to end.

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Wed Nov 21 05:29:51 EST 2007


Hi,

the patch below is a trivial change to the merge helper function
of Data.List.sort. Its effect is that the first argument of merge
is evaluated before the second argument instead of vice versa.

I think it's obviously correct. Also, sort is necessarily strict in
the whole list, so there can be no loss of laziness.

Rationale:
The change helps to avoid a stack overflow in the common case where
each element of a list depends on the previous one. Examples for such
lists are '[1..]' or uses of 'iterate f' where f is a strict function.
I believe this case is far more common than the opposite case where
each element of the list depends on the next one, so the patch below is
an improvement.

See also
  http://thread.gmane.org/gmane.comp.lang.haskell.cafe/30598

Bertram


Wed Nov 21 11:14:58 CET 2007  Bertram Felgenhauer <int-e at gmx.de>
  * Data.List.sort: force elements from start to end.
  this prevents a stack overflow on  sort (take 10^6 [1..])

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/x-darcs-patch
Size: 3351 bytes
Desc: A darcs patch for your repository!
Url : http://www.haskell.org/pipermail/libraries/attachments/20071121/55ca8873/attachment.bin


More information about the Libraries mailing list