Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yep, the "sort only to get head" trick only works fully with selection sort, where it reduces complexity from O(n^2) to O(n) (reduces to a simple max/min). But it also confers some advantage in the case of standard merge sort: the last two sorted sublists will not be merged.

Regarding "repeat", I find it pretty much awesome that it is implemented as a circular linked list with a single element, as in:

    repeat x = xs where xs = x : xs
which ensures that it will take up constant space no matter how "far" in it is evaluated.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: