> This article and discussion emphasises the key debate over
> generics and arrays, and which approach works best. I've
> had a variety of conversations with language designers
> down the years, and one thing I've noticed is that there
> is often a strong emphasis on proving the type system. As
> part of this, there is often a extremely strong dislike of
> arrays because of their 'unsound' covariant nature.
>
> However, in the real world, I find that all the developers
> I talk to have no problem whatsoever with the covariant
> nature of arrays, and even find it more intuitive than the
> restrictions imposed when its done 'correctly' (generics).
> I can only conclude that this is just a difference in how
> (academic) language designers and developers think about
> the languages they write/use.
>
I suspect the dislike is on array covariance, not arrays per se. Is that correct? Because I'd expect nonvariant arrays in a language with generics wouldn't bother anyone, academic or otherwise.
> If you want to see what a JavaNG language looks like where
> you can freely switch between a List of Numbers and a List
> of Integers, take a look at Fan -
http://fandev.org .
> Where Scala takes Java's type system and strengthens it,
> Fan goes the opposite direction, and takes a slightly more
> dynamic approach. Given the success of fully-dynamic
> languages over the past few years, it seems to me that
> Scala's super-static typing isn't the way for the industry
> to go.
>
I've been curious about Fan's approach. My understanding is users can't make generic types, but that three built in types (Map, List, and Func) take type parameters. I assume Map takes 2, List 1, and Func a return type plus 0 to many parameter types.
First, are these type parameters on Map, List, and Func treated as nonvariant, covariant, contravariant? Or some combination? I see no mention of variance in their documentation.
Also, what do people usually do when they want to make some other collection besides List or Map? Do they cast, or perhaps use the -> to invoke mehods dynamically on objects pulled out of collections?