3 ms·
I should have pointed out that my code was theoretical and not actual. My example assumes a (non-tail call) merge sort. Sort specifically was (I felt) a small
by loewenskind 16y ago
I should have pointed out that my code was theoretical and not actual. My example assumes a (non-tail call) merge sort.
Sort specifically was (I felt) a small part of my point but I should have known that on a "hacker" site one must be exact. :)
- ithkuil 16y agoI understand that you wanted to make a simple example, I just wanted to expand a little bit the issue of laziness and make it look slightly less magic. I found a fascinating examples of the expressiveness and beauty of haskell due to lazy evaluation, which I think is better suited for FP evangelism: fibs = 0 : 1 : zipWith (+) fibs (tail fibs) Here we are defining the fibonacci sequence in a declarative way, recursing with a recursive "call". The way the 'fibs' function is coded directly reflects the definition of the fibonacci sequence itself: The 'fibs' list is defined as a list containing the first 2 elements and then, as a tail, the result of the application of the + function on the previous pair of elements. "You can borrow things from the future as long as you don't try to change them"