Thursday, March 27, 2008

Learning Haskell

Uh, no taocp today because I got stuck in Haskell.Org's haskell-98 tutorial. Functional programming has been unknown to me. We don't have a Lisp-derived language as the first language in the univ. (it's the evil Java there!) so not until ~one year ago did I start to satisfy my curiosity and downloaded the legendary Lisp lecture videos from MIT servers. I wrote some basic algorithms in Common Lisp and liked it but I never had the motivation to watch the whole lecture series nor write anything real in Common Lisp.

Having recently become a regular reddit/programming reader I've seen a lot of Haskell related articles in the hot list. At the univ. I've seen a bit of Haskell fanaticism, and functional progr. fanaticism in general, going on, too. Because of that I decided to find out more about this language.

Right now, having read one-thirds of the tutorial, I can already say that I'm happy that I opened it. Never have I seen such a beautiful definition of quicksort before:

qsort [] = []
qsort (x:xs) = qsort [ y <- xs | y < x ]
++ x ++
qsort [ y <- xs | y >= x ]

Yes, the pivot could be chosen more carefully as this can easily fall to O(n^2), but ignoring that, this is a marvelously lucid piece of code.

No comments: