14 Aug 2007
n00b Thoughts on Haskell
I toyed with the idea of learning a functional programming language before. It’s good to see that toying often eventually leads to doing, as has been the case with Swedish. Some things that eventually prompted me to pursue FP more were an excellent article on the subject and personal experience with tedious maintenance of state in an ugly ‘monster class’ Python program I wrote. I thought that perhaps obsession with remaining functional and encapsulating state as much as possible—via monads, the mysterious components with which Haskell compilers reproduce—is perhaps a good idea. I still love object-oriented programming, especially in Python, because it is so easy, but FP makes anything imperative look like troglodyte crap now.
I have done some exercises and read parts of Yet Another Haskell Tutorial, among a few others. At this point, I have only recently learned a new distinction between ‘classes’ (like ‘interfaces’ in Java) and ‘types’ (more or less like ‘classes’ in other languages), and am barely qualified to comment on the matter, but that never stopped me before. Haskell is interesting in that, without monads, no program written in Haskell would ever ‘run’. Pure Haskell, like a system of equations, cannot ‘run’. It simply is. That sounds like ‘crystallogy weenie and pipe-stress freak’ substance until you consider that functional programming languages such as Haskell are inherently thread-safe and allow foolproof test units. Overall, it seems to be a very rich, powerful and concise language. The well-known quicksort implementation is a good example:
quicksort :: Ord a => [a] -> [a] quicksort  =  quicksort (x:xs) = quicksort [y | y <- xs, y<x] ++ [x] ++ quicksort [y | y <- xs, y>=x]
Five lines, including (an automatically deducible) declaration. It could probably fit into three. Haskell pwns n00bs.
I remember that object-oriented programming used to be considered an academic toy, used only by ivory-tower chair-polishers who drink liberal tea and eat quiche. Since then, OO has not only come into mainstream acceptance, it has also become a meaningless buzzword fit for the meager intellects of PHBs. I wonder whether Haskell and other FP systems will meet the same fate one day. In any case, I will remain faithful to Haskell, so no one can claim that I jumped on the bandwagon and avoid the turgidity usually associated with bandwagons (e.g., XML).
Well, second post in and I’m quite ready for Hank Dagny to step in and decry the liberal decadence of ‘lazy evaluation’.