The Unreasonable Effectiveness of Constructive Data Modeling

Lobsters Hottest Events

Summary

By treating types as positive spaces for constructing new values rather than negative spaces for restricting values, and combining product types and sum types, we can precisely model data invariants and avoid fighting with the type checker. It recommends using simple type composition rather than complex type system features.

<p><a href="https://lobste.rs/s/vptzoz/unreasonable_effectiveness">Comments</a></p>
Original Article
View Cached Full Text

Cached at: 07/27/26, 09:49 PM

TL;DR: By treating types as positive space that constructs new values rather than negative space that restricts existing ones, and by making proper use of product types and sum types, we can precisely model data invariants without complex type system features, thus avoiding fights with the type checker. ## From the Dark Ages of Static Typing to a Renaissance The speaker originally worked on the Haskell compiler and later developed care software for nursing homes using Scala at August Health. The software involves medication management, where errors can have serious consequences, so the team placed great emphasis on correctness, extensively using tests and static typing. In the early days of static typing, mainstream languages were Java and C++. Java was conservative, restrictive, and tightly coupled with object orientation; C++ was complex and not safety-focused. This led many programmers to consider static typing outdated, embracing dynamic languages like JavaScript and Ruby. In recent years, Rust and TypeScript have brought about a renaissance of static typing—Rust emphasizes safety, and TypeScript adds types to JavaScript. All of this has made static typing "cool" again. ## The Dilemma of Type System Complexity However, the speaker is not satisfied with the current state. Type system complexity is growing too fast; most TypeScript programmers don't understand how it works and often "fight" with the type checker. Java is frustrating because it is too restrictive, and TypeScript is frustrating because it is too complex. Many think they need fancy features (like dependent types) to solve problems. But the speaker believes that by shifting perspectives and using simple product types and sum types, invariants can be effectively captured, and this works in most languages that support these features. ## Core Idea: Types Are Construction, Not Restriction ### Negative Space vs. Positive Space People usually think of types as restrictions: draw small circles in the `unknown` universe, excluding unwanted values. But Java's class definition not only restricts existing values but also introduces a new class of runtime values (e.g., `Point` structs). Therefore, types can be seen as constructing positive space from nothing. Take natural numbers as an example: if you want to represent non-negative integers only using signed integers, you would want to restrict the value set, but refinement types are hard to implement. If you first define an unsigned integer type (positive space) that contains only the desired values, then extending upward is simple. ### Non-empty List and Even-length List - **Non-empty list**: consists of "one element" and "zero or more elements". Represent it using a tuple, no complex type features needed. - **List with an even number of elements**: elements come in pairs, can be represented as a `list of pairs`. Although operations on the list need adaptation, as long as the representation and interpretation of data are decoupled, flexible modeling is possible. ### User Example: At Least One of Email or Phone Suppose there is a user struct in a database containing email and phone fields, at least one must be set. One might think dependent types are needed (the type of "email" depends on the value of "phone"). But by introducing an additional enum type that explicitly lists all possible states, the problem is solved: ``plaintext type ContactMethod = | Email(string) | Phone(string) | Both(email: string, phone: string) `` This way, the type system enforces at least one contact method. If a new state is needed later (e.g., no contact method), just add a new variant. ## Summary and Shift in Perspective The key is to shift from "type as restriction" to "type as construction". Most languages provide product types (records, tuples) and sum types (enums, unions, algebraic data types). Combined with exhaustive pattern matching, they can precisely model data invariants. Instead of pursuing overly complex type system features, think about how to construct the desired positive space using simple combinations. This approach allows programmers to regain control over the type system and reduce fights with the type checker. --- Source: YouTube: The Unreasonable Effectiveness of Constructive Data Modeling (https://www.youtube.com/watch?v=0BXuYlNrUmE)

Similar Articles

@NoraX2026: https://x.com/NoraX2026/status/2066499278449897564

X AI KOLs Timeline

This article explores how abstract modeling ability helps people quickly transfer across different domains by extracting variables, relationships, and constraints to capture the core structure, rather than memorizing specific content.

Typst: Designing for Incrementality

Lobsters Hottest

Typst uses constrained memoization (comemo) and pure function design to make the language and compiler work together, achieving efficient incremental compilation and real-time preview. The article details the design ideas of layout caching, module evaluation memoization, function purity, and the introspection system.

@Phoenixyin13: This latest blockbuster paper from Meta FAIR aims to tell the AI industry an important bellwether: "Large model data is ushering in the era of intelligent scientists." In this paper, a 4B small model precisely refined by Autodata not only crushes the same-scale models trained with traditional synthetic data on legal reasoning tasks, but also...

X AI KOLs Timeline

Meta FAIR's latest paper proposes the Autodata method, which uses an intelligent data scientist Agent to autonomously generate and optimize high-quality data, enabling a 4B small model to defeat a 397B large model on legal reasoning tasks. This indicates that data quality can bridge the gap in parameter count, providing new insights for data pipelines and scaling.

Structural Correctness

Hacker News Top

A technical blog post discussing how structural descriptions like type systems and build systems leverage graph-structured models to ensure correctness, highlighting the definitional nature of systems like Bazel.

Data types à la carte (2008)

Lobsters Hottest

This paper presents a technique for composing data types and functions from independent components, and extends the approach to combine free monads, enabling a modular structuring of Haskell's IO monad.