Adding sum types (variants) to Hell

submited by
Style Pass
2024-11-23 23:30:02

Hell is my little shell scripting language that’s a thin layer over Haskell’s own standard library and runtime. This post is for people that like language implementation details. It has a simply typed system, without polytypes (no forall).

The record is a linked list type that is indexed by a type which itself is also a linked list, and in both cases we keep both a key k and a value a.

This exact representation is used in Hell. It’s defined in the meta language (Haskell) and used in the object language (Hell) directly and is manipulated in a type-safe way; so accessor functions are all total (they don’t have an “otherwise throw an error” case). I cover this in a bit more detail in Tour of Hell.

The challenging question in defining a case analysis on this type is how to make it total, and not require an “or else throw” case. I went with a simple accessor data structure that looks like a case:

It’s basically the same as Record except that every field is (a -> r) instead of just a, meaning we have a record of functions.

Leave a Comment