Skip to main content

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.

5 votes
3 answers
377 views

Is the read / write relationship fundamentally so special?

I previously thought constants (read-only objects) are not very important in a language that isn't concerned much about safety. They are just a recursive flag, that is sometimes also used in ...
user23013's user avatar
  • 3,314
3 votes
2 answers
408 views

Does the C# type of generics need compiling to multiple instances of target code?

In C++, templated code are compiled multiple times according to the parameters. But I just realized how restrictive C# generics are: The interfaces you are using on variables in a generic parameter ...
user23013's user avatar
  • 3,314
5 votes
1 answer
236 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 ...
feldentm's user avatar
  • 2,418
3 votes
0 answers
329 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,...
Jonas's user avatar
  • 705
13 votes
5 answers
779 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): ...
Seggan's user avatar
  • 3,403
15 votes
1 answer
274 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 ...
Rob N's user avatar
  • 1,175
10 votes
6 answers
1k 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 ...
kaya3's user avatar
  • 22.4k
5 votes
1 answer
184 views

How could a language implement generic traits?

Take C#'s IEnumerable<T> interface. It has a singular requirement: ...
Bbrk24's user avatar
  • 9,672
14 votes
9 answers
1k 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, ...
rydwolf's user avatar
  • 4,870