4 ms·
I'm actually more puzzled about the infinite recursion in this type function: fn Node(T: type) type { return struct { value: T, nex
by xg15 2y ago
I'm actually more puzzled about the infinite recursion in this type function:
fn Node(T: type) type {
return struct {
value: T,
next: ?*Node(T) = null,
};
}
In other languages, defining types in terms of themselves is unproblematic, because the type identifier is just a symbol and the whole thing amounts to a graph with a backreference.
However, here it's supposed to represent actual executable code, which is run by the compiler and "produces" a type in the end. But how would the compiler execute this function without getting stuck in a loop?
- throwawaymaths 2y agoThat seems wrong? For exactly the reason you say. The correct code, I would guess, should be `@This()` However, I also wouldn't be surprised if somehow the memoization in the zig compiler makes this ok