Open badlogic opened 9 years ago
Turns out C# allows you to specify variance with in/out. There are still limits on primitive types.
Concise overview www.cs.cornell.edu/Courses/cs312/2007fa/lectures/lec22-type-inf.pdf
Check how Java, Ceylon, Scala, C# et al treat variance.
Typing rules & judgements: http://www.cse.chalmers.se/edu/year/2012/course/DAT150/lectures/proglang-07.html https://www.google.at/url?sa=t&source=web&rct=j&ei=ReylVN6vO8f0UPeWgegK&url=https://www.cs.utah.edu/~mflatt/past-courses/cs3520/public_html/f02/lecture14.pdf&ved=0CC0QFjAGOAo&usg=AFQjCNHPc6eHeeCaANdaScS_vIO0MCGTJA&sig2=9v8wlGqdZzpcUMFYN-2Umw
Tate on Java wildcards and use-site variance http://www.cs.cornell.edu/~ross/publications/tamewild/tamewild-tate-pldi11.pdf
Mixed site variance in Java, JEP: http://openjdk.java.net/jeps/8043488
Scala's type hierarchy: http://docs.scala-lang.org/tutorials/tour/unified-types.html auto-boxing/unboxing for AnyVals. Can't create own AnyVal.
Quick intro to co-/contravariance: http://www.stephanboyer.com/post/39/covariance-and-contravariance
Assuming we treat everything as an object like Scala, but optimize for AnyVal (use primitives, auto-box/unbox). How'd we be able to generate code for this (ignore bool which is also an anyval)
def sum<T: AnyVal>(l:List<T>) {
var sum: T
foreach(v in l) {
sum += v
}
}
Well, i just answered my question. What about Any? Check what Scala folk can do with any. I.e. comparator interface over any. Possible? Or is any just a virtual
type?
Good answer on Scala variance http://stackoverflow.com/questions/663254/scala-covariance-contravariance-question
Ceylon type system http://ceylon-lang.org/blog/2012/01/18/type-system-manifesto/
Scala specialization: http://www.scala-notes.org/2011/04/specializing-for-primitive-types/
Generics should not be covariant, i.e. Array != Array
Compare to C#