You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type list<'a> = nil | cons(head: 'a, tail: list<'a>);
40
40
```
41
41
42
-
### CRITICAL RULE: Disjoint Type and Constructor Namespaces
42
+
### Type and Constructor Namespaces
43
43
44
44
In this logic engine, all type names and constructor names are stored in a single flat registry (`Context.data.literals`).
45
45
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.
53
48
54
49
---
55
50
@@ -59,7 +54,7 @@ The type system does not support implicit subtyping or inheritance.
59
54
60
55
-**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:
61
56
```linear-logic
62
-
type animal = makeAnimal(kind: species);
57
+
type animal = animal(kind: species);
63
58
type item = animalVal(who: animal) | flower | rock | tree;
64
59
```
65
60
-**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.
75
70
Constant values or compound terms can be declared using the `let` keyword:
76
71
77
72
```linear-logic
78
-
let myCat = makeAnimal(cat);
73
+
let myCat = animal(cat);
79
74
let initialStage = active(flower);
80
75
```
81
76
@@ -104,7 +99,7 @@ fun isFlower(flower) = true
104
99
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).
0 commit comments