|
|
|
|
|
by j-pb
1579 days ago
|
|
Kinda, but much more than that and the ergonomics are quite different as the entire language is basically available. For example in Zigs comptime, types are first class citizens which can be queried and operated on. This gives you generics without a lot of type system magic, and even const generics over arbitrary types. All without a macro system or Turing-Complete type checking (similar in flavour to the DeBruijn criterion: the comptime code/higher order proof system is turing complete but the type/core checking is straight-forward). And yes the problem you describe could exists, but I've not encountered anything like it in practice. But the idea you had there captures the difference between Zigs and Rusts type-system/generics quite nicely: > Rust tries to proof universally qualified correctness and behaviour of code, i.e. regardless of its context, while zig only proofs you the correctness of specific instantiations. While this may sound like a bug, I'd argue that it's a feature, as it's YAGNI applied at a type level, and for example allows you to do things like: switch (builtin.target.cpu.arch) {
.x86_64 => //do intel stuff
.aarch64 => //do arm stuff
else => @panic("unknown arch!");
}
With the switch arms that don't apply simply being ignored and never type checked.
This allows you to use a basic language construct where C requires a preprocessor and Rust requires macros or compiler magic. |
|