2 ms·
Eh, even outside the functional niche generic types are pretty mainstream these days. Eg people reasonably expect that their language's standard library offers
by eru 5y ago
Eh, even outside the functional niche generic types are pretty mainstream these days. Eg people reasonably expect that their language's standard library offers a sorting function that can deal with any comparable items.
And once you have that kind of functionality, you need more than just what you described.
(And, no, Go's approach doesn't cut it. Their 'generic' sorting interface only works for in-place algorithms.)
- flohofwoe 5y agoGenerics are mostly just a compile-time duck-typing layer on top of the simple static typing model I described (with the purpose of getting some of the flexibility of dynamic typing back into a statically typed language).
- reuben364 5y agoGenerics are not really the statically typed answer to duck-typing. Subtyping with structural types, such as in TypeScript, is.
- eru 5y agoI think the confusion might stem from C++'s templates. Those templates can be used to do something like generics, but they are also basically duck typing at compile time. In Haskell terms, C++'s generics are like typeclass-instances without typeclasses themselves. (I think in Java terms they would be similar to not providing interfaces. But I don't know enough about Java to see whether that's actually true.)