4 ms·
Type parameterization has been around for a long time, but all existing implementations make tradeoffs the Go team is not willing to make: http://research.swtch
by crawshaw 12y ago
Type parameterization has been around for a long time, but all existing implementations make tradeoffs the Go team is not willing to make: http://research.swtch.com/generic http://research.swtch.com/generic
- pjmlp 12y agoOr don't know how to implement. It has been pointed out multiple times that the page you refer to, only focus on C++ and Java, while forgeting about all the other languages.
- crawshaw 12y agoIf there exists an implementation of type parameterization that imposes neither a compile time cost nor a run time cost, I would be interested in reading about it. The languages and compilers I'm familiar with (Scala, Haskell, MLton) all pay a cost, usually in compile time.
- kvb 12y agoWhat's problematic about .NET's approach[1]? [1] http://research.microsoft.com/en-us/um/people/akenn/generics/FOOL2003.ppt http://research.microsoft.com/en-us/um/people/akenn/generics...
- MichaelGG 12y agoThe answer, as I understand, is that .NET has to copy code for each non-reference-type instantiation. .NET gets away with it because most types are reference typed and can use the same code. In F#, you can use hat types via inlining to get even more power. Like creating a map function that works directly on List, Array, and Set - but without using any common interface. Pretty neat, but it emits the function's IL into every callsite so it can get out of hand. I recall there being a mailing list thread on Go where the designers addressed this. I've no idea how Go is implemented so perhaps the multiple-copies problem is actually significant.
- kvb 12y agoTechnically, I believe that value types with the same layout could share implementations (though I don't believe this is implemented). In any case, if you don't have generics you have to do the same thing by hand anyway (e.g. create an IntList type, a DoubleList type, etc.), so I can't see how that's any better. More likely, I think, is that Go doesn't do JIT compilation, so there would be some challenges getting a comparable implementation built on Go's runtime. But .NET's new native toolchain solves the same problem, so it's clearly not insurmountable.
- pjmlp 12y agoIn cases static linking is used, which happens to be Go's case, this can be done at link time. Also addressed by Ada generics for example. There are many others. Strong typed languages with generics go back to CLU (1974), so there are lots of research material, as well as, real languages if one steps outside Java/C++ implementation mindset.
- warfangle 12y agoI'm uh, pretty sure the people who practically invented Unix know how to implement generics if they wanted to.
- pjmlp 12y agoSometimes people are placed in pedestals, but they are only human.
- NateDad 12y agoThey are human. They've also been programming for over 30 years with numerous big successes that prove they know what they're doing.
- pjmlp 12y agoSo how successful would have been UNIX and C if AT&T reacted sooner than it did in terms of ownership and prevented universities access to them? Edit: Removed stupid comment.