3 ms·
I’m struggling with your assertion that Zig’s meta-programming is ‘typesafe’. I am very aware of its benefits compared to C’s ‘preprocessor nonsense’ (i.e. text
by throwaway17_17 3y ago
I’m struggling with your assertion that Zig’s meta-programming is ‘typesafe’. I am very aware of its benefits compared to C’s ‘preprocessor nonsense’ (i.e. textual replacement ‘macros’), but I don’t think the normal definition of type safety covers how Zig’s meta-programming functions (I am assuming you’re talking about comptime and using Type arguments for things like generics). I am certainly able to understand how comptime expressions look well typed and safe compared to C, but, AFAIK, Zig’s comptime expressions are on par with C++ templates in Type Theory terms.
Big caveat here being, I don’t see anything wrong with the implementations of this sort of meta-programming in Zig. It is in some ways analogous to the difference between static and dynamic typing, there is a PCWalton tweet explaining his view on this somewhere [1], particular regarding generics across languages. And while I take a different stance on the issue, I do think the tweet is a decent example. Zig’s meta-programming works well and errors will be caught during compilation at some point, I just don’t think it meets the technical (probably academic-centric) definition of type safety. I think it would take a comparison to something like Template Haskell to actually find type safe macros (MetaML came say earlier, but is not very well known).
— I’m certainly open to being wrong about this from a technical standpoint, so feel free to disagree and maybe direct me to better/clearer documentation.
1 — https://twitter.com/pcwalton/status/1369101878642941953 https://twitter.com/pcwalton/status/1369101878642941953 :: There is a follow up tweet using more academic terms in a Type Theoretic setting, but I couldn’t find it quickly on mobile
- throwawaymaths 3y agoYes for typesafe generics I mean "equivalent to template <T> in c++" For sure there are type-uhdsaff generics in zig. Allocator is probably the biggest example.