cs252r : Advanced Functional Programming - Fall 2006

These pages are a record of the in-class discussions for the graduate class "Advanced Functional Programming" given at Harvard University in the Fall of 2006.

November 1, 2006


Machinery

Obviously, the results in this paper generalize Damas and Milner's work on type inference. Briefly, how would you characterize the machinery that is brought to bear to achieve the generalization?

This formulation is based on logic, and not syntactic or algorithmic rules. The constraint system may or may not be syntactically formulated, but the type system and its proofs do not depend on this.

This paper uses models, and denotational techniques, whereas other system we have looked at use syntactic techniques.

The proof techniques in this paper are non-constructive: it is not clear how to implement this system given the way it is formulated.

Examples

In Example 11 on page 7, what should be the type for a primitive add?

 add :: forall d. dim(d) -> dim(d) -> dim(d) 

Using the semantic equations on page 8, what can you deduce about the model of the type (forall a. List a) in HM(HERBRAND)? In other words, what do you know about [forall a. List a]?

The model for this type is the intersection of all sets of values of type (List t) for some mono-type t. As it turns out, this set only contains Nil and bottom. That is, Nil and bottom are the only values that have type (List t) forall mono-types t.

One group came up with a slightly different answer:

[forall a.List a] = { bottom, [], [bottom], [bottom,bottom], ... }

Lemma 5 claims that for any closed type scheme s, [s] is an ideal, which among other properties is nonempty. Kindly identify an inhabitant of the ideal [forall a.a]. (Hint: if you have trouble, write a let-bound name for which Haskell will infer the type (forall a.a).)

A Haskell term with the type forall a.a is a non-terminating term, e.g.

 let x = x in x 

Analysis

Where Mark Jones has separate rules for forall elimination and function elimination, HM(X) seems to have just the forall-elim rule. Can you please explain why, and show the correspondence between the HM(X) system and Jones's system?

The forall elim rule also eliminates constraints: in HM(X) the forall elimination and qualifier elimination are combined in one rule. Type class constraints are the constraints in HM(MJ).

In the last part of page three, considering the constraint system C to be constructor-class constraints,

Explain in Haskell-programming terms what is meant by "(|- exists a.C) for all constraints C ... and for all type variables a in fv(C)."

What is Haskell's ``open-world assumption'' (if you don't know, ask the course staff), and what does it have to do with all this?

Section 3 is loaded with exciting formalism, but at least there are some familiar words that go with conditions C1 and C2 page 4. What are they?

Isn't the definition of "free variables" (fv(C)) on page 5 the strangest thing you've ever seen? What does it tell you about the answer to the first question above?

Can you justify using the name "satisfiability" to describe the property (|- exists fv(C).C) on page 5?

Relate the Herbrand algebra (in Example 7 on page 6) to what you know about the implementation of Hindley-Milner type inference, especially as formulated in Mark Jones's paper.

Can you relate the named rules in Figure 2 to the corresponding rules on page 209 of Damas and Milner's paper? Which rule is new in HM(X)? Can you use the claim HM = HMX(HERBRAND) to justify the fact that this rule is not required in Damas and Milner?

In the definition of soundness on page 8, do you have any guesses about why a sound constraint system requires monotype solutions?

BibTeX

@Article{Martin-Odersky-and-Martin-Sulzmann-and-Martin-Wehr1999
  , number     = 1
  , author     = "Martin Odersky and Martin Sulzmann and Martin Wehr"
  , journal    = "Theor. Pract. Object Syst."
  , issn       = "1074-3227"
  , publisher  = "John Wiley & Sons, Inc."
  , title      = "Type inference with constrained types"
  , volume     = 5
  , address    = "New York, NY, USA"
  , url        = "http://portal.acm.org/citation.cfm?id=308203"
  , pages      = "35--55"
  , year       = 1999
  }