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 8, 2006


Technicalities

In the upper right of Figure 1 on page 11, why doesn't the figure just make rho ::= tau | sigma? Given your answer to this question, what informal characterization of rho describes all type systems in this paper?

Making rho ::= tau|sigma would limit the system to rank 1 polymorphic types.

None of the rhos in the paper have a top-level forall quantifier.

What is skolemization? Rewrite rule skol on page 14 to make the skolemization less cunning and more explicit. Your new rule should include a side condition of the form "b fresh".

remark: (from nr) The skolemization theorem says: forall a. exists b. P(a,b), which is equivalent to the statement: exists F. forall a. P(a,F(a)). Both of these are implied by the statement: exists c. forall a. P(a,c). However, it is not clear what this has to do with the descriptions in the paper.

Algorithmics

This paper goes to great lengths to develop simple logical rules into working code. These questions are intended to help you develop your understanding of that process.

What can you conjecture about general strategies for making logical rules syntax-directed?

In general, the problem you need to deal with is where you have rules in which the premise has the same form as the conclusion.

When you have a rule with the same form in its premise and conclusion, you can proceed by incorporating the rule into all of the other rules; essentially, applying the rule everywhere possible. In some cases, you may be able to determine that the rules have no effect at certain points and can be removed.

What can you conjecture about general strategies for making syntax-directed rules deterministic?

In addition to the problem above, another problem is when you have multiple rules with conclusions of the same form. This will also introduce non-determinism into the system.

When you have two rules with the same conclusion, you may be able to combine them into one larger rule with a disjunction in the premise. However, in some cases there may not be a clear test for choosing one over the other.

Another strategy is to introduce fresh skolem constants, and generate a set of constraints. The problem then becomes one of solving constraints. If the constraints have unique solutions, then the rules are deterministic.

We have already read about a formulation of type inference with explicit substitutions. (I believe it was in Mark Jones's paper on constructor classes.) That formulation uses lots of substitutions. Yet in their implementation, PJ et al. use but a single substitution, which they mutate in place. What kind of argument would you make to justify such an implementation? Or in other words, what theorem justifies this implementation? State the theorem as precisely as you can.

Hint: you must consider just how the logical formulation of the type system is going to be converted into an algorithm; with mutation in the picture, order is going to matter.

If C =_S D is performed before C' =_S' D, then S' = R.S for some R. By "before" we mean the in terms of the order of traversal of the syntax tree.

Ideas

What are the good ideas in this paper?

Implementation

What do you think of the trick embodied by the Expected type on page 50? (Before answering, you might revisit the example at the bottom of page 52).

How difficult would you find it to adapt Figure 10 to your own compiler?

How difficult would you find it to extend this system with constructor classes?

BibTeX

@Misc{Simon-Peyton-Jones-and-Dimitrios-Vytiniotis-and-Stephanie-Weirich-and-Mark-Shields2004
  , title      = "Practical type inference for arbitrary-rank types"
  , url        = "citeseer.ist.psu.edu/article/jones04practical.html"
  , author     = "Simon Peyton Jones and Dimitrios Vytiniotis and Stephanie Weirich and Mark Shields"
  , year       = "2004"
  , text       = "Under consideration for publication in J. Functional Programming"
  }