Introduction to Functional Programming

𝕊𝕋𝕃ℂ++ and Tooling


Learning Objectives

  • You know how to run 𝕊𝕋𝕃++ code online or on your machine.

Throughout this course, we will use a functional programming language called 𝕊𝕋𝕃++ which the course authors designed during early 2025. The language is functional and minimalistic, and even supports polymorphism, which is a core programming language feature we will learn about during the course.

𝕊𝕋𝕃++ is based on lambda calculus1, but it also comes with primitive types like integers, booleans and characters. Although its foundations are much simpler, the syntax and general feel of 𝕊𝕋𝕃++ resembles some modern functional programming languages, like Haskell.

No files opened Select a file to edit
Loading Exercise...

Here’s a listing of supported features.

FeatureExamplesLevel
Value literals1, true, 'a'Term
Term variablesx, foo, int.to_string, _ (initial letter lowercase)Term
Type variablesX, Bar (initial letter uppercase)Type
TypesInt, Bool, Char, String (= [Char]), Int -> Bool, (Int, Bool), Int + Bool, forall X, XType
Functionsfun x : Int, x, fun X : Type, [:X]Term
Lists[1, 2, 3:Int], [:Bool]Term
Pairs(1, true)Term
Sumsinl 1 Bool, inr true Int have type Int + BoolTerm
Primitive operations+, <=, ==, if b then x else y, f . gTerm
Definitionsf : Int -> String
f = fun n : Int, int.to_string n <> "!"
Declaration
Type aliasesNat : Type
Nat = [Unit]
Declaration
Recursionf : Int -> String
f = f
Declaration
Syntax extensionsinfixl x >=< y = x * y - y * xDeclaration
IOio.readline : IO StringTerm
Overview of supported features in 𝕊𝕋𝕃ℂ++

𝕊𝕋𝕃++ supports importing declarations from other modules using the import keyword, however the OpenCS platform does not support this, so imports are never used in the examples. Also there are no namespaces or visibility rules, so imports are quite limited right now.

For more complete examples with also list and sum operations, check the playground.

Loading Exercise...

Online Playground

An online playground for 𝕊𝕋𝕃++ is available here. The playground is not part of the course platform, but it remembers code you have written there locally in your browser.

You can find the source code for 𝕊𝕋𝕃++ on GitHub: Aalto-OpenCS

𝕊𝕋𝕃++ is written in Rust and packaged using Nix and Docker. You can start the REPL with docker using the following command:

docker run --rm ghcr.io/aalto-opencs/stlcpp

Tip: Type :help in the REPL to see available commands.

However, if you want to start the REPL from a file, you need to mount it in Docker, or alternatively build the project from source. To mount the current directory in Docker and start the REPL from a file, use:

docker run --workdir /mnt -v $PWD:/mnt --rm ghcr.io/aalto-opencs/stlcpp example.stlc
example.stlc λ

Editor Integration

For VS Code/Codium, you can install the 𝕊𝕋𝕃++ extension manually by downloading the .vsix file from the latest release. To install it, open the extensions panel, click the ... (more actions) button, and select Install from VSIX to select the downloaded extension.

There is also experimental Zed editor syntax highlighting, which you can install using the Install Dev Extension option described here.

Footnotes

Footnotes

  1. STLC means simply typed lambda calculus. However, 𝕊𝕋𝕃++ is not actually simply typed, but second-order instead. Second-order lambda calculus is also called System F. The name is left over from earlier times when 𝕊𝕋𝕃++ was simply typed.