15-150: Principles of Functional Programming (Fall 2018)

The purpose of this course is to introduce functional programming. Saying that this is another "programming paradigm" is an understatement. Instead, think of functional programming as a different way to understand computation, one coming from a mathematical perspective. This has interesting implications. First of all, programs become more structured objects, which facilitates reasoning about their correctness. We will see how to apply the well-know principle of induction to do that. Learning how to implement programs with this particular mathematical structure will change the way we solve problems. We will learn how to decompose problems in smaller parts and use these parts to compose a solution. This approach results in natural and elegant solutions for many computer science problems.

Learning goals
Upon completion of this course, students will have acquired a mastery of basic functional programming techniques, including the design of programs using types, the development of programs using mathematical techniques for verification and analysis, the use of abstract types and modules to structure code, and the exploitation of parallelism in applications.
In particular, a student taking this course will learn to:

Moreover, you should be able to understand this (do not forget the tooltip).

You must have completed 21-127 (Concepts of Mathematics) and 15-112 (Fundamentals of Programming) to attend this course.

This is a 10 unit core course.

Place and time

Sundays and Tuesdays 15:00 to 16:20 CMB 2147 lectures
Thursdays 15:00 to 16:20 CMB 2035 labs


In the table below, labs are in purple, exams are in red and the next lecture/lab is yellow. Grey days are in the past or have no lectures.


Giselle Reis (Instructor)

Office: 1008
Office hours: by appointment
E-mail: giselle@cmu.edu

Sameer Ahmad (CA)

Office: ARC
Office hours:

  • Thursday: 16:30 - 19:30
  • Saturday: 12:00 - 15:00
E-mail: sjahmad@andrew.cmu.edu

Hanna Moazam (CA)

Office: ARC
Office hours:

  • Sunday: 9:30 - 12:00
  • Monday: 16:30 - 17:30
  • Tuesday: 13:00 - 15:00 and 16:30 - 17:30
  • Thursday: 9:30 - 11:00
E-mail: hmoazam@andrew.cmu.edu

Maimoon Siddiqui (CA)

Office: ARC
Office hours:

  • Tuesday: 8:00 - 9:30
  • Friday: 13:00 - 15:00
  • Saturday: 8:00 - 12:30
E-mail: maimoons@andrew.cmu.edu



Homework: 45%

Midterm: 15%
Project: 15% Participation: 5% Final exam: 20%

Getting the Assignments

The writeup and starter files for each assignment can be found on Autolab. Log in with your andrewID, select the course and then the assignment. You can see the pdf with the instructions by clicking on "View writeup". The starter code and template for typing your answers are in a tgz file which can be downloaded by clicking on "Download handout". Uncompressing this file will create the directory <asgn>-handout with the starter code and a LaTeX template in the latex subdirectory. If you need to download these files again, be careful not to overwrite your work!

Submitting the Assignments

The handout contains a Makefile to help you organize your files for submission. Typing make in the handout directory will create the file <asgn>-handin.tgz and latex/<asgn>.pdf. If you need help using this Makefile, ask the course staff. The tgz file must contain the solutions for the coding part. The pdf must contain the solutions for the written part. It is your responsibility to ensure that the generated files contain the correct material.

The tgz file needs to be submitted to Autolab. It will immediately run a series of tests on your code and give you a score with some feedback. Make sure to check it! If your code does not pass all tests, you can submit it again until the deadline. You are limited to a total of 10 submissions for each assignment.

The pdf with your written solutions must be submitted to Gradescope. No other file formats will be accepted.


Setting up your programming environment:
The functional programming language we will use for this course is in the ML (for Meta-Language) family and it is called SML (Standard ML). There are different compilers (i.e. implementations) for SML, but your code will be tested with Standard ML of New Jersey (or SML/NJ) version 110.83.

You can use SML/NJ in one of two ways:

If you are using emacs, there is an sml-mode where you can edit your file and run it interactively. To install, see http://elpa.gnu.org/packages/sml-mode.html. Here are a few useful commands (C-x means hit Ctrl+x):
  • C-x C-f : open a file (if this is a .sml file and sml-mode is installed, you should see (SML) on the status bar)
  • C-space : select a text region
  • C-x C-c : exit emacs
Additionally, the following commands can be used to interact with the repl
  • C-c C-l : load the file in an sml repl (first time asks the name of the sml command used)
  • C-x ` : find the next error (` is the grave accent key. On my keyboard layout, I need to press this key + space to actually type it.)
  • C-c C-b : send selected region to sml repl

As far as I know, there is no sml integration with vim, but this is a good text editor which I use on a daily basis. Vim has three main modes: command, insert or visual. By default, it starts on command mode. You can enter insert mode (for editing) by typing i and visual mode (for selecting) by typing v. Hitting ESC will return to command mode. Here are a few useful commands:
  • i : enter insert mode
  • ESC : return to command mode
  • :w : write file (aka save)
  • :q : quit vim

Download and install Sublime Text from http://www.sublimetext.com (preferably version 2).
Similar to emacs, Sublime has also integration with SML, which provides syntax highlighting, a repl and code templates. The SML package is installed using Package Control.
To install Package Control, see the instructions at https://packagecontrol.io/installation. To install SML Package:
  1. Press Control/Command+Shift+p in Sublime
  2. Type "Install Package"
  3. Then search for "SML (Standard ML)"
You can either use Sublime as a text editor to work on your machine locally, or you can setup your Andrew File SFTP server and modify your files on the server on Sublime. To set up SFTP server on your Sublime:

Step1: Install the SFTP plugin (which allows you to edit files on AFS):
  1. Press Control/Command+Shift+p in Sublime
  2. Type "Install Package"
  3. Then search for "SFTP"
Step2: Setting up server:
  1. Go to File → SFTP/FTP → Setup Server
  2. Delete the template and paste (substituting your andrew ID where appropriate):
                  "type": "sftp",
                  "sync_down_on_open": true,
                  "sync_same_age": true,
                  "host": "linux.andrew.cmu.edu",
                  "user": "YOUR_ANDREW_ID",
                  "remote_path": "/afs/andrew.cmu.edu/usr/YOUR_ANDREW_ID/private/15150",
                  "connect_timeout": 30,
  3. Save this file under the name AFS. This is the name you will use to refer to this connection.
Once eveything is set up, you can open a file on AFS via File → SFTP/FTP → Browse Server. Saving the file will cause it to be uploaded to AFS, where you can compile and run it.

As for the rest, you can find a million resources online, so just google it 😉


Your written assignments will look much better if you develop them in LaTeX. Typically you will edit a .tex file which is compiled into a pdf. This file uses specific tags and commands for typesetting. If you only know Word (or similar) for creating documents, LaTeX takes a little getting used to, but it is worth it. After you become familiar with the syntax, some advantages are:

There are various tools for editing and compiling LaTeX. If you do not want to install anything locally, you can use one of the web-based ones, such as ShareLatex. If you use one of those tools, upload all files in the latex directory of the handout.


You are expected to comply with the university policy on academic integrity (see also The Word and Understanding Academic Integrity).

Collaboration is regulated by the whiteboard policy: you can bounce ideas about a homework with other students, but when it comes to typing it down for submission, you are on your own. You are not allowed to use notes, files, pictures, etc, from any previous discussion nor previous versions of this course.

And remember not to ignore your inner voice when it says “That’s probably not the best decision...”.

An Invitation to Students with Learning Disabilities:

Carnegie Mellon University is committed to providing reasonable accommodations for all persons with disabilities. To access accommodation services you are expected to initiate the request and submit a Voluntary Disclosure of Disability Form to the office of Health & Wellness or CaPS-Q. In order to receive services/accommodations, verification of a disability is required as recommended in writing by a doctor, licensed psychologist or psycho-educational specialist. The office of Health & Wellness, CaPS-Q and Office of Disability Resources in Pittsburgh will review the information you provide. All information will be considered confidential and only released to appropriate persons on a need to know basis.

Once the accommodations have been approved, you will be issued a Summary of Accommodations Memorandum documenting the disability and describing the accommodation. You are responsible for providing the Memorandum to your professors at the beginning of each semester.

Take Care of Yourself:

Do your best to maintain a healthy lifestyle this semester by eating well, exercising, getting enough sleep and taking some time to relax. This will help you achieve your goals and cope with stress.

All of us benefit from support during times of struggle. You are not alone. There are many helpful resources available on campus and an important part of the college experience is learning how to ask for help. Asking for support sooner rather than later is often helpful.

If you or anyone you know experiences any academic stress, difficult life events, or feelings like anxiety or depression, we strongly encourage you to seek support. Counseling and Psychological Services (CaPS-Q) is here to help: call 4454 8525 or make an appointment to see the counselor by emailing student-counselling@qatar.cmu.edu. Consider reaching out to a friend, faculty or family member you trust for help.

If you or someone you know is feeling suicidal or in danger of self-harm, call someone immediately, day or night at 5554 7913. If the situation is life threatening, call 999.