News for hackers. Stuff that matters.
Re:Turn O(n^2) reverse into O(n) by zvrba on Monday December 16, 2013 @03:32AM (#6913516)
So the original line of code has apparently been present since the very first import by Sigbjørn Finne in https://github.com/nominolo/HTTP/blob/c4765e822eb92196fec955... (check line 443).

If a Haskell expert (e.g., he authored hdirect -- an IDL compiler and interface with Win32 COM -- sadly defunct now) makes this kind of mistake, how are mere mortals supposed to reason about algorithmic efficiency?

Re:Turn O(n^2) reverse into O(n) by velis_vel on Monday December 16, 2013 @04:47AM (#6913745)
I don't think this was an 'oh my god we're trying to track down why cabal update is so slow and we just can't find it' issue like you make it out to be.

edit: http://www.reddit.com/r/haskell/comments/1sh67u/the_reason_w... This comment by the patch author indicates that actually tracking it down was a fairly straightforward profiling job.

Re:Turn O(n^2) reverse into O(n) by zvrba on Monday December 16, 2013 @05:58AM (#6914001)
I didn't try to imply that it was difficult to find the performance problem. It's an observation on something else: Haskell is often mentioned for its equational reasoning. I find it interesting that correct equational reasoning in this case lead to a correct program, but one with absymal performance.

It'd be interesting to think how one could encode performance characteristics into equations.

Re:Turn O(n^2) reverse into O(n) by Peaker on Monday December 16, 2013 @12:06PM (#6916067)
I think having simple and direct denotational semantics necessarily means having relatively complex, indirect operational semantics (e.g: Haskell). Having a simple and direct operational semantics necessarily means having complex and indirect denotational semantics (e.g: C).

C makes performance easy and correctness hard. Haskell makes correctness easy and performance hard.

The trick is, in most programs, you only need performance for a tiny subset of the program. You need correctness throughout the whole program.

Re:Turn O(n^2) reverse into O(n) by zvrba on Tuesday December 17, 2013 @02:28AM (#6919987)
Why do you think that there must be a tradeoff between simplicity of denotational and operational semantics?
Re:Turn O(n^2) reverse into O(n) by Peaker on Tuesday December 17, 2013 @08:03AM (#6920858)
Because operational semantics (of contemporary computers, at least) are very different from a simple denotational semantics.

We have to bridge that gap:

1) Either use a compiler that hides away the operational details

2) Or use a language that directly maps to the operational semantics, but then is necessarily far away from the denotational ones

Re:Turn O(n^2) reverse into O(n) by jjaredsimpson on Monday December 16, 2013 @06:58AM (#6914209)
Its known that postpending to a linked list is slow. It's just a property of the data type.
Re:Turn O(n^2) reverse into O(n) by velis_vel on Monday December 16, 2013 @12:12PM (#6916121)
> I find it interesting that correct equational reasoning in this case lead to a correct program, but one with absymal performance.

That's not really an interesting property of Haskell, though. You can always write correct but slow code in any language.

> It'd be interesting to think how one could encode performance characteristics into equations.

I've seen the concept of encoding performance in types played around with, but I can't find actual work (if any) that's been done on it.

Re:Turn O(n^2) reverse into O(n) by eru on Monday December 16, 2013 @10:32PM (#6919442)
> You can always write correct but slow code in any language.

Yes, but Haskell makes that exceptionally easy.

Re:Turn O(n^2) reverse into O(n) by sjtgraham on Monday December 16, 2013 @04:06AM (#6913607)
Humans occasionally make mistakes, including expert ones.
Re:Turn O(n^2) reverse into O(n) by vanderZwan on Monday December 16, 2013 @07:51AM (#6914394)
Exactly. Isn't it comforting to know that making mistakes is only human? And isn't this a wonderful practical example of why you want to be open source?
Re:Turn O(n^2) reverse into O(n) by microtherion on Monday December 16, 2013 @07:33AM (#6914342)
I suppose what Alan Perlis said about LISP programmers—that they know the value of everything and the cost of nothing—is true for Haskell programmers as well.
Re:Turn O(n^2) reverse into O(n) by kovalkos on Monday December 16, 2013 @09:05AM (#6914716)
This is a bad application of the quote.

Most of the Lisp hackers are usually knowledgeable about analysis of algorithm complexity.

Alan Perlis comment talks about inefficiency of Lisp programs due to a lot of (meta) abstraction and indirect mapping of abstract software to hardware.

Re:Turn O(n^2) reverse into O(n) by microtherion on Tuesday December 17, 2013 @08:53PM (#6925396)
Admittedly, this particular case seems amenable to fairly straightforward algorithmic complexity analysis, but it seems to me that the lazy nature of Haskell seems to make it even harder to get a good grasp of costs involved than in a language like Lisp.
Re:Turn O(n^2) reverse into O(n) by nilkn on Monday December 16, 2013 @11:49AM (#6915921)
Mistakes of this sort have been made in many languages. I don't see what this has to do with Haskell specifically.
Re:Turn O(n^2) reverse into O(n) by hesselink on Monday December 16, 2013 @10:29AM (#6915260)
I think back then, the 'n' just wasn't very large, so O(n) versus O(n^2) didn't make much of a difference.
Re:Turn O(n^2) reverse into O(n) by 6d0debc071 on Monday December 16, 2013 @04:08AM (#6913613)
Advantage in focus - maybe he wrote it once and didn't look back at it. Low hanging fruit elsewhere for typical use case?
Re:Turn O(n^2) reverse into O(n) by eru on Monday December 16, 2013 @10:30PM (#6919436)
> [...] how are mere mortals supposed to reason about algorithmic efficiency?

You profile, and then you look at the suspicious parts.