4 ms·
OK, The article indeed shows what the Hindley-Milner algorithm is. The discussion is similar to a google techtalk I've seen. The discussion seems straightforwa
by joe_the_user 18y ago
OK,
The article indeed shows what the Hindley-Milner algorithm is. The discussion is similar to a google techtalk I've seen. The discussion seems straightforward and I can see the connection to automatic theorem proving and prolog. But the article doesn't particular say why the algorithm is cool. I mean, one could embedded some logic problem in the types of the functions one used and get the answer to the problem using Hindley-Milner but it would be easier to just use prolog or an automatic theorem prover. Further, not all programming problems are easily amenable to being put into the form of a logic problem.
So I'm waiting for the article that shows why this is cool, I.E., what concrete problems the Hindley-Milner algorithm would be useful for.
- davidw 18y agoIf I understand things right, it can give you static typing, and the benefits that entails, without all the "Foobar foobar = new Foobar()" crap. It just figures it out for you based on how your code is written. Maybe I'm wrong though...
- silentbicycle 18y agowithout all the "Foobar foobar = new Foobar()" crap Exactly. You will spend less time restating things the compiler should be able to figure out by itself. Vanilla H-M type inference (as in SML and OCaml) requires you to write code which the type inference can completely resolve, however. This tends to lead to compilers that seem really strict until you learn to work with rather than against them, but are excellent at catching several entire categories of bugs at compile-time. The type inference also works with complicated higher-order functions (where the full type signature might be several lines long!), not just trivial examples, and rapidly determines what code will be affected by any small changes, but it can add a little more friction to rapidly changing code, and every once in a while you will still need to do things to appease it. Whether or not this is a net plus or minus depends on your programming style, the project, etc. (Dynamically-typed languages don't need type annotations either, but they have different trade-offs.)
- rcoder 18y ago"So I'm waiting for the article that shows why this is cool, I.E., what concrete problems the Hindley-Milner algorithm would be useful for." Here's a quick take: Ruby programmers (and, to a lesser extent, other dynamic OO coders) tend to get very excited about concepts like "duck typing" -- 'if it walks like a duck, it may as well be a duck' -- and tend to use it heavily for polymorphism, future-proof APIs, and other nifty "agile" programming techniques. However, with HM type inference and either modular programming (ala ML) or typeclasses (ala Haskell), you can gain most of the same terseness and dynamism of your "duck-typed" Ruby code, while still having strong compile-time checks that your "duck-like" objects in fact satisfy all the requirements of "duck-ness". The biggest trade-off, IMO, is that you now have a little logic programming language embedded in your type system, and can't compile your program until all the type constraints can be resolved. Also, unlike Java, where such problems are (from the production code I've seen, anyway) usually handled with a runtime cast through the Object ground type, languages with HM type inference usually require there to actually be a valid type-conversion function between the mis-matched types in question. None of this is unique to Hindley-Milner type inference, of course; HM is just the standard algorithm for languages which implement the simply-typed lambda calculus.
- silentbicycle 18y ago> Also, unlike Java, where such problems are [...] usually handled with a runtime cast through the Object ground type, languages with HM type inference usually require there to actually be a valid type-conversion function between the mis-matched types in question. And they usually also have pattern-matching, which makes this relatively straightforward (when there is in fact a valid conversion). It's worth taking a look at the OO system in OCaml, by the way. It works very similarly to duck-typing, but it also infers the required methods at compile time: "this function requires its first argument to be any object that takes this message with these argument type(s) and returns that type." This decouples polymorphism from inheritance/subclassing. That way, you can use OO without getting too bogged down in yucky "Circle/Ellipse" problems ( http://c2.com/cgi/wiki?CircleAndEllipseProblem http://c2.com/cgi/wiki?CircleAndEllipseProblem ). Ironically, the OO system in OCaml doesn't seem to get used all that much, though - with the other abilities the language already gives you, you don't really need to use OO except for problems for which it is actually a good fit, and in practice that's fewer than many people would claim.