Image for Algebraic data types

Algebraic data types

Algebraic data types are a way to build complex data structures by combining simpler ones. Think of them like puzzle pieces: they can represent different possibilities or variants. For example, a data type for “Shape” might be either a “Circle” with a radius or a “Rectangle” with width and height. These variants are combined in a structured way—either by summing options (like “either this or that”) or by nesting data (like “a list of items”). This approach helps programmers clearly model and handle data that can take multiple forms, improving code correctness and readability.