3 ms·
However the lack of generics means that you can't write a general-purpose map, filter, reduce, etc. I'm not so sure, why not just define them "dynamically"? Fr
by andreyf 17y ago
However the lack of generics means that you can't write a general-purpose map, filter, reduce, etc.
I'm not so sure, why not just define them "dynamically"? From the article: it's defined as an empty interface, and everything implements the empty interface
- scott_s 17y agoThat might be possible, but that seems to go against the design goal of making a systems programming language that can replace C.
- mbreese 17y agoOr have an interface "mappable" or "filterable", and then have everything include those methods... It's possible, but it does add a bit of extra complexity.
- btilly 17y agoWell if you follow the second link you will find Adam Langley (one of the initial developers of Go) saying that the type system precludes a generic map, grep, etc. You point out that everything implements the empty interface, but knowing that something implements the empty interface isn't very useful. A map, grep, etc needs to be passed a function and a bunch of data, then needs to apply the function to each piece of data. But the type system can't let you pass a piece of data to the function unless it knows the types are compatible. So if your function takes ints and adds them, then you really need to know that all of your pieces of data are ints. To use functions that accept data of other types, you will need a different version of grep for every type of function you accept. This is exactly the problem that generics tries to solve.