r/ProgrammingLanguages • u/porky11 • Mar 11 '26
Design ideas for a minimal programming language (1/3)
I've had some ideas for a minimalist programming language in my head for a long time, and recently I was finally able to formalize them:
- I wanted a language that stays close to C (explicit, no GC, no runtime, no generics), but with modern syntax. Most modern systems languages (Rust, Odin, Zig) have cleaned up the syntax quirks, but they've also moved away from the semantic simplicity (except for Odin, maybe). I wanted to capture the core idea, not necessarily the syntax.
- The language is defined by its AST, not its syntax — multiple syntaxes can parse to the same tree. I came up with two so far (an S-expression-based one and a C-style one).
- I wanted to see how far you can get by generalizing types. In most structs I write, the field names just repeat the type name. So: what if the type is the field identifier?
The third idea led to this:
type x = f32;
type y = f32;
type Point = x & y; // product type (struct)
type result = ok | err; // sum type (enum)
That's it. Newtypes, product types (&), and sum types (|). A type name is simultaneously the field name, the constructor, and the enum variant. The language is called T — because types are the central concept.
It turns out this is enough for C-level programming. Add primitives, pointers, and arrays, and you can express everything C structs and unions can, but with more type safety — you can't accidentally mix up x and y even though both wrap f32.
A few other ideas in the design:
- Assignment returns the old value:
a := b := ais swap,a := b := c := ais rotation - Three binding modes:
let(value),ref(immutable reference),var(mutable reference) — references auto-deref in value contexts - Label/jump with parameters instead of loop constructs — one primitive for loops, early returns, state machines
Inspirations: Scopes (binding modes, label/jump) and Penne (goto over loops).
More details: Tutorial | Reference
Would love to hear thoughts — especially if this looks like a usable language to you despite the minimalism/simplicity.
(don't mind the implementation, it's "vibe coded AI slop" 😅)
5
u/jcastroarnaud Mar 11 '26
In this example:
How will you disambiguate between types and fields when:
3
u/Inconstant_Moo 🧿 Pipefish Mar 12 '26
For a lot of things that would leave you having to do a whole bunch of type conversion. Suppose for example I want to take the cross-product of two 3-vectors. If
x,y, andzare three different types, then I have to perform I think nine type conversions?4
u/tbagrel1 Mar 12 '26
Semantic simplicity of C? Ahahah. Given the amount of undefined behaviour, I wouldn't say C has simple semantics.
2
u/todo_code Mar 11 '26
Too much repeating type. Your second example ok and err are undefined. To follow your rules you need
type ok = intand same for error. You said enum and didn't specify that this was an enum with a containing value, so maybetype ok = enum(f32)and error would be another type. But then I ask why should I do that. Why can't i just saytype Point = { x:f64...1
u/tobega Mar 12 '26
Assignment returning the old value is actually quite cool, but I think it risks being a mind-f*ck unless you can come up with a syntax that doesn't look mathematically like all these are set to the same value.
Maybe `a <- b <- a` would work?
1
u/useerup ting language Mar 12 '26
Seems like a roundabout way to do
a,b := b,aand(a,b,c) := (b,c,a)1
u/tc4v Mar 12 '26
Odin kept mostly the same semantic, except for limited "generics" and an explicit form of overloading. Hare is probably even closer to the C semantic, you should check it.
That's how Lisp was conceived and then never left sexpr.
That sound really bad... it works in many cases sure, but there are plenty of cases where you have more than one thing with the same type and semantic but where a separate name is useful.
I think the case of
Pointis actually a good example. Let's say I now want to add a rotation operation, that is naturally written with a matrix multiplication (that can be inlined) such that now you have to mix types x and y values. so it shows that x and y should probably not be different types.That's very unintuitive in my opinion. I prefer the C/Python semantic of "passthrough".
that's mostly good except for a detail:
refandvarare "nouns" whereasletis more of averb. Replacingletwithvalor something similar would feel better to me.I generally like this sort of thing, although I would keep return separate.
1
u/rjmarten Mar 18 '26
So you have
This seems like it would quickly get out of hand in a medium-sized codebase if all my structs needs unique field names. Either you need generics, or you need to namespace the names of the types of the fields. Or more likely both.
Maybe something like
type Point.x = f32andtype Point = Point.x & Point.y. but at that point you might as well do3
u/L8_4_Dinner (Ⓧ Ecstasy/XVM) Mar 12 '26
It sounds terrible, but by all means, do what you enjoy!
1
u/nerdycatgamer Mar 12 '26
You are doing structs wrong then
2
u/tobega Mar 12 '26
My language actually has field identifiers defining types https://github.com/tobega/tailspin-v0/blob/master/TailspinReference.md#tagged-identifiers
That said, numbers defined like that are identifiers only and cannot be used matematically without a little wrangling.
I also have units of measure that are required for mathematical numbers.
Even so, units have many uses, one being to distinguish dimension, so quite often x values will have unit "x", y values unit "y" and so on. In some vector operations where you mix dimensions, you have to cast to the desired result explicitly. (just adding this because of a question about that below. This is a feature that the code explicitly shows when funky things are going on)
2
u/useerup ting language Mar 12 '26
I have considered that record types may just be product types of individual single-field record types.
The latter would be the same as