Proposal: Add `std.meta.satisfies` Function

I see the writing on the wall, but to offer some pushback…

  1. availing a solution (not necessarily a holy grail) in std, rather than via new keywords or builtins as suggested in other recent brainstorms, could be valuable to many users even if the std itself decided NOT to overcomplicate its code with use of the facility. (It looks like std code did have references to std.meta.trait, and the indirection-complication likely contributed to the smell that led to killing trait.
  2. std.meta.trait is ages old now and after a quick look at it… I feel it’s more awkward and complicated than @Verafahn’s proposal here.
  3. @Verafahn’s proposal looks like it adheres to the “optional only” aspect discussed in the earlier thread, and thus could be entirely or mostly ignored by std code if it didn’t add value.
  4. There have been recent conversations around whether std should include the kitchen sink - in particular, whether it should include facilities not needed by the language or std itself; I don’t know the core team’s read on that, but if there was readiness to expand the boundaries a little, in light of the maturity stage of zig, then this could be a candidate.
  5. If the inclusion of this (or something like this) in std made zig more attractive to programmers endeared with trait-style programming and use-cases, it could expand the scope of zig adoption. (I rarely ever write code that would benefit from the benefits of clear interface definition for polymorphic designs, so this position is not an expression of selfish desire at all).
  6. On the other hand, one of the other significant ingredients in earlier discussions has been the value of seeing interface specification in the function signature (via the use of a new zig keyword, for instance). This new proposal does not (seem to) scratch that itch, and that may be an unscratchable itch (it’s “going too far”) in that it involves supporting a new keyword (probably), and thus changing the language, not just the std.

I appreciate the thoughtfulness of your proposal, @Verafahn, and expect your vftrait lib, at least, will find users as such.

3 Likes