Get the latest tech news

Adding algebraic data types to Nickel


A recent release of Nickel added algebraic data types and pattern matching. This blog post explains the motivation behind this addition, the design choices made, the considerations around backward compatibility and how ADTs can be useful for a configuration language.

As we have been writing more and more Nickel, we realized that we have been missing ADTs a lot for library functions - typically the types enum Option<T> { Some(T), None } and Result<T,E> = { Ok(T), Error(E) }- where we don’t care about serialization. This difficulty just doesn’t exist in a nominal type system like Rust: there, Option::Some refers to a unique, known and fixed ADT constructor that is known to require precisely one argument. After exploring the route of union types, which came to a dead-end, we settled on a structural version of ADTs that turns out to be a natural extension of the language and didn’t require too much new syntax or concepts.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of nickel

nickel

Photo of Algebraic Data Types

Algebraic Data Types

Related news:

News photo

MIT develops low-cost, high-energy batteries using disordered rock salt cathodes | The new material family primarily comprises manganese, an earth-abundant element less expensive than nickel and cobalt.

News photo

The algebra and calculus of algebraic data types (2015)

News photo

The Smallest, Lightest Solar-Powered Drone Takes Flight | It weighs less than a nickel and can fly nonstop while the sun shines