This course will provide an introduction to software development in the functional paradigm, with a focus on pure, statically-typed functional programming. The functional paradigm isn't a language or technology--it's an entire school of thought on what a computer program is and how to write one. It has a long history, based on a model of computation developed by the mathematician Alonzo Church in the 30s. The functional paradigm contrasts with the imperative paradigm, which most of today's existing software is written in. But although the functional paradigm has yet to go fully mainstream, the imperative world has been taking most of its bleeding-edge ideas about software design from the functional world, particularly in recent years. And to all appearances, that trend is on the rise, with expansive new purely functional software and tooling currently under development at companies like Facebook, Google, Microsoft, GitHub, and countless others. In addition, the library ecosystem for languages such as Haskell and OCaml has become sufficiently rich and extensive that an increasing proportion of today's successful software companies (including Jane Street Capital and Input-Output) have been able to develop their entire code base purely functionally.
There are a lot of ways to characterize the difference between programming in the functional style and programming in the imperative style. But just to whet your appetite, the language we will be working with has the following distinctive features:
+ every data structure is immutable
+ there is no shared state between functions
+ every expression must be well-typed at compile time
+ types can be inferred, and therefore need not be declared
+ data modeling is done using algebraic data types
+ functions can be made general-purpose with polymorphic types
+ interfaces are built using ad-hoc polymorphism, a.k.a. 'type classes'
The language of this course is Haskell. Haskell is arguably the main agenda-setter for the functional paradigm, and it is also somewhat challenging to learn outside of a class. At least in the opinion of this instructor, knowing your way around Haskell puts you in an excellent position to get going with other functional languages. That said, although we will spend a lot of time becoming intimately acquainted with Haskell, the main goal of this class is to focus on big-picture concepts that can be readily ported to other languages and technologies--in some cases including languages with limited support for the functional style. The functional style offers a wide array of data structures, patterns, and techniques that are nearly indispensable for writing clean, modular, maintainable, bug-free code that runs blazingly fast. These are all methods that any software developer can benefit from having in their personal toolkit.
The week-by-week breakdown of topics will be as follows:
Week 1: Haskell basics, linked lists, recursion
Week 2: point-free, lazy evaluation, algebraic datatypes
Week 3: type classes, basic IO, Maybe and Either
Week 4: functors, intro to applicatives and monads
Week 5: more monads, a little more IO
Week 6: midterm exam, the State monad
Week 7: intro to applicative parsing
Week 8: monad transformers
Week 9: lazy evaluation, conclusion, final project
Work for the course consists of short weekly readings, weekly code exercises, a midterm exam, and a final project. The weekly exercises are intended to be challenging but hopefully also fun. They will not presuppose any prior familiarity with functional programming. The bulk of the final project is written piecemeal every week as part of the homework, with the final two weeks set aside for finalizing it.
The main text for this class is the homework assignments, which are intended to be read week by week, like a textbook. However, we will also be reading the first half of Finding Success (and Failure) in Haskell, by Julie Moronuki and Chris Martin, which can be purchased here:
Moronuki and Martin's book is simply incredible, and highly recommended for anyone who would like to get started with Haskell.
We won't be using any general textbook in this class, but if you are looking for a general-purpose Haskell book to use for reference, Graham Hutton's Programming in Haskell (second edition) is excellent: