4 ms·
I think one of the possibly-good moves Zig makes, similarly, is using `comptime` for generic types. I don’t have a good sense of how that interacts with paramet
by chriskrycho 4y ago
I think one of the possibly-good moves Zig makes, similarly, is using `comptime` for generic types. I don’t have a good sense of how that interacts with parametricity and ability to constrain those (and I suspect that’s an important question!) but it’s an interesting example of a possible trade off that lets the language size space.
(And: thanks!)
- skribanto 4y agoRather than traits like what Rust has, the approaches I've generally seen for polymorphic behavior are explicit "interface" structs that hold a vtable, or comptime "duck-typing". I'm still rather new to Zig so there may be other approaches, but this is what I have seen so far. One positive side effect is that there is only one "language" to learn as opposed to two different syntaxes like Rust does. While most people only use a very constrained part of the Rust type system, at the end of the day it is Turing Complete[1] (or possibly close to it? I don't know enough theory to know the rigor of what constitutes Turing completeness) and trying to keep all of it in mind can be taxing.[2] [1]: https://sdleffler.github.io/RustTypeSystemTuringComplete/ https://sdleffler.github.io/RustTypeSystemTuringComplete/ [2]: https://hirrolot.github.io/posts/why-static-languages-suffer-from-complexity https://hirrolot.github.io/posts/why-static-languages-suffer...
- anonymoushn 4y agoI'm not sure exactly what is meant here, but you just have the whole language available and you can express whatever constraints you want on the types of things.
- Rusky 4y agoThe problem is that you have to do that by hand, and thus it will be possible to get out of sync with the actual requirements of the generated code, leading to C++-like template error messages that have to include the entire stack for you to make sense of what went wrong. Or in other words, there are two parts to checking constraints: checking that the caller satisfies them, and checking that the callee doesn't accidentally rely on anything beyond those constraints. Zig's approach only gives you the first one.
- deleted 4y ago[deleted]