3 ms·
It's not. How many OOP languages do you know where type-inference works? I know of none ... Ocaml uses a special syntax for reconciling the type-inference with
by bad_user 17y ago
It's not. How many OOP languages do you know where type-inference works?
I know of none ... Ocaml uses a special syntax for reconciling the type-inference with the inclusion polymorphism that it supports ... (name : sub_type :> super_type). And IMHO it gets ugly.
I'm not really clear about what "type unification" you're referring to, but the actual types in Java aren't known until runtime (you usually only know a parent). To change this behavior an overhaul of the entire architecture is needed.
- StrawberryFrog 17y agoHow many OOP languages do you know where type-inference works C# Not "type-inference" in the very general sense, just "type-inference" in the "when you see 'var someVar = 3;' you can infer that someVar is of integer type" sense. Which is what java is doing again. Playing catch-up to c#.
- bad_user 17y agoJava is not adding local type inference as in C#. It only adds the diamond construct for inferring the generic types from the variable's type being assigned ... Map<String, Integer> m = new HashMap<>(); Which is ugly, but many Java developers are taking "programming to an interface" rule quite literally.
- 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.