Tech News
← Back to articles

Modular Interpreters and Visitors in Rust with Extensible Variants and CGP

read original related products more articles

Programming Extensible Data Types in Rust with CGP - Part 2: Modular Interpreters and Extensible Visitors

Posted on 2025-07-09

Authored by Soares Chen

Discuss on Reddit, GitHub or Discord.

This is the second part of the blog series on Programming Extensible Data Types in Rust with CGP. You can read the first part here.

As a recap, we have covered the new release of CGP v0.4.2 which now supports the use of extensible records and variants, allowing developers to write code that operates on any struct containing specific fields or any enum containing specific variants, without needing their concrete definition.

In the first part of the series, Modular App Construction and Extensible Builders, we demonstrated an example use of the extensible builder pattern, which uses extensible records to support modular construction of an application context.

In this second part of the series, we will explore the use of extensible variants, by examining how it can be used in an extensible visitor pattern to build a modular interpreter for a toy math expression language.

Part 1: Modular App Construction and Extensible Builders – In this introductory part, we present a high-level overview of the key features enabled by extensible data types. We then dive into a hands-on demonstration showing how extensible records can be used to build and compose modular builders for real-world applications.

Part 2: Modular Interpreters and Extensible Visitors (this post) – This part continues the demonstration by introducing extensible variants. We use them to address the expression problem, implementing a set of reusable interpreter components for a small toy language.

... continue reading