views:

1985

answers:

4

I encountered this term "Hindley-Milner" which I'm not sure if grasp what it means. I read Steve Yegge's "Dynamic Languages Strike Back" and "The Pinocchio Problem" and Daniel Spiewak's "What is Hindley-Milner? (and why is it cool?)". But there is no single entry for this term in wikipedia where usually offers me a concise explanation.

What is it? What languages and tools implement or use it?

Would you please offer a concise answer? Thanks.

+10  A: 

Wikipedia Reference

Sufficiently concise?

Richard A
+1 for brevity. Though I think you could make it more concise than that. :-)
George Stocker
SO seems to be a bit laggy these last few days. Your answer didn't have a proper link when I first commented. And, that comment never showed up!
Peter LaComb Jr.
@Peter: Yes, I was too ignorant to put a proper link, although it showed correctly in the preview, it didnt' show in the final post. Luckily I noticed and fixed it before you embarassed me!
Richard A
+3  A: 

You may be able to find the original papers using Google Scholar or CiteSeer -- or your local university library. The first is old enough that you may have to find bound copies of the journal, I couldn't find it online. The link that I found for the other one was broken, but there might be others. You'll certainly be able to find papers that cite these.

Hindley, Roger J, The principal type scheme of an object in combinatory logic, Transactions of the American Mathematical Society, 1969.

Milner, Robin, A Theory of Type Polymorphism, Journal of Computer and System Sciences, 1978.

tvanfosson
The latter one can be found here: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.67.5276
Magnus
+37  A: 

Hindley-Milner is a type system discovered independently by Roger Hindley (who was looking at logic) and later by Robin Milner (who was looking at programming languages). The advantages of Hindley-Milner are

  • It supports polymorphic functions; for example, a function that can give you the length of the list independent of the type of the elements, or a function does a binary-tree lookup independent of the type of keys stored in the tree.

  • Sometimes a function or value can have more than one type, as in the example of the length function: it can be "list of integers to integer", "list of strings to integer", "list of pairs to integer", and so on. In this case, a signal advantage of the Hindley-Milner system is that each well-typed term has a unique "best" type, which is called the principal type. The principal type of the list-length function is "for any a, function from list of a to integer". Here a is a so-called "type parameter," which is explicit in lambda calculus but implicit in most programming languages. The use of type parameters explains why Hindley-Milner is a system that implements parametric polymorphism. (If you write a definition of the length function in ML, you can see the type parameter thus:

     fun 'a length []      = 0
       | 'a length (x::xs) = 1 + length xs
    
  • If a term has a Hindley-Milner type, then the principal type can be inferred without requiring any type declarations or other annotations by the programmer. (This is a mixed blessing, as anyone can attest who has ever been handled a large chunk of ML code with no annotations.)

Hindley-Milner is the basis for the type system of almost every statically typed functional language. Such languages in common use include

All these languages have extended Hindley-Milner; Haskell, Clean, and Objective Caml do so in ambitious and unusual ways. (Extensions are required to deal with mutable variables, since basic Hindley-Milner can be subverted using, for example, a mutable cell holding a list of values of unspecified type. Such problems are dealt with by an extension called the value restriction.)

Many other minor languages and tools based on typed functional languages use Hindley-Milner.

Hindley-Milner is a restriction of System F, which allows more types but which requires annotations by the programmer.

Norman Ramsey
Great answer! It's just as I remember it (now) from a course two years ago :) Maybe instead of "type system" (although that's correct) it might be more illuminating to speak of "an algorithm for inferring types"...
ShreevatsaR
It's not an algorithm.
chaos
There is, however, a Hindley-Millner type inference algorithm, which is usually what is meant.
Jay Conrod
@Jay: There is *not* a Hindley-Milner type-inference algorithm; the algorithm is correctly known as the 'Damas-Milner' algorithm or as 'Algorithm W'. (There is also an 'Algorithm M'.)
Norman Ramsey
@Norman Ramsey So the Wikipedia page (http://en.wikipedia.org/wiki/Type_inference#Hindley.E2.80.93Milner_type_inference_algorithm) is incorrect to have a heading titled "Hindley–Milner type inference algorithm"?
@unknown: tecnically yes. Hindley and Milner discovered the type system; Damas and Milner discovered the algorithm. Damas is destined to be forgotten by history.
Norman Ramsey
A: 

Simple Hindley Milner Type Inference implementation in F#

http://fsharpcode.blogspot.com/2010/08/hindley-milner-type-inference-sample.html

HoloEd