Skip to content
HN On Hacker News ↗

Replacing implicit optionals with a None type in TypeDB

▲ 13 points • 2 comments • by flyingsilverfin • 6d ago • HN discussion ↗

Pangram verdict · v3.3

We believe this text is mainly human-written, with some AI content.

9 %

AI likelihood · overall

Human
91% human-written 9% AI-generated
SEGMENTS · HUMAN 2 of 5
SEGMENTS · AI 3 of 5
WORD COUNT 440
PEAK AI % 100% · §2
Analyzed
Nov 20
backend: pangram/v3.3
Segments scanned
5 windows
avg 88 words each
Distribution
91 / 9%
human / AI fraction
Verdict
Human
Pangram v3.3

Article text · 440 words · 5 segments analyzed

Human AI-generated
§1 Human · 0%

TypeDB has implicitly handled optional variables since version 3.4. Auto-unwrapping every optional is convenient most of the time, but can hide bugs: making a variable optional silently changes your query’s answers. In addition, there is no way to condition on emptiness, making complex updates difficult to orchestrate. So, we changed our type system to include a native None type, forcing explicit handling – like Rust or Kotlin, but in a database. In this article we’ll look at null-ability and optionality, examine implicit versus explicit handling patterns, and define TypeDB’s new optionality semantics. Tldr; TypeDB 3.15 ships with a new set of constructs: an isset constraint for filtering unset variables, and if conditional operators for write clauses. These replace the automatic, implicit unwrap behaviour for enhanced control, safety, and maintainability. Now, making a variable optional forces you to handle it downstream rather than implicitly eliminating answers. And, we’ve formalized our optionals as a built-in None type that participates in TypeQL’s union-of-types model just like any other type. For example, a variable that could be polymorphically person, company, or an empty optional is typed as $x: person | company | None.

§2 AI · 100%

From null to types Every language eventually has to say “this isn’t here.” A company may not have an office address, or an order may not have had its tax computed yet. The simplest approach is a sentinel: pick a value outside the data domain, like an empty string for a missing address, and treat it as “absent.” Of course, that breaks as soon as the sentinel turns out to be a real value. A tax of 0 is a real value in most systems.As a result, most languages added a special null: one extra value that fits into every domain and can’t be confused with real data. The catch is that nothing tracks which variables might hold it, so you have to track that yourself, and every time you forget, it becomes a bug.

§3 AI · 93%

Tony Hoare called it his “billion dollar mistake”.

§4 AI · 100%

SQL adds another layer: because NULL can be compared, you can get values that are neither true nor false – but UNKNOWN. Every predicate has to account for three-valued logic. Functional languages took a different route. Instead of adding a special value to every domain, they introduced a type for absence: -- Haskell data Maybe a = Nothing | Just a // Rust enum Option<T> { None, Some(T) } Now the compiler knows which variables might be empty, and it makes you handle that case before your code runs.

§5 Human · 0%

The idea has worked so well it’s spread to mainstream languages, from std::optional in C++ to Optional in Java.