Live data from Hacker News

Haskell One Liners to Impress Your Friends

blog.fogus.me

11–19 of 19 posts

Re: Haskell One Liners to Impress Your Friends

#12

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…

This "10 one liners.." is the third or fourth one this week; so I think it's just a way to say "Heh, your favorite language can do that? Mine too, here's how".

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!" ;-)

Re: Haskell One Liners to Impress Your Friends

#13
post #9

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...

No, it's quicksort. It's just not the best implementation of quicksort.

Re: Haskell One Liners to Impress Your Friends

#14

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.

Re: Haskell One Liners to Impress Your Friends

#16
Without knowing what's included in the core of the language and what comes as constructs on top of it, it is hard to get impressed with these examples.

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) !"

Re: Haskell One Liners to Impress Your Friends

#17
post #9

I'm surprised this is missing the canonical quicksort in one line of Haskell

It's because this post is part of a meme: someone wrote a post with precisely this list of 10 one liners in some language (Scala, I think) and then several others have written translations to other languages.

Re: Haskell One Liners to Impress Your Friends

#18

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.

Flipped curried operator? You mean like this:

  (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.

Re: Haskell One Liners to Impress Your Friends

#19

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.

No, it's not. First line of Hoare's 1962 paper describing 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.

Post reply on HN