Building a Typechecker from scratch

2h 16m 15s
English
Paid

Course description

Untyped programs are often prone to errors, runtime exceptions, and can make debugging much harder. That’s why many production languages implement a static typechecker — an extra module, which is aimed to increase programs safety and make development simpler.

Type checking or type inference? What is Type theory and Type judgements? Is my language weakly or strongly typed? And how am I actually going to implement a typechecker?

There are so many questions when it comes to implementing this module. If you’ve been asking those questions in implementing your programming language, or just want to understand how typeckechers work under the hood, on a hands-on practical implementation, this course is for you.

Often related books on Type theory and type judgements go to theoretical aspects viewing types as mathematical sets, not explaining how actually to build a practical typechecker. I believe we should be able to build and understand a typechecker for a full programming language, end-to-end, in 2-4 hours — with a content going straight to the point, showed in live coding sessions as pair-programming and described in a comprehensible way.

In the Building a Typechecker from scratch class we focus specifically on a static typechecker, and build a similar to TypeScript, Java, etc. We slightly touch Type theory and already since the first lecture go into the practical implementation.

Implementing a typechecker would also increase your engineering level, as it touches several aspects of data structures and algorithms.

Read more about the course

Prerequisites

An optional prerequisite for this class is the Building an Interpreter from scratch (aka Essentials of Interpretation) course, where we build an AST-interpreter for a full programming language. Unless you already have understanding of how programming languages work at this level, i.e. what eval, a closure, a scope chainenvironments, and other constructs are — it is recommended to take the interpreters class as a prerequisite.

Who this class is for?

This class is for any curious engineer, who would like to gain skills of building complex systems (and building a typechecker for a programming language is an advanced engineering task!), and obtain a transferable knowledge for building such systems.

If you are interested specifically in compilers, PL and Type theory, and want to build a typechecker module for your programming language, this class is also for you.

What is used for implementation?

Sometimes people think that to build a typechecker you certainly need to use some programming language which is itself “very related to types and type theory” (such as OCaml of other functional programming languages). But actually no! You can build a fully working typechecker in plain JavaScript, and cover all the aspects of the Type systems. And this is exactly what we use for implementation.

JavaScript, being the most popular programming language, should be accessible for many engineers, and also our goal is to provide a simple and concise implementation, not focusing on specifics of a host language. So the code should be portable to any language of your taste and choice: TypeScript, Rust, OCaml, C++, Python, etc.

Note: we want our students to actually follow, understand and implement every detail of the Typechecker themselves, instead of just copy-pasting from final solution. Even though the full source code for the typechecker is presented in the video lectures, the code repository for the project contains <em>/* Implement here */</em> assignments, which students have to solve.

Watch Online

This is a demo lesson (10:00 remaining)

You can watch up to 10 minutes for free. Subscribe to unlock all 20 lessons in this course and access 10,000+ hours of premium content across all courses.

View Pricing

Watch Online Building a Typechecker from scratch

0:00
/
#1: Introduction to Type theory and checking

All Course Lessons (20)

#Lesson TitleDurationAccess
1
Introduction to Type theory and checking Demo
19:39
2
Typing Numbers and Strings | Testing
04:18
3
Math binary operations | String concat
06:46
4
Variables and Typing Environment, Р“
08:17
5
Blocks and Local scope
06:55
6
Parsing: S-expression to AST
07:31
7
Control flow: If and While expressions
07:25
8
User-defined functions | Local environments
09:16
9
Function calls | Built-in functions
04:42
10
Closures | Recursive calls
05:12
11
Lambda functions and IILE | Syntactic sugar
04:30
12
Declaring new types | Type aliases
03:54
13
OOP | Classes
06:40
14
OOP | Instances
03:51
15
Super calls | Inheritance
02:49
16
Union type
06:02
17
Union | Type narrowing
07:24
18
Generics | Function declarations
06:51
19
Generics | Function calls
07:09
20
Final executable
07:04

Unlock unlimited learning

Get instant access to all 19 lessons in this course, plus thousands of other premium courses. One subscription, unlimited knowledge.

Learn more about subscription

Comments

0 comments

Want to join the conversation?

Sign in to comment

Similar courses

Make a Spotify Clone from Scratch: JavaScript PHP and MySQL

Make a Spotify Clone from Scratch: JavaScript PHP and MySQL

Sources: udemy
Do you want to become an expert in JavaScript, PHP and MySQL? Do you want to build a real music streaming site just like Spotify? If so, you’re in the right place! This course w...
14 hours 59 minutes 31 seconds
Remake Retro Games with JavaScript

Remake Retro Games with JavaScript

Sources: udemy
Old is gold. Let's get inspired by the classic games from the 80's and add our own graphics and game features.
7 hours 5 minutes 41 seconds
JavaScript Basics for Beginners

JavaScript Basics for Beginners

Sources: codewithmosh (Mosh Hamedani)
JavaScript is one of the most popular programming languages in the world. Companies like Walmart, Netflix, and PayPal run big internal applications around JavaS
6 hours 39 minutes 44 seconds