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.
Or read this on Hacker News