2 ms·
Adding a Hindley-Milner-like type-inference to a language that has subtype polymorphism and method overloading is really not a good idea (or possible for that m
by bad_user 17y ago
Adding a Hindley-Milner-like type-inference to a language that has subtype polymorphism and method overloading is really not a good idea (or possible for that matter).
let plus x y = x + y
let sum = plus 1 2
This is Ocaml, but let's assume it has type-classes. Method "plus" would be a generic method with a type like ...
(Num 'a) -> (Num 'a) -> (Num 'a)
The actual return type (int) is detected when the actual call is made. But that's assuming you know the actual types of the parameters at compile-time. And that's not the case in OOP languages ... by definition they have (at least) single-dispatch.
That's why languages like Ocaml don't allow this. Full type-inference and languages like Java / C# don't mix.
- jbellis 17y agoGo doesn't have method overloading, and it doesn't have polymorphism in the traditional sense either. (Not sure what effect Go's Interface inference has on H-M.)
- jganetsk 17y agoI think it's ok. I would think it's like type classes, which work pretty well for Haskell. And Go doesn't need full-fledged type inference. I bet they could work something out that's simpler and more explicit. Regardless, even explicit type variables would be very useful.