7 ms·
But everything you can do with generics you can do manually by copying and pasting code?
by chrisseaton 4y ago
But everything you can do with generics you can do manually by copying and pasting code?
- brabel 4y agoOh that's true. But you're a terrible masochist if you consider that an option.
- spion 4y agoLets take `map` for example. Before generics, you would have to reimplement map for every type combination. Each implementation would be done with a for loop. Now, while I'm willing to look over having one `map` implementation being done in imperative code and then everything else using that, I'm not exactly comfortable calling reimplementing map with imperative code for every type combination functional programming.
- spion 4y agoOr lets look at persistent data structures, a staple of functional programming: https://github.com/tobgu/peds https://github.com/tobgu/peds Notice how you'd need to generate the DS for every type you'd like to use it with, which is not the case with built in mutable maps and slices. To make them type-safe, you need to generate them for every type you use. While this is technically possible, it does make the language quite hostile towards functional programming. With generics, this is rectified but the problem with non-composable multi-return-value functions still remains