How to resolve the algorithm Algebraic data types step by step in the E programming language

Published on 12 May 2024 09:40 PM
#E

How to resolve the algorithm Algebraic data types step by step in the E programming language

Table of Contents

Problem Statement

Some languages offer direct support for algebraic data types and pattern matching on them. While this of course can always be simulated with manual tagging and conditionals, it allows for terse code which is easy to read, and can represent the algorithm directly.

As an example, implement insertion in a red-black-tree. A red-black-tree is a binary tree where each internal node has a color attribute red or black. Moreover, no red node can have a red child, and every path from the root to an empty node must contain the same number of black nodes. As a consequence, the tree is balanced, and must be re-balanced after an insertion.

Red-Black Trees in a Functional Setting

Let's start with the solution: