Learning Haskell (was: Haskell-Cafe digest, Vol 1 #730 - 5 msgs)

Graham Klyne GK@ninebynine.org
Mon, 23 Jun 2003 15:26:14 +0100

At 08:13 23/06/03 -0500, Mark Espinoza wrote:
>  I am thinking about learning Haskell and rewriting my shopping cart,
>which I have written very poorly in perl, in Haskell. I already have
>GHC installed on my web server and personal computer. Is this a good
>or bad idea? Does Haskell have anything like perl's CGI module? What
>are the advantages of Haskell over Lisp? (I already have a couple of
>Lisp books because I was looking into lisp when I discovered Haskell.)

I'll respond from the perspective of a relatively recent comer to 
Haskell.  The big win, to my mind, of using Haskell over other "rapid" 
programming languages/environments is its type safety, which I would think 
is a real advantage for an e-commerce application, where (I presume) 
security is a concern, and the expressive power of higher order functions.

I have found the quality of language implementations and basic libraries to 
be excellent.  I use Hugs and GHC.  A possible drawback is that the support 
for web applications may be immature compared with, say, Perl.  (Others may 
offer different opinions, but I note that it's only very recently that 
there has been an XML parser for Haskell supporting XML namespaces.)

In order to develop a serious web application, you'll need to come to terms 
with Haskell's way of doing I/O.  It's fully capable, and really quite 
powerful, but it does take some time to get one's head around when coming 
from a more conventional programming background.
>I much prefer to learn from books rather than electronic media, so
>what books could I use. Besides basic Haskell information, I would be
>interested in any networking or CGI specific Haskell books.

I don't know of any networking-specific Haskell books.  Once you have a 
reasonable command of the basic language, Haskell support libraries tend to 
be very easy to understand use, in my experience.

Materials I have found useful include:

The Craft of Functional Programming, Simon Thompson -- it starts a little 
slowly for my taste, but the later sections are packed with useful 
information relevant to Haskell programming technique.  I found a few gaps 
in coverage of the Haskell language, so it's not always useful as a reference.

Haskell 98 Language and Libraries, The Revised Report, Simon Peyton-Jones 
-- this is essentially the same as the Haskell reference material available 
at Haskell.org, but I really find it to be more accessible in book form.

Pure Functional Data Structures, Chris Okasaki -- I found this was useful 
not so much for the purpose suggested by its title, but because it gives 
insights into programming style/techniques that work with a functional 
programming language.  Unfortunately, the book's "first language" is 
Standard ML, and you have to look to an appendix for Haskell code 
examples.  I'd suggest looking at this after you have a feel for basic 
Haskell language structures, for some guidance on how to use them.


Those happen to be the Haskell books I have, and they've all been useful to 
me.  There  are others which may be better.

There is also a wealth of material available on the web in the form of 
conference papers, etc.  Some of this is pretty academic computer science, 
but some that I have found useful at a practical level are (sorry no URIs, 
but Google should find most of these, especially if combined with the 
keyword "Haskell"):

GHC manual and libraries;  chapter 7 discusses some important language 
extensions that are not yet part of the standard.  In particular, section 
7.8 introduces Multiparameter type classes (see also Type classes, 
exploring the design space, which is cited there).

State in Haskell, John Launchbury and Simon Peyton-Jones:  I found this to 
be one of the more illuminating introductions to Monads (which are central 
to Haskell I/O).

Why Functional Programming Matters, John Hughes:  this gives some good 
indicators as to whjy you might use a language like Haskell, which in turn 
suggests styles of programming that best leverage Haskell's strengths.

Scrap Your Boilerplate, Ralf Lammel and Simon Peyton-Jones:  for me, even 
though it describes features not yet present in standard Haskell, this 
serves as a continuation of the John Hughes paper, suggesting the kind of 
coding advantages one may seek to gain from a functional language like 
Haskell.  (A message I read into this is that higher order functions 
provide a way to achieve the advantages of something like C++ Standard 
Template Library, without compromising type safety in the ways that STL can 
entail, and some hints about how to achieve that.)


Coming from many years of using conventional programming languages (Pascal, 
C, C++, Java, Python, ... ) I've found the Haskell learning curve to be 
quite steep (but then again, I found Perl to be quite difficult, with it's 
irregular structure and its many ways to do any given thing).  The type 
system is both very powerful and sometimes very subtle, but once you start 
coming to terms with it, it is really helpful in picking up logical flaws 
in one's code ... at compile time.  Learning to use higher order functions 
effectively also takes some mental recalibration.

For all the new ideas to be learned, I am now finding that Haskell amply 
repays the effort in elegant, easily constructed and reliable code.


PS: I maintain a few Haskell-related links at:

Graham Klyne
PGP: 0FAA 69FF C083 000B A2E9  A131 01B9 1C7A DBCA CB5E