3 ms·
> C++ templates on the other hand you could argue are not types (but templates), but that is nit-picking. Not only is it nitpicking, it seems wrong even in an
by mhh__ 6y ago
> C++ templates on the other hand you could argue are not types (but templates), but that is nit-picking.
Not only is it nitpicking, it seems wrong even in an academic sense of the term. Whether the template itself is a type or not probably depends on what theoretical language you use to discuss it.
The template is monomorphized into a new type per instantiation, yes, but the moment it actually has a number in it it's a type.
In D the template can quite happily accept pretty much anything as a parameter (particularly structs i.e. better code quality), and I'm surprised other languages don't allow this. Why have a bunch of template parameters on a line when you can just program the way you normally would.
- steveklabnik 6y ago> I'm surprised other languages don't allow this. Rust doesn't (arbitrary values, anyway, const generics is the start of this being possible) because we don't have templates, we have generics. I agree if you're going with a template-based system, it makes a lot of sense to accept whatever, but if you aren't, then things are more complicated.
- mhh__ 6y agoI think the typechecking here should be possible for rust in the sense that it's just a value of a known type (this isn't like C++ hacks). https://d.godbolt.org/z/Tb5jKv4ns https://d.godbolt.org/z/Tb5jKv4ns
- steveklabnik 6y agoIt's possible, (and I think might even work on nightly? Don't have the time to check right this second) but is just a lot more work to support than in a template-based system, that's all. We'll get there!