Repository navigation
Type System and Safety
0x4171341 edited this page Jul 24, 2026
·
1 revision
L++ is designed to be safe without a tracing garbage collector.
x := 1
mut y := 2
y += 3
A non-mut binding cannot be reassigned or have fields mutated.
Function parameters cannot be reassigned directly. Use a local mutable copy:
def double_it(x: Int) -> Int:
mut result := x
result *= 2
return result
L++ uses a hybrid strategy:
| Value kind | Strategy |
|---|---|
| primitives | copied |
| strings | ARC-managed |
| structs | stack unless escaping |
| escaping structs | ARC heap |
| containers | ARC handles |
| ownership cycles | rejected or arena-classified |
The compiler checks whether a value escapes its local scope.
Examples of escaping:
- returned from a function
- stored in a list or map
- captured by a closure
Escaping values are promoted to ARC-managed storage.
Owned cycles are rejected because ARC alone cannot reclaim them.
struct Node:
next: Node # rejected as cyclic owned struct
This prevents a large class of memory leaks.
Generics are phase 1. Type parameters are accepted by the type checker and erased to the native value representation. Full trait bounds and monomorphization are future work.
- Type aliases are parsed but full substitution is still experimental.
- Generic enum payloads and rich
Result[T]style APIs are on the roadmap. - Some older scratch examples in the repository intentionally fail safety checks.