|
|
|
|
|
by rheeseyb
4902 days ago
|
|
"Nothing is evaluated unless necessary head (sort ls) The list will only be sorted enough to find the minimum" This may be technically true, but is a pretty bad example with much hand waving - what exactly does it mean to be "sorted enough to find the minimum" given that Haskell uses a merge sort implementation internally? A better example of Haskell's lazy nature (taken from the Learn You A Haskell book) would be: take 10 (repeat 5) - it's very easy to comprehend taking the first 10 elements of an infinitely long list without needing to compute the entire list. |
|
Regarding "repeat", I find it pretty much awesome that it is implemented as a circular linked list with a single element, as in:
which ensures that it will take up constant space no matter how "far" in it is evaluated.