Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
infixl 6 +<br />
infixl 7 *<br />
f = 1 + 2 * 3<br />
Renamer<br />
After parsing we will traverse the entire AST and rename all user-named variables to machine generated<br />
names and eliminate any name-shadowing. For example in the following ambiguous binder will replace<br />
the duplicate occurrence of x with a fresh name.<br />
f x y = \g x -> x + y<br />
f x y = \g a0 -> a0 + y<br />
-- x in definition of g shadows x in f<br />
We will also devise a general method of generating fresh names for each pass such that the names generated<br />
are uniquely identifiable to that pass and cannot conflict with later passes.<br />
Ensuring that all names are unique in the syntax tree will allow us more safety later on during program<br />
transformation, to know that names cannot implicitly capture and the program can be transformed<br />
without changing its meaning.<br />
Datatypes<br />
User defined data declarations need to be handled and added to the typing context so that their use<br />
throughout the program logic can be typechecked. is will also lead us into the construction of a<br />
simple kind inference system, and the support of higher-kinded types.<br />
data Bool = False | True<br />
data Maybe a = Nothing | Just a<br />
data T1 f a = T1 (f a)<br />
Each constructor definition will also introduce several constructor functions into the Core representation<br />
of the module. Record types will also be supported and will expand out into selectors for each of the<br />
various fields.<br />
Desugaring<br />
Pattern matching is an extremely important part of a modern functional programming, but the implementation<br />
of the pattern desugaring is remarkably subtle. e frontend syntax allows the expression of<br />
nested pattern matches and incomplete patterns, both can generate very complex splitting trees of case<br />
expressions that need to be expanded out recursively. We will use the algorithm devised Phil Wadler to<br />
perform this transformation.<br />
Multiple Equations<br />
111