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


I know some of you have been having difficulty with your projects, so I thought last night I'd sit down and tackle an A-normalizer for the language we discussed in class Monday. What follows are some notes that may help you.

If you recall, in class we had something like the following:

  data Val = Unit | Pair Val Val | Inl Val | Inr Val | Var Name

  data ANF = Return Name                  
           | Consume Name
           | Send Name Val ANF             
           | Send2 Name Val Name Val ANF     
           | Split Name Name Name ANF         
           | Use1 Name Name Name ANF        
           | Use2 Name Name Name Name ANF      
           | Case Name (Name, ANF) (Name, ANF)

For reasons that may become clear below I've elected to call this type ANF rather than the M we used in class. Also, because I haven't implemented any support for typing, I used an untyped form here. You would be wise to use a typed form, where the alternatives in the case construct are suitable labelled, e.g., Case Name (Name, Ty, ANF) (Name, Ty ANF).

As noted, a Name corresponds to a wire and an ANF (the new M form) corresponds to a circuit. The Case construct is unique in that it connects to two, distinct downstream circuits, and on any execution, at most one of those circuits is activated. Both the Split and the Send2 have multiple output wires but those wires feed into a single circuit.

Now by itself this datatype is useless, because any value of this type is already A-normalized. (I will continue to talk about A-normalization and A-normal form although this is obviously a different language.) So you also need a source language. What does it need?