5 ms·
Was hoping the author found a solution to (in my view) Zig's biggest shortcoming with generic types: a parameter that accepts all instances of a generic type mu
by nusaru 4y ago
Was hoping the author found a solution to (in my view) Zig's biggest shortcoming with generic types: a parameter that accepts all instances of a generic type must either (a) be declared as "anytype" or (b) also require a comptime parameter for the generic type argument. For example, the standard library passes around instances of std.io.Writer as anytype, so zls auto-completion doesn't work.
Also see: comptime interfaces proposal https://github.com/ziglang/zig/issues/1268 https://github.com/ziglang/zig/issues/1268
- Kukumber 4y agoI agree with that, the language needs some love in that area
- remorses 4y agoInterfaces are the most important thing Zig needs to implement ASAP It would also help creating a uniform standard library, for example creating a Writer interface instead of having specific functions for files, sockets, buffers and all kind of types
- jimbob45 4y agoHow are you going to implement interfaces if Zig is without classes in the first place?
- mirekrusin 4y agoGo has interfaces and doesn’t have classes.
- akira2501 4y agoThere's quite a bit of mildly hairy runtime code necessary to achieve this.
- anonymoushn 4y agoFor the equivalent thing (interfaces with runtime dispatch and without owning the underlying struct) Zig has explicit vtables. I sort of think any new "interfaces" feature should at least partly be about describing constraints on types at compile time.
- remorses 4y agoi think adding interfaces that are simply enforced at compile time would be a good start You could create a new type like Dynamic(InterfaceName) that handles dynamic dispatch somehow