So You've Always Wanted to Learn Haskell?
Instructors: Jean Q. Yang and Joe P. Near
{jeanyang, jnear}@csail.mit.edu
Lecture 1 slides
Haskell is a statically-typed, purely functional programming language similar to ML (think Scheme with strong types and type inference--and without the parentheses). If you've always wanted to learn Haskell but didn't know how to start or haven't gotten around to it, this is the class to overcome the activation barrier. We will describe how Haskell works, show you how to compile and run your first programs, and give you an idea of programs Haskell is good for writing.
Your Haskell education should proceed as follows:
- Haskell basics. At the core, Haskell is a functional language with a strong, static type system. If you are familiar with functional programming, the only thing to get used to is the type system (which supports bounded parametric polymorphism) and the type inference engine, which can infer polymorphic types.
- Monads. In a pure functional language (one without any effects), a good design pattern for storing state is by carrying it around as an extra argument representing the world. Monads in Haskell are just a language construct supporting the manipulation of this world. Haskell supports doing all kinds of effectful things this way, including I/O.
- Type classes. Most language support overloading in an ad hoc way.
Haskell supports overloading with type classes, which define classes of types
that support a given set of operations. For instance, the
Show
class comprises types a
that define the show : a ->
string
function for serializing a value of type a
.
- Advanced topics. This is beyond the scope of the class, but there are all kinds of fancy things in Haskell having to do with types (phantom types, arrows) and pure functional programming (functional reactional programming, etc.) you can pursue.
Prerequisites
We expect people to be familiar with functional programming idioms (higher-order functions and partial application, map/reduce) and have experience programming in languages with static type systems (C/Java is fine).
Administrivia
The course will take place 3-5PM January 25-26, 2010 (Monday and Tuesday), 34-301. There will be no homework, but we recommend doing some preparation before classes to get the most out of lecture.
Course Outline:
Day 1: Getting started with Haskell. Jean will talk about the logistics of using Haskell (GHC compiler/GHC interactive shell), the principles of Haskell (static typing, algebraic data types, living in a purely functional world), and work up to explaining monads as a built-in language construct for threading state through a functional computation. Recommended preparation:
- Install the Haskell compiler GHC.
- Get
hello world
program running. Play around with some things if you so desire.
Day 2: Uses for Haskell. Joe will go through some programs written in Haskell to highlight 1) how Haskell looks in the wild and 2) the strengths of Haskell as a programming tool. Recommended preparation:
- Read and run the example files from Day 1.
- Load things into GHCi to look at the types.
Compiling and running Haskell
The typical use of Haskell involves compiling it and running the binaries. We recommend using the Glasgow Haskell Compiler (GHC). There is also an interactive shell GHCi that is useful for loading programs to check the types of things, etc.
Resources
- Write Yourself a Scheme in 48 Hours - a fast-paced introduction to Haskell: takes you from compiling your first program to having a Scheme interpreter that uses type classes and monads. This is as on speed as the gentle introduction is gentle.
- A Gentle Introduction to Haskell - an introduction to the Haskell languages: types, functions, standard type classes, monads, etc. Some have complained that this is too gentle.
- Hacking in Haskell - notes from Greg Price's SIPB course on Haskell from IAP 2009.
Why Haskell?
- Programming with Haskell types and language constructs teaches good discipline and makes you a better programmer across languages.
- It's elegant as hell.
- People think you are cool if you are a good Haskell hacker.
- It's the ultimate language for writing things like compilers (which involve transformations over well-defined data structures and storing limited state).