News for hackers. Stuff that matters.
Re:Zig-style generics are not well-suited for most languages by pron on Sunday October 09, 2022 @07:38PM (#33146346)
> The C++ committee added concepts after decades of pain with templates, and even these do not overcome all the problems mentioned above. I would not be surprised to see Zig add a similar system (likely with its own twist to it) at some point if it keeps growing in usage.

Templates in C++ are quite different because of overload candidate resolution (and so SFINAE), which makes debugging templates a pain. Zig doesn't have overloads at all, plus, the error reporting mechanism (which C++ doesn't have) is available at compile time, as it is at runtime.

Having said that, I actually would like to see "concepts" in Zig, probably as a simple boolean predicate as the type, for one reason, and one reason only, which isn't mentioned in the article: documentation.

Re:Zig-style generics are not well-suited for most languages by throwawaymaths on Sunday October 09, 2022 @07:51PM (#33146418)
I think this could be basically done as a check in the stdlib relatively easily, via something like:

    const MyConcept = std.concept.build(.{...});

    const requires = std.concept.requires;

    const MyType = 
      requires(
        MyConcept, 
        struct{
          ...
      });
requires simply passes through the type passed to it.

If it fails, it gives some nicely formatted compile time errors.

Re:Zig-style generics are not well-suited for most languages by kassane on Monday October 10, 2022 @09:02AM (#33150820)