3 ms·
> Other generics systems provide more information to the compiler, so in addition to compiling faster and providing The templating system in C++ is not generi
by soulbadguy 10y ago
> Other generics systems provide more information to the compiler, so in addition to compiling faster and providing
The templating system in C++ is not generic type system, it's not even strictly speaking part of the C++ type system. It's usually define as a metaprogramming facility. Because it be used to abstract on types, it's the defacto generic system in C++, but it can also be used to abstract over definitions, expressions, computation shapes (like unrolling a loop on a factor relative to the size of a type). C++ templates are slow when compared to other generic system because of a lot of bad design decisions (compilation model and how/when a template has to be intanciated), but also because it can do more, and is used to do more.
> the compiler can use knowledge of specific type classes, interfaces, modules to optimize the implementation of.
Depends on what you mean by more information: In c++ complex type constraints can be express through template. Even more important, in you example you have to rely on someone in the rust compiler community to implement that specific type transformation. Because, the template system is extremely expressive,whoever designed the "option type" can also ship instructions to the compiler on how to specialize for NonZero type...
> You can also have nice features like GHC's rewrite rules which allow you to effectively tell the compiler how to optimize your types.
It's hard to have both, most generic type system are fast because they don't do much
as you start adding feature and smartness into the system, the performance degrades...scala compile time being a good example.
> Rust and Haskell both have it.
can you specialize on struct in rust/haskell or just implementation of traits ?