In this course, we will study functional programming, and will learn how to take advantage of the features of modern typed functional programming languages. We will study in depth the notions of algebraic data types, higher-order functions, polymorphism, and side-effects. The practice sessions will be done in Haskell, but concepts presented in the course can be applied in many other languages such as OCaml, SML or Python.
Prerequisites: CSE201 and CSE203
Fall 2024 Schedule:
Instructors:
Your grade is computed based on:
five formative assignments (20% = 5 x 4%)
a final exam (30%)
a final project (40%)
participation (10%)
where regularly asking questions during labs or lectures or on the
Moodle Q & A
forumSlack
space will earn you full credit for participation. Attendance at
labs is mandatory except for medical reasons or with prior permission.
Attendance at lectures is strongly encouraged.
You will receive full or almost-full credit on the formative assignments so long as you make a reasonable attempt at completing them. Collaboration is allowed and encouraged, although you should understand everything that you submit and acknowledge your collaborators. This extends to online forums and tools such as ChatGPT. Remember that the point of the formative assignments is to be formative, i.e., to help you to learn, and learning at times requires grappling with the material.
The main components for determining your course grade are a final exam and a final project. The final exam will be a two-hour exam with both theoretical questions and programming problems, held during the last lab (Lab 7). The final project will require you to write some more significant functional code in a small group of 1-3 people, on a topic that will be introduced later in the semester. The project will be due after the holiday break, and each group will give a brief presentation to be scheduled in November.
The Glasgow Haskell Compiler (GHC) is an open source compiler and interpreter for Haskell. It includes the following programs that may be run from the command line:
ghci
: the interpreter.
The main way of interacting with the interpreter is to enter Haskell
expressions at the >
prompt, which will then be
evaluated and printed. Here is an example:
> 2 + 2
4
> let x = 2 in x + x
4
There are many other more specialized commands; for example, two
important ones are :load
(or :l
) for loading a file, and :type
(or :t
) to find out the type of an expression.
ghc
: the compiler. You can use
this to produce stand-alone executables from Haskell source.
runghc
(or runhaskell
). This allows you
to run Haskell programs without having to compile them
first.
Documentation on all of these programs and more is available at the GHC User’s Guide.
GHC 9.6.2 is already installed on the lab machines. You can verify this by running
$ ghc --version
in a terminal. We will be using the interpreter ghci
more often than the compiler ghc
. You can run it as
follows:
$ ghci
GHCi, version 9.6.2: https://www.haskell.org/ghc/ :? for help
Prelude>
To install GHC for yourself (e.g., on your laptop), the easiest approach may be to use ghcup. In addition to installing GHC, ghcup will also install the Cabal library manager and build system, and optionally Stack, which is a newer tool for developing Haskell projects.
In any case, make sure that you install a stable release of GHC, version 9.6.2 or higher.
You will also need some editor to edit Haskell source files. VS Code is a popular choice, although personally I use Emacs.
Whereas labs are designed to provide more practical programming experience, lectures cover the theoretical foundations of functional programming. I will attempt to provide lecture notes reasonably in advance of (or eventually after) the lectures, with the understanding that they may not be an exact transcript of what happened during lecture, and that I reserve the right to modify them at any point to incorporate corrections/improvements/additions. I will also post a copy of any slides that I use, eventually incorporating bug fixes. Of course you are welcome to take your own notes during lectures!
Although there is no course textbook, the following books may be helpful to complement the lectures:
Programming in Haskell, 2nd edition by Graham Hutton.
Thinking Functionally with Haskell by Richard Bird.
Copies of both books are available on reserve at the Bibliothèque Centrale. (The book webpage for Programming in Haskell also provides links to slides and videos based on Hutton’s Functional Programming course at Nottingham University.)
There are also several good books on Haskell that are freely available online:
Learn you a Haskell for Great Good! A colorful introduction to the language.
Haskell WikiBook. Includes a Beginner’s Track as well as an Advanced Track with lots of more advanced material.
Real World Haskell. Includes extended examples of practical applications.
You may also find these links useful:
Finally, if you enjoy this course and want to go further, you may be interested in:
Samuel Mimram’s graduate course and associated book Program = Proof, which works all the way up to an introduction to homotopy type theory.
David Thrane Christiansen’s introduction to Functional Programming in Lean, which is a dependently typed functional programming language and proof assistant of increasing popularity in the mathematics community.
This year’s project is about writing a text adventure game on and around trees.