I'm surprised this is missing the canonical quicksort in one line of Haskell
http://augustss.blogspot.com/2007/08/quicksort-in-haskell-qu...
11–19 of 19 posts
I'm surprised this is missing the canonical quicksort in one line of Haskell
http://augustss.blogspot.com/2007/08/quicksort-in-haskell-qu...
Trying to look at this from the perspective of someone who doesn't know Haskell, most of these aren't impressive, but in fact advertisements against Haskell. First, consider that 6 of them are essentially applying a builtin function. That you can sum a list with the function sum [1..10] is not impressive, it at best speaks to what functions the language designers thought to include. Similarly, partition (>60) [49, 58…
I wanted to show a "Impress your friend with python" suite but would not be shy to use 3-4 lines and make it easy to read and finish the article with: "Don't impress your friend, code in a way that you'll keep them!" ;-)
I'm surprised this is missing the canonical quicksort in one line of Haskell
But the 'canonical quicksort' is not quicksort ;), just a slow look-alike: http://augustss.blogspot.com/2007/08/quicksort-in-haskell-qu...
Trying to look at this from the perspective of someone who doesn't know Haskell, most of these aren't impressive, but in fact advertisements against Haskell. First, consider that 6 of them are essentially applying a builtin function. That you can sum a list with the function sum [1..10] is not impressive, it at best speaks to what functions the language designers thought to include. Similarly, partition (>60) [49, 58…
It's not just using first-class functions here, it's partially applying a flipped curried operator. That's not exactly common.
An oldie, but a goodie.
I see them as an equivalent of giving STL-heavy examples when trying to impress someone with C++ - "Look! Sorting an array with one function call - std::sort(head, tail) !"
I'm surprised this is missing the canonical quicksort in one line of Haskell
Trying to look at this from the perspective of someone who doesn't know Haskell, most of these aren't impressive, but in fact advertisements against Haskell. First, consider that 6 of them are essentially applying a builtin function. That you can sum a list with the function sum [1..10] is not impressive, it at best speaks to what functions the language designers thought to include. Similarly, partition (>60) [49, 58…
> might be impressive to someone who has never seen first class functions (though they'd probably ascribe it to syntactic tricks) It's not just using first-class functions here, it's partially applying a flipped curried operator. That's not exactly common.
(defn flip-arguments
[func]
(fn [& args]
(apply func (reverse args))))
(prn (partition-by (partial (flip-arguments
I noticed Haskell does automatic currying. You can easily create that or basically any other language feature using Lisp macros: (defn currify
[f n]
(fn [arg]
(if (= n 1)
(f arg)
(currify (partial f arg) (dec n)))))
(defmacro currying-function
[arg-names & code-args]
`(currify (fn ~arg-names ~@code-args) ~(count arg-names)))
(def gt (currying-function [a b] (> a b)))
Once you experience the power of Lisp macros it is hard to go back to non-homoiconic languages such as Haskell that hide the underlying structure of the code.I am not impressed by the Haskell code shown here, flipping and currying are feature Lisps had back in the 1980s or earlier, before Haskell was born.
Actually, I find the Haskell code rather revolting. First of all because of the horrid camel-case names (isInfixOf, parseXMLDoc, curlGetString, etc) then there is the very confusing syntactic constructs, like $ and , and hard to interpret names like map, fmap, mapM_, foldl, and foldl1.
Earlier quoted context omitted.
But the 'canonical quicksort' is not quicksort ;), just a slow look-alike: http://augustss.blogspot.com/2007/08/quicksort-in-haskell-qu...
No, it's quicksort. It's just not the best implementation of quicksort.
A description is given of a new method of sorting in the random access store of a computer
The paper also emphasizes the use of in-place mutations in quicksort. The qsort one-liner uses lists, which are not random-access and cannot be modified in-place.