Overview of the code

Code you will write or edit


Disambiguator that takes VScheme into UnambiguousVScheme. I’ve written all the boilerplate; all you have to do is translate the three ambiguous forms VAR, SET, and APPLY.


A stub that you will fill out with your internal representation of K-normal form.


A stub that you will fill out with functions that embed K-normal form into (ambiguous) VScheme.


A stub that you will fill out with functions that project UnambiguousVScheme into K-normal form.


The driver for the Universal Forward Translator, which you will extend with support for K-normal form: a reader, a materializer, an emitter, and a case for translate.

Code you will look at and understand


The referent type and referent function embody the three roles of names. Value constructor X.PRIMCALL and functions etaExpand implement the two legal uses of primitive functions. (A third use, assigning to a primitive, is an unchecked run-time error, which implies that the compiler can do as it likes. The C standard calls such things “undefined behavior.”)


Two internal representations of vScheme code: VScheme, in which the meaning of each name and action of each function call depend on context, and UnambiguousVScheme, in which the meaning of each name and action of each function call are made explicit in the syntactic form.


Information about vScheme primitive functions, which ultimately correspond to VM instructions. The type primitive is what’s used in K-normal form, and it’s abstract. There’s a lot to digest here, but you can do it gradually.

What’s important for this module are functions find and arity. You will also need to refer directly to the primitives setglobal and getglobal.

Important code you already understand


Used to manage the possibility of failure in your projection functions. And some of the combinators are used in pipelines in the UFT driver in uft.sml.


Defines function Impossible.impossible, which you’ll call when you need to signify an assertion failure, e.g., an invariant violation.

Code you may never look at

Input is read into vScheme via sxlex.sml, sx.sml, and vscheme-parse.sml.

Source code related to prettyprinting includes wpp.cm, Wpp-sig.sml, Wpp.sml, pp-sig.sml, pp.cm, prettyprinter-sig.sml, ppdyn-sig.sml, pputil-sig.sml, pp.sml, ppdyn.sml, ppnormal.sml, pptest.sml, and pputil.sml. There are a lot of files because I dragged in legacy components from two other software projects—it’s a mess I might clean up one day.