15-150: Principles of Functional Programming

Lecture 13: Regular Expressions

In today's lecture, we discussed regular expressions, a tool which we can use to describe a wide variety of string validation problems. These can help us write efficient validators for any string recognition problem on a class of languages called regular.

Importantly, we found that regular expression matching admitted an elegant implementation when written in a continuation-passing form, which allowed us to naturally achieve a simple and powerful backtracking implementation. We saw that by giving ourselves the flexibility to define a continuation which describes what to do after a subsection of the string validation work, it allowed us to essentially enforce conditions on all future paths the matcher would take.

Due to their algebraic and composable structure, regular expressions also end up being an excellent example of a datatype in ML.

We also brought back this idea of strengthening the implementation versus weakening the specification, when trying to solve some computational problem. In the case of the regular expression matcher, we ended up being able to strengthen our implementation to rule out a class of issues having to do with looping forever on certain regular expressions.

We then finished the lecture by deciding to prove soundness and completeness for our matcher implementation.

Slides