Questions tagged [generics]
Generic types permit functions, types, or classes that can dynamically depend on one of multiple possible types, such as a set that can be parameterized to contain only strings. Use this tag for questions about designing and implementing generic types in a language.
7
questions
5
votes
1
answer
198
views
Prior art on precedence rules on template instantiation for inner entity clashes
I'm looking for prior art on languages handling clashes happening during template instantiation between inner entities. For example, if we have a type parameter E intended to be an exception type and ...
3
votes
0
answers
211
views
How to implement type checking of generics?
I am implementing a toy language, for learning. As of now, it has a Rust-like syntax and I would like to implement monomorphization of Generic types.
After parsing, I have an Abstract Syntax Tree. Now,...
13
votes
5
answers
409
views
What strategies did Go use to circumvent the lack of generics?
Go (was) famous for its lack of generics. However, the lack of generics in a statically typed language makes quite a few things harder. For example (in a pseudocode because I don't know Go):
...
15
votes
1
answer
212
views
Pros and cons of overloading vs type classes or similar polymorphism
I'm playing with creating a language after doing the LLVM Kaleidoscope tutorial. I've added some basic type checking, and now I want to add some functions that write things to standard output, as must ...
7
votes
4
answers
519
views
How to choose between monomorphisation and type erasure for generics?
Generic functions in compiled languages can be implemented in (at least) two different ways:
Monomorphisation ─ separate versions of the function are compiled for each different assignment of type ...
5
votes
1
answer
127
views
How could a language implement generic traits?
Take C#'s IEnumerable<T> interface. It has a singular requirement:
...
15
votes
9
answers
831
views
What are some syntax options for describing generic ("templated") types?
In languages like C++ and Rust, generics use angle brackets. For example, Vec<f64> for a vec of floats, ...