4 ms·
This "mathematical interpretation" is still far too complicated for most "statically typed languages" (outside the "functional niche"). You have a handful hardw
by flohofwoe 5y ago
This "mathematical interpretation" is still far too complicated for most "statically typed languages" (outside the "functional niche"). You have a handful hardware-compatible integer- and floating-point data types which can be combined into composite data structures. The compiler checks upfront whether assignments are type-compatible (which is the biggest and most important difference to dynamically typed languages).
That's pretty much it.
- eru 5y agoEh, 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.)