Course Overview

Q: What will we study in this course?

There will be two primary themes:

  1. Implementing and analyzing efficient data structures, particularly in the context of functional programming languages.

  2. Functional reactive programming (FRP) for interactive programs.

Why? Well, because all of you have seen at least one functional programming language before (Racket in 151 or Haskell in 161, and perhaps Standard ML in 221 or 226x), there's an implicit "Advanced" or "Topics in" that prefixes the "Functional Programming" name of this course. So, we need to choose some topics to study.

There's certainly plenty of interesting and important topics related to data structures, some of which you may have seen in other courses. But probably few of you have seen all of the data structures and analysis techniques we will cover, and fewer still will have spent much time with them in the context of a purely functional language. That's one good topic.

Functional reactivity is a neat idea for building interactive programs. It's not really mainstream yet, so probably few of you have spent much time with it before. That makes for another good topic.

Q: What language will we use?

The vehicle we will use for programming is Elm, an exciting, new-kid-on-the-block language that features FRP at its core and that compiles to JavaScript for browser integration. The core of Elm, on top of which FRP primitives are built, is a small dialect of ML.

Machine Learning... huh?

No, not that ML. In our world, ML refers to a family of functional programming languages, developed since the 1970s, which has served as seminal work for decades of programming language design and engineering work.

I like to think of ML as kind of sitting halfway between Racket and Haskell for several reasons.

Evaluation Strategy

Like Racket and pretty much every language you may know besides Haskell, Elm is eager — expressions will be evaluated even when their resulting values are not immediately, or ever, needed elsewhere in the program.

Interestingly, however, we will see that lazy evaluation is actually crucial to building efficient data structures in purely functional languages (i.e. without mutable variables).

To bridge this gap, Elm (and most other ML dialects) do provide mechanisms for lazy evaluation on top of the eager semantics.


Unlike Racket but like Haskell, ML has a static type system that rejects programs that might possibly (but not necessarily) fail with certain kinds of run-time errors.

ML type systems feature a bunch of really neat and powerful features — such as parametric polymorphism and automatic type inference — but generally do not employ mechanisms like Haskell's type classes.

Note: there is a statically typed dialect of Racket called Typed Racket. In fact, designing typed dialects of "dynamic" languages like Racket, JavaScript, Python, etc. is an active area of programming languages research.

Side Effects

Even when functional programming languages do offer imperative (or impure) features such as mutable variables, their use is discouraged and typically used in small, local ways.

Although both ML and Haskell languages do have features that produce side effects, their type systems track such features in very different ways. Such effects typically "go outside" an ML type system, whereas in Haskell effects are recorded in types. Functions of type Int -> String in ML may possibly perform I/O with the user, but in Haskell they cannot. Instead, such functions would have type IO (Int -> String) in Haskell.

Although Elm does not offer mutable variables, we will see other mechanisms that it provides which break out of the purely functional paradigm.

What makes Elm a "small" dialect?

Practical languages that build on an ML core typically have many additional features — such as objects, modules, threads, exceptions, laziness, and many forms of syntactic sugar — that help with real-world programming. Popular full-fledged ML dialects include Standard ML, OCaml, and F#. In comparison to these languages, Elm is, by design, much smaller but provides FRP features at its core.

Q: What else should I know?

This course will feature usual things like homeworks, exams, grades, TAs, etc. See the Course Info page for details.

If you like programming and math (in other words, if you like computer science), I think you will like this course.

If you like only courses that are super-polished, however, then perhaps this course is not for you. I will occasionally choose to cover topics that I will be grokking for the first time. (I like learning, too!) In addition, although the Elm language, libraries, and tools are really coming along nicely, it is still a small language with a small (but helpful!) community. As a result of these factors, there may be times during the course when you will have to get your hands a bit dirty. That said, I think we'll have some fun.