Skip to content

Commit 8f4ca25

Browse files
committed
feat: enable support for overlapping type and constructor names in logic schema definitions
1 parent f771cf3 commit 8f4ca25

2 files changed

Lines changed: 13 additions & 19 deletions

File tree

animated-transformer/.agents/skills/relational_linear_logic_syntax/SKILL.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,12 @@ type typeName = variant1 | variant2(...) | variant3;
3939
type list<'a> = nil | cons(head: 'a, tail: list<'a>);
4040
```
4141

42-
### CRITICAL RULE: Disjoint Type and Constructor Namespaces
42+
### Type and Constructor Namespaces
4343

4444
In this logic engine, all type names and constructor names are stored in a single flat registry (`Context.data.literals`).
4545

46-
- **No Name Overlapping:** A type name and a constructor name **must never be identical**.
47-
- **The Namespace Clash:** Declaring `type animal = animal(kind: species);` causes the constructor name `animal` to overwrite the type name `animal` in the literal registry. This results in runtime type-checking failures like:
48-
`TypeError: Cannot convert undefined or null to object` in `validateAddedTypes`.
49-
- **Solution:** Always prefix or distinguish constructor names from their return types (e.g., use `makeAnimal` or `animalKind` as the constructor for the `animal` type):
50-
```linear-logic
51-
type animal = makeAnimal(kind: species);
52-
```
46+
- **Overlapping Names are Supported:** A type name and a constructor name can safely be identical.
47+
- **Cleaner Schemas:** Declaring `type animal = animal(kind: species);` is fully supported and recommended when a type has a single primary constructor, allowing cleaner and more natural schemas.
5348

5449
---
5550

@@ -59,7 +54,7 @@ The type system does not support implicit subtyping or inheritance.
5954

6055
- **Lifting/Wrapping Pattern:** To include a value of a distinct type (like `animal`) inside a broader union type (like `item`), you must define an explicit wrapper constructor to "lift" the value:
6156
```linear-logic
62-
type animal = makeAnimal(kind: species);
57+
type animal = animal(kind: species);
6358
type item = animalVal(who: animal) | flower | rock | tree;
6459
```
6560
- **Compile-Time Enforcement:** By keeping `animal` as a separate type, you can strictly type action/state parameters to only accept animals at compile-time:
@@ -75,7 +70,7 @@ The type system does not support implicit subtyping or inheritance.
7570
Constant values or compound terms can be declared using the `let` keyword:
7671

7772
```linear-logic
78-
let myCat = makeAnimal(cat);
73+
let myCat = animal(cat);
7974
let initialStage = active(flower);
8075
```
8176

@@ -104,7 +99,7 @@ fun isFlower(flower) = true
10499
Actions represent state transitions in the linear logic story. They consume resources on the left-hand side (LHS) of the `-o` operator and produce resources on the right-hand side (RHS).
105100

106101
```linear-logic
107-
action monkeySquish: { ?j: jumpedOver(makeAnimal(monkey), flower) } -o { ?s: squished(makeAnimal(monkey), flower) };
102+
action monkeySquish: { ?j: jumpedOver(animal(monkey), flower) } -o { ?s: squished(animal(monkey), flower) };
108103
```
109104

110105
- **LHS (`{ ... }`):** The linear resources required to trigger the action.

animated-transformer/src/app/logic-explorer/logic-docs.component.html

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@ <h2>2. Algebraic Data Types (ADTs)</h2>
107107
<pre class="code-body" [innerHTML]="getHighlightHtml(listTypeCode)"></pre>
108108
</div>
109109

110-
<div class="callout warning">
111-
<mat-icon>warning</mat-icon>
110+
<div class="callout info">
111+
<mat-icon>info</mat-icon>
112112
<div class="callout-content">
113-
<strong>CRITICAL Namespace Rule:</strong>
114-
All type names and constructor names are stored in a single flat registry. Therefore,
115-
<strong>a type name and constructor name must never overlap</strong>.
116-
Declaring <code>type animal = animal(kind: species)</code> causes the constructor to overwrite
117-
the type, yielding type-checking failures at runtime. Always prefix or vary the constructor:
118-
<code>type animal = makeAnimal(kind: species)</code>.
113+
<strong>Namespace & Overlapping Names:</strong>
114+
Type names and constructor names are stored in a single flat registry, but they
115+
<strong>can safely overlap</strong>. Declaring <code>type animal = animal(kind: species)</code>
116+
is fully supported and allows the constructor to share the name with its type, providing
117+
a cleaner and more natural syntax.
119118
</div>
120119
</div>
121120
</div>

0 commit comments

Comments
 (0)