5 ms·
FWIW the demo snippet is a toy and not the real quicksort, which is in-place, rather than copying the list / creating garbage at every step. Ironically it say
by chubot 10y ago
FWIW the demo snippet is a toy and not the real quicksort, which is in-place, rather than copying the list / creating garbage at every step.
Ironically it says "A powerful language for building scalable systems on the JVM" but this literally doesn't scale as quicksort does.
http://stackoverflow.com/questions/7717691/why-is-the-minimalist-example-haskell-quicksort-not-a-true-quicksort http://stackoverflow.com/questions/7717691/why-is-the-minima...
https://wiki.haskell.org/Introduction#Quicksort_in_Haskell https://wiki.haskell.org/Introduction#Quicksort_in_Haskell
This is related to the "Genuine Sieve of Eratosthenes", which is also an imperative algorithm and NOT a functional one:
https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
This brings to mind the slur "Haskell (Lisp) programmers know the value of everything but not the cost".
- petters 10y agoI saw that quicksort code when I looked at Haskell back in 2002. Why is that still used as an example? I have seen in-place quicksort in Haskell and it is not pretty.
- nine_k 10y agoThe example is simple and expressive, it's relatively easy to understand even if you don't known the language. It gives you the idea of the expressive power. It's not performant, though, and should not be considered a real quicksort implementation. So it's not showing you the cost of this particular abstraction.
- rahulmutt 10y ago"Relatively easy to understand even if you don't know the language" <- We have empirically verified this by showing code samples of quicksort side-by-side in Java, Scala, Clojure, and Eta to ~100 programmers who had no experience with functional programming at an exhibition. Eta won, followed closely by Scala (people just love their curly braces!). One person liked Clojure because of "it looked like English" and no one liked Java. For this reason, we have posted it on the landing page. We have made no claims that it's the most performant nor that it's the fully correct quicksort (accounting for uniques) - the whole point was to highlight the expressiveness.
- taeric 10y agoI'm curious, though, if this is really applicable. There are two problems, to me. First, this is not a good implementation of quicksort. Second, it is not often that people will be implementing quicksort.
- rahulmutt 10y agoI agree that it's not a good implementation, as I said it's for illustrative purposes. You also don't implement the "Hello World!" program ever in real life, yet every programming language intro starts with that. Relative to that, a sorting algorithm is a lot more instructive. I think if I changed the name of 'quicksort' to 'sortUniqueList' that would clear things up.
- taeric 10y agoHmm... fair. I am criticizing something without a suggestion. I don't have one and I confess that worries me. In trying to teach my children, I have actually grown away from the "this is what the code looks like" to examples. And I commend the site for doing that. 2048 seems like an odd example, but conciseness is the goal, I'm guessing. Still a fun one. (Snake would be more fun for kids, I'm guessing. But that is just a guess.)
- rahulmutt 10y ago2048 was just convenient. It just so happens that there was an existing Haskell project that used the native GLTK library. I just swapped that out with JavaFX and it worked. If I were to write a book on Eta, I would certainly use a simpler game! I personally learned to code as a child by playing with examples and developing a game, so I can bet your kids are going to grasp programming fast. The human brain learns naturally from examples as opposed to theory.
- js8 10y agoIf I understand you correctly, you basically verified this for Haskell (which you call Eta), since there are no visible differences with Haskell yet. Why make another language anyway, if your experiment shows that Haskell is readable? You're saying that the problem with Haskell adoption are lack of tooling and documentation, which can surely be resolved without having to design another language. In fact, I don't think bad language design hindered adoption of any language ever (examples: COBOL, APL, MUMPS, BASIC, PHP, Javascript). I wish you wouldn't break compatibility with Haskell, ever. I think it would make both languages stronger (if they were just one), since everybody could just reuse code. I don't see a reason for having another language just to fix minor syntactic problems. Edit: I think what I am not clear about is where exactly do you intend to break the compatibility with Haskell and how do you think that action will help adoption of your language.
- hota_mazi 10y ago"Great in theory, terrible in practice" is a good summary of pure functional programming, in my experience :-)
- rahulmutt 10y agoI'd love to hear about your experience and ways I can build Eta to make that experience better. Feel free to shoot me an email.
- michaelmrose 10y agoI'm sorry this isn't at all easy to understand if you don't know the language. For example what is $ in this context how does <- work, how does the where clause work precisely and why is it required before the assignments? Is the colon required to separate arguments? I'm not expecting you to give me a tutorial here in the comments and I'm 100% sure I could read a tutorial and understand in a few minutes but it doesn't seem particularly obvious if you don't know haskell. Its easy to misread familiar as obvious.
- platz 10y agoso, because they used a toy (not a real) quicksort on the home page, you don't want to see the project succeed?
- omaranto 10y agoAlso both of the inequalities in the list comprehensions are strict, so it removes duplicates in addition to sorting.
- hyperpallium 10y agoPerhaps it's not surprising that quicksort is very clear in functional languages, since C. A. R. Hoare was inspired to invent it by learning functional programming. Perhaps it's not surprising that the common advice is to learn functional programming for the insights, since quicksort is not at all quick in its very clear functional programming form.