ThisBindle::Code::Haskell

I'm finally making an effort to actually learn Haskell. Brief dabbling, general buzz, and personal recommendations all point to it being awesome and flat out making you a better programmer.
I don't think I'll be following John's method of learning Haskell by writing a compiler, but I am following this tutorial on writing a Scheme interpreter per his recommendation.

Made this snowflake fractal as part of working through (Amazon.com) The Haskell School of Expression: Learning Functional Programming through Multimedia

Haskell: w(hy)tf?

Language wars are silly, and I don't pretend to know enough about Haskell to say that one _should_ develop in it. However, learning a language that admits (or beter yet, requires) concepts that are new to you is unlikely to make you a worse programmer/thinker/person. For a nice treatment of this, see The Perils of JavaSchools.

So, what are these motivating concepts for Haskell? As stated up top, I'm busying myself finding out.
The fact that it is purely functional and lazy is really exciting enough for now, despite not getting past the first 3 lines of the wikipedia page. I'm also kind of psyched to dip into Category theory through monads, which will allegedly break my brain.

What does Haskell look like?

Compellingly like math, (if math compells you). Check out this 6-line quicksort (line numbers added for clarity):

1) quicksort :: (Ord a) => [a] -> [a]
2) quicksort [] = []
3) quicksort (x:xs) =
4)   quicksort [y | y <- xs, y<x ]
5)   ++ [x]
6)   ++ quicksort [y | y <- xs, y>=x]

This well-known algorithm showcases the power of list comprehension, which reads very much like set notation. Line-by-line, this code can be read as follows:

Note that, while brief, this is a very readable way to do quicksort in Haskell. Line 1 is optional, and lines 3-6 are separated for readability.

Lazy Functions

Functions in Haskell are lazy. That is, they evaluate only as much as they need to. This allows for, amongst other things, infinite data structures. Check out this list of all positive integer factorials:

factorials :: [Integer]
factorials = 1 : zipWith (*) [2..] factorials

The top line just states that 'factorials' is a function returning a list of integers. 'zipWith' takes a binary function and two lists, returning a list formed by applying the function to the elements of the two lists. Check out the code for zipWith in the Haskell Prelude.

Thus the above code defines 'factorials' recursively as '1' prepended (with the operator ':') onto the list formed by applying multiplication in turn to the elements of the integers greater than 2, and the list 'factorials' itself.
That is we prepend 1 onto the list

[2 * (factorials[1] = 1), 3 * (factorials[2] which is the previous element, 2), ...]

Thanks to lazy evaluation, this can then be used like ' take 200 factorials' without concern for actually generating any factorials other than the first 200.

Haskell Links

The Haskell homepage
A Tour of the Haskell Prelude
A Gentle Introduction to Haskell
John's Haskell reference links.
Learning Haskell
Caltech's CS11 Haskell Track
(Amazon.com) The Haskell School of Expression: Learning Functional Programming through Multimedia