Daily Thought - 2025-02-27
Hey, I'm Hanno! These are my daily thoughts on Crosscut, the programming language I'm creating. If you have any questions, comments, or feedback, please get in touch!
I like designs that consist of simple, orthogonal, and composable elements. To understand what that means, let's look at a design that isn't that. Here's how you define a struct in Rust:
struct Measurement {
value: Value,
unit: Unit,
}
To define a struct, you have to give it a name, and it's always nominally typed. Those are three concepts (data layout, type name, nominal typing) that are inextricably tied together in this one thing.
Let's look at another Rust example, defining a tuple:
type Measurement = (Value, Unit);
Tuples are always structurally typed, so giving them a name is optional. Here, I'm providing a name using a type alias. I think design-wise, this is a bit better than the previous example; because everything I'm showing here is orthogonal and composable. But there's no way to make it nominally typed.
At least not directly. You could completely change it into something else, a tuple struct:
struct Measurement(Value, Unit);
Now we're back to using a struct which bundles all those different concepts, like the original example above. Except that this kind of struct is also partially redundant with tuples.
I think this approach to data types is weird and undesirable. Is is neither simple (some elements are bundles of multiple concepts), orthogonal (different elements are redundant with one another), nor composable (can't make a nominally typed tuple or a structurally typed struct).
Hey, you! Want to subscribe to my daily thoughts? Just let me know (maybe include a nice message, if you're up for it), and I'll send you an email every time I post a new one.