3 ms·
> How many OOP languages do you know where type-inference works? D, C++0x
by p0nce 17y ago
> How many OOP languages do you know where type-inference works?
D, C++0x
- bad_user 17y agoThose only work for local declarations where the type of the expression is known. This thread was talking about type inference in this case ... var l = [12.4, 13, "a string"]; This would require the array to have generic arguments, and those generics arguments to be inferred from the types given to the constructor (in this case the base class would be Object). I think it works in Scala, but a type unification is really hard ... i.e. to be able to write your own generic functions / classes with the generic type inferred from the base class of the given arguments. The definition of a generic function that would do this would look like ... Array<T> createArray<T> (T ... args) Also, since generic definitions are a PITA to write and read, many people dream of a Hindley-Milner type system where the generic type is discovered. But I don't know of a single OOP language that does that (Ocaml and F# try, but it's ugly) since OOP polymorphism is not compatible.