Any Haskell puzzlers?

I just watched Joshua Block’s talk Effective Java - Still Effective After All These Years. I’m not a Java developer1 but I still found the talk very interesting. Mr Block offers tips and tricks to deal effectively with a few aspects of Java, and I’m sure many a Java developer out there would find that part very interesting. For me however, the most interesting part was the appetizers and the dessert :-)

The appetizer and dessert consisted of three puzzlers. A puzzler is a piece of code that high-lights some peculiarity of the language or standard libraries. The puzzlers in this talk were are follows:

Simple question

What is printed by the following code, and why?


What is the result of the following code, and why?


This one consists of two classes, which are compiled together:

Now modify the latter like this:

Compile the second version of alone and then run PrintWords, what is the result and why?

Any puzzlers for Haskell?

Of course I couldn’t help but wonder what puzzlers there are for Haskell. Do note though that puzzlers aren’t just obfuscated code; they are readable code that you think does one thing but in reality it does something else. I’d really like to read any Haskell puzzlers you can come up with. Post them on your own blogs, or as comments to this post.

NB I should probably mention that I really don’t want answers to the puzzlers. I’ve watched Josh Bloch’s presentation, and I think anyone interested in finding out should watch it for themselves.

  1. If I ever find myself in a situation that calls for Java I’m very likely to spend some time looking at Scala :-)


Dan, a nice little example of the power of irrefutable (lazy) patterns.


@solrize, hardly the kind of code you’re likely to find in any real software project out there though, is it? :-)


Intrigued by the puzzles, I had to look briefly at the video. It is interesting that the conclusion after the first puzzle, @09:34 is that “Strange and terrible methods lurk in libraries”. Huge libraries are a main selling point of Java, especially vs. Haskell, but sometimes there’s something to be said for the DYI approach also - something that “clearly works, as opposed to merely works”.

Leave a comment