On Feb 17, 8:12 am, Reinier Zwitserloot <[email protected]> wrote: > agreed, sort of. We really have to decide if we want java to become a > structural/nominal hybrid language. Right now java is strictly > nominal. BGGA wants to add functional types, which is structural > typing (I don't give you a Comparator, nono, I give you an {Integer, > Integer => int} - that's not nominal typing).
Well, not quite. List<String> is the same type as List<String> not (only) because they have the same name, but because they have the same type arguments. That's structural typing, and generics are indeed structurally typed. As are arrays. Java is not strictly nominal. > Scala solved this by creating 22 > tuple classes. I don't think this is an acceptable solution. Pair-wise > generics requires more generics syntax before you can use it, and if > ever you need to make an explicit mention of the generics type, it's a > total horrorshow (Tuple<String, Tuple<Integer, Tuple<List<String>, > Nothing>>> is what you'd actually have to write when all you meant was > a (String, Integer, List<String>) tuple). It seems logical to just add > N-tupled generics parameters, but that's not exactly a simple change > to make. Indeed, the whole point of structural typing is the eliminate the syntactic mess. One could define (T,U) as meaning identically the same thing as Pair<T,U>, and then you get the best of both worlds. BGGA doesn't actually introduce an extension to the type system for function types - they are defined as shorthand for an instance of a system-provided nominal interface type. The structural behavior of BGGA's function types is due to the fact that generic types are already structurally typed in Java. > The easiest solution, but it feels hackish to me, is to auto-generate > the tuple classes. And somehow make sure that they're the same type when accessed from different class loaders, etc. Yes, that's the usual technique for defining structural types. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaposse?hl=en -~----------~----~----~----~------~----~------~--~---
