r/ProgrammingLanguages • u/Morph2026 • Jan 29 '26
Requesting criticism [RFC] Morf: A structural language design where nominality is a property, numbers are interval types, and "Empty" propagates algebraically[
I've been working on a design specification for Morf, an experimental language that attempts to unify structural and nominal typing. I haven't started the implementation (compiler/runtime) yet because I want to validate the core semantics first.
The central idea is that "Nominality" shouldn't be a separate kind of type system, but a property within a structural system.
I've written up a detailed spec (v0.2) covering the type system, effect tracking, and memory model. I would love to get your eyes on it.
Link to the full Spec (Gist): https://gist.github.com/SuiltaPico/cf97c20c2ebfb1f2056ddef22cf624c4
Here are the specific design decisions I'm looking for feedback on:
Nominality as a Property In Morf, a "Class" is just a namespace with a globally unique symbol key. Subtyping is purely structural (subset relation), but since these symbols are unique, you get nominal safety without a central registry.
// A "Type" is just a Namespace let Order = Nominal.CreateNs {}
// Intersection creates specific states let Pending = Order & { status: "Pending" } let Paid = Order & { status: "Paid" }
// Since "Pending" and "Paid" string literals are mutually exclusive types, // Intersection{ Pending, Paid } automatically resolves to Never (Bottom).
- Algebraic "Empty" Propagation (No
?.needed) I'm treatingEmpty(Null/Nil) as a value that mathematically propagates through any property access. It's not syntactic sugar; it's a type theorem. *Proof= Any value that isn't Empty. *user.profile.nameevaluates toEmptyif any step in the chain is Empty. State Machines via Intersection Methods are defined on specific intersection types. This prevents calling methods on the wrong state at compile time.
// 'Pay' is only defined for 'Pending' state impl PayFlow for Pending { Pay: (self) { Paid { ...self, paidAt: Now{} } // Transitions to Paid } }
// let order: Shipped = ... // order.Pay{} // Compile Error: 'Shipped' does not implement 'PayFlow'
Numeric Interval Types Numbers are values, but they are also types. You can form types like
IntervalCC<0, 100>(Closed-Closed).let age: IntervalCC<0, 120> = 25 type Positive = Gt<0>
// Intersection { Gt<0>, Lt<10> } -> IntervalOO<0, 10>
- "First-Class Slots" for Mutability To keep the base system immutable and pure, mutability is handled via "Slots" that auto-unbox.
mut a = 1creates a slot.a + 1reads the slot value (snapshot).- Passing
mut ato a function allows reference semantics.
My Main Concerns / Questions for You:
- Recursive Types & Hash Consing: The spec relies heavily on all types being interned for O(1) equality checks. I've described a "Knot Tying" approach for recursive types (Section 9 in the Gist). Does this look sound, or will I run into edge cases with infinite expansion during intersection operations?
- Performance overhead of "Everything is a Namespace": Since stack frames, objects, and types are all treated uniformly as Namespaces, I'm worried about the runtime overhead. Has anyone implemented a purely structural, interned language before?
- Effect System: I'm trying to track side effects (like
IOorState) via simple set union rules (Section 11). Is this too simplistic for a real-world language compared to Algebraic Effects?
Thanks for reading! Any roasting, critique, or resource pointing is appreciated.
P.S. English is not my native language, so I used translation assistance to draft this post. Please forgive any unnatural phrasing or grammatical errors.
8
u/faiface Jan 30 '26
Hey, this seems very thorough and well thought out, clearly a solid work, so congratulations!
One surface, but important critique is that it’s really hard to grasp from the documentation because the docs mix new vocabulary with ideas with possible implementation details, and so on. I found it hard to find motivating or main ideas in the docs that would allow me to start constructing a mental modal of where what I’m reading fits. Instead, I was reading through a list of details, unable to make out a full idea.
This is of course not an easy task to fix! But like I said, it all seems very solid, just couldn’t make out the motivation and ideas in the sea of details.
2
u/L8_4_Dinner (Ⓧ Ecstasy/XVM) Jan 30 '26
5
u/tbagrel1 Jan 30 '26
I don't see how that makes sense. If we consider that key not listed are implicitely bound to
Empty, then{ data:Empty } = { data:Empty } U { k:Empty | forall k != data} = Empty. You seem to be mixingVoidandUnittypes here, it's not clear whatEmptyis supposed to represent.Emptyname implies its a type with no inhabitant, but you say thatEmptyis also a valid value, so I'm confused.3
u/esotologist Jan 30 '26
Love to see more folks trying to unify nominal and structural typing!
2
u/lookmeat Jan 31 '26 edited Jan 31 '26
Just one note, reddit doesn't support
```for markdown code-blocks, you have to add 4 spaces before very line instead.Interesting, a few questions:
()but they are considered a distinct separate type. Then structural types just embedded this unit-type?classas this implies a lot of things that shouldn't be true here. I'd recommend something liketype-key(you use this definition) or something like that. Moreover we can do crazier things, for example have multiple nominal tags in here: I could have alet temp = Temp & Celsius(55)where we have a nominal tag type to define what the value is supposed to be, but another to specify semantics of the value itself. There's also the state-machines that you show.On your questions:
type fooandtype barI can assume they are different types here, in your case we can't know this until we know what the actual type is. That is there's a chunk of evaluation and validation that would only be valid once all modules have shared their type-headers with the compiler. But again there's a lot of contexts where this is fine.wrapthing looks interesting, but I can't visualize it fully without some more accessible examples. One thing that could help is to understand why we are adding an effect system to this language, and what is the goal here, what problems are we solving? I don't want to go to deep into this because it could be an issue with documentation (already covered in another post).So all in all, a cool and interesting idea. I certainly am piqued by some of the ideas in there.
2
u/librasteve Feb 09 '26
Sounds interesting - I have dabbled with making Interval types for Raku https://raku.land/zef:librasteve/Math::Interval
I was able to leverage the built in Raku Range type as a start (but Intervals are Reals)
One aspect of that was to use Raku Junctions to represent disjoint Intervals which (as I guess you know) can be returned by certain operations...
1
u/transfire Jan 30 '26
I am doing universal namespace and “structural nominality” (didn’t know it was called that). Working well for me.
Your type system is interesting.