3 ms·
Regarding the 'missing interface feature' it's quite trivial to write a generic comptime function which checks whether an input value has the expected shape by
by flohofwoe 2y ago
Regarding the 'missing interface feature' it's quite trivial to write a generic comptime function which checks whether an input value has the expected shape by checking it against a struct type which describes the interface (basically a comptime typeguard), such a helper function could probably go into std.meta and would provide better error messages then the followup compile errors - won't necessairly help with the LSP problem though.
Whether that's a good or bad idea remains to be seen (usually I prefer syntax sugar over such a building blocks system - reminds me too much of the C++ stdlib approach), but a surprising amount of dedicated typesystem features in other languages can be done with comptime coding in Zig.
- dminik 2y agoYeah, that should be possible and is something I considered when I was playing around with comp time. But, having a language-provided or even recommended way makes things much easier. Also, I wouldn't call it trivial. I think you need to deal with recursively comparing types and also need to handle Self and other quirks. It kind of reminds me of the other side of static/dynamic polymorphism in that much of the language lives only on undocumented conventions. At some point, the folks writing Zig decided that they really needed some runtime polymorphism for their stdlib implementation. Of course, this would be implemented in the language (using dyn traits in rust, or OOP in C++) in every other langauge. Ok, but this is Zig, so maybe it's implemented as a std.meta helper in the stdlib? Of course not. Instead you have to figure out what the stdlib does, which is of course to implement it manually for every type that needs it. Making it worse is that at some point the way to do this has changed and so at least at the time there were actually two different ways to do dynamic dispatch in the stdlib and other people's code/tutorials/whatever. What a mess of a language. So many good ideas hindered by baffling decisions. Writing Zig is like grinding teeth.