<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="robots" content="index,nofollow">



<title>XML - MLton Standard ML Compiler (SML Compiler)</title>
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="all" href="common.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="screen" href="screen.css">
<link rel="stylesheet" type="text/css" charset="iso-8859-1" media="print" href="print.css">


<link rel="Start" href="Home">


</head>

<body lang="en" dir="ltr">

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-833377-1";
urchinTracker();
</script>
<table bgcolor = lightblue cellspacing = 0 style = "border: 0px;" width = 100%>
  <tr>
    <td style = "
		border: 0px;
		color: darkblue; 
		font-size: 150%;
		text-align: left;">
      <a class = mltona href="Home">MLton MLTONWIKIVERSION</a>
    <td style = "
		border: 0px;
		font-size: 150%;
		text-align: center;
		width: 50%;">
      XML
    <td style = "
		border: 0px;
		text-align: right;">
      <table cellspacing = 0 style = "border: 0px">
        <tr style = "vertical-align: middle;">
      </table>
  <tr style = "background-color: white;">
    <td colspan = 3
	style = "
		border: 0px;
		font-size:70%;
		text-align: right;">
      <a href = "Home">Home</a>
      &nbsp;<a href = "Index">Index</a>
      &nbsp;
</table>
<div id="content" lang="en" dir="ltr">
XML is an <a href="IntermediateLanguage">IntermediateLanguage</a>,  translated from <a href="CoreML">CoreML</a> by <a href="Defunctorize">Defunctorize</a>,  optimized by <a href="XMLSimplify">XMLSimplify</a>, and  translated by <a href="Monomorphise">Monomorphise</a> to <a href="SXML">SXML</a>. <h2 id="head-55f8ebc805e65b5b71ddafdae390e3be2bcd69af">Description</h2>
<p>
XML is polymorphic, higher-order, with flat patterns.  Every XML expression is annotated with its type.  Polymorphic generalization is made explicit through type variables annotating <tt>val</tt> and <tt>fun</tt> declarations.  Polymorphic instantiation is made explicit by specifying type arguments at variable references. XML patterns can not be nested and can not contain wildcards, constraints, flexible records, or layering. 
</p>
<h2 id="head-8781d615fd77be9578225c40ac67b9471394cced">Implementation</h2>
<a href = "http://mlton.org/cgi-bin/viewsvn.cgi/mlton/tags/on-MLTONWIKIVERSION-release/mlton/xml/xml.sig?view=markup"><img src="moin-www.png" alt="[WWW]" height="11" width="11">xml.sig</a> <a href = "http://mlton.org/cgi-bin/viewsvn.cgi/mlton/tags/on-MLTONWIKIVERSION-release/mlton/xml/xml.fun?view=markup"><img src="moin-www.png" alt="[WWW]" height="11" width="11">xml.fun</a><br>
 <a href = "http://mlton.org/cgi-bin/viewsvn.cgi/mlton/tags/on-MLTONWIKIVERSION-release/mlton/xml/xml-tree.sig?view=markup"><img src="moin-www.png" alt="[WWW]" height="11" width="11">xml-tree.sig</a> <a href = "http://mlton.org/cgi-bin/viewsvn.cgi/mlton/tags/on-MLTONWIKIVERSION-release/mlton/xml/xml-tree.fun?view=markup"><img src="moin-www.png" alt="[WWW]" height="11" width="11">xml-tree.fun</a> <h2 id="head-a6de4b535fedeaa8890bd890b60fe09f87b5f96a">Type Checking</h2>
<p>
XML also has a type checker, used for debugging.  At present, the type checker is also the best specification of the type system of XML.  If you need more details, the type checker (<a href = "http://mlton.org/cgi-bin/viewsvn.cgi/mlton/tags/on-MLTONWIKIVERSION-release/mlton/xml/type-check.sig?view=markup"><img src="moin-www.png" alt="[WWW]" height="11" width="11">type-check.sig</a>,<a href = "http://mlton.org/cgi-bin/viewsvn.cgi/mlton/tags/on-MLTONWIKIVERSION-release/mlton/xml/type-check.fun?view=markup"><img src="moin-www.png" alt="[WWW]" height="11" width="11">type-check.fun</a>), is pretty short. 
</p>
<p>
Since the type checker does not affect the output of the compiler (unless it reports an error), it can be turned off.  The type checker recursively descends the program, checking that the type annotating each node is the same as the type synthesized from the types of the expressions subnodes. 
</p>
<h2 id="head-35ec00231a68203708e39f0e2cc10b50c6bf62de">Details and Notes</h2>
<p>
XML uses the same atoms as Core ML, hence all identifiers (constructors, variables, etc.) are unique and can have properties attached to them.  Finally, XML has a simplifier (<a href="XMLShrink">XMLShrink</a>), which implements a reduction system. 
</p>
<h4 id="head-93b9e289e2842469d001eccf7ad5d79f3c302dc9">Types</h4>
<p>
XML types are either type variables or applications of n-ary type constructors.  There are many utility functions for constructing and destructing types involving built-in type constructors. 
</p>
<p>
A type scheme binds list of type variables in a type.  The only interesting operation on type schemes is the application of a type scheme to a list of types, which performs a simultaneous substitution of the type arguments for the bound type variables of the scheme.  For the purposes of type checking, it is necessary to know the type scheme of variables, constructors, and primitives.  This is done by associating the scheme with the identifier using its property list. This approach is used instead of the more traditional environment approach for reasons of speed. 
</p>
<h4 id="head-a7be579adae76065044668534f763ced06dbf2b3">XmlTree</h4>
<p>
Before defining <tt>XML</tt>, the signature for language XML, we need to define an auxiliary signature <tt>XML_TREE</tt>, that contains the datatype declarations for the expression trees of XML.  This is done solely for the purpose of modularity -- it allows the simplifier and type checker to be defined by separate functors (which take a structure matching <tt>XML_TREE</tt>).  Then, <tt>Xml</tt> is defined as the signature for a module containing the expression trees, the simplifier, and the type checker. 
</p>
<p>
Both constructors and variables can have type schemes, hence both constructor and variable references specify the instance of the scheme at the point of references.  An instance is specified with a vector of types, which corresponds to the type variables in the scheme. 
</p>
<p>
XML patterns are flat (i.e. not nested).  A pattern is a constructor with an optional argument variable.  Patterns only occur in <tt>case</tt> expressions.  To evaluate a case expression, compare the test value sequentially against each pattern.  For the first pattern that matches, destruct the value if necessary to bind the pattern variables and evaluate the corresponding expression.  If no pattern matches, evaluate the default.  All patterns of a case statement are of the same variant of <tt>Pat.t</tt>, although this is not enforced by ML's type system.  The type checker, however, does enforce this.  Because tuple patterns are irrefutable, there will only ever be one tuple pattern in a case expression and there will be no default. 
</p>
<p>
XML contains value, exception, and mutually recursive function declarations.  There are no free type variables in XML.  All type variables are explicitly bound at either a value or function declaration.  At some point in the future, exception declarations may go away, and exceptions may be represented with a single datatype containing a <tt>unit&nbsp;ref</tt> component to implement genericity. 
</p>
<p>
XML expressions are like those of <a href="CoreML">CoreML</a>, with the following exceptions.  There are no records expressions.  After type inference, all records (some of which may have originally been tuples in the source) are converted to tuples, because once flexible record patterns have been resolved, tuple labels are superfluous.  Tuple components are ordered based on the field ordering relation.  XML eta expands primitives and constructors so that there are always fully applied. Hence, the only kind of value of arrow type is a lambda.  This property is useful for flow analysis and later in code generation. 
</p>
<p>
An XML program is a list of toplevel datatype declarations and a body expression.  Because datatype declarations are not generative, the defunctorizer can safely move them to toplevel. 
</p>
</div>



<p>
<hr>
Last edited on 2006-11-02 17:35:47 by <span title="76.16.241.4"><a href="MatthewFluet">MatthewFluet</a></span>.
</body></html>
