learning haskell

2009-07-28

A sudden rush of blood to the head
—I attempt to learn Haskell.

why?

It seemed like a good idea at the time? Well, perhaps a wee bit more than that.

Since finishing the webapps the realization has dawned that I’m never going to make a living at developing web applications, or, in fact, in anything computing—and that I really don’t want to. What I’m really interested in is the theoretical side of computing and the mathematical under-pinnings of same. [Although we'll see if I keep this interest up when the maths get’s difficult!]

So, given this interest and that a great chunk of my degree will involve Java and objects, it seemed like a good idea to learn a functional language. And it also seemed that as I’m not doing much [course-wise] this summer that now would be a good time to start.

why haskell?

I looked at Haskell and Scheme/Lisp [these seemed to have the best online resources available and Erlang looked a wee bit too hard]. For me Haskell came out way ahead, if for somewhat shallow/subjective reasons:

  • Haskell seems ‘cleaner’—no loops, strong typing, explicit signatures, immutable variables…
  • Haskell is, to my mind[!], was more intimately connected to the lambda calculus [one of the reasons for my interest in functional programming].
  • I don’t like the way Scheme/Lisp code looks.

In the end the tipping point was finding Real World Haskell, just a brilliant resource—lucid, informative and thought-provoking. A free online book that I’m going to buy because the authors deserve the money.

how am i getting on?

Bearing in mind that I’ve only been learning for four[–ish] days and that I’ve only spent a couple of hours at the command line, pretty well. I’m enamoured.

did m263 help?

Yes. In fact without it I would have been in some trouble, true I might have managed, but nine months learning the building blocks haven’t been wasted.

A solid grounding in the workings of recursion is an essential, without it you’ll struggle with Haskell, which I expected. What I hadn’t expected was that blocks one and two of M263 [datatypes, functions, specification, signatures, etc…], and that unit 15 [efficiency] would prove so useful.

  • Functions are very important in Haskell, I don’t quite grok them yet. I have problems with partial evaluation and currying but I feel that I’m on the road—the cat of understanding is scratching at my skull.
  • A good understanding of Abstract Data Types, and how to handle them, just makes learning any language so much easier—knowing that a Haskell string is just a list of char and not a distinct type…well, helps.
  • In Haskell [and I’m sure other languages] you need to understand exactly what ADT you are dealing with otherwise you'll write inefficient code—Haskell lists aren’t arrays so length may not be a trivial thing to compute.

my “hello world”

As I said, I’m just starting, so here’s my [first] function:

-- length of list myLen :: [a] -> Integer myLen [] = 0 myLen (x:xs) = 1 + myLen xs

And Called

gchi> :load c:\ghc\hello.hs -- compiler stuff gchi> myLen [] 0 gchi> myLen ['a', 'b', 'x'] 3

Still struggling with the Fibonacci I’m afraid!