<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.8">
<title>SyntacticConventions</title>
<link rel="stylesheet" href="./asciidoc.css" type="text/css">
<link rel="stylesheet" href="./pygments.css" type="text/css">


<script type="text/javascript" src="./asciidoc.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install(2);
/*]]>*/
</script>
<link rel="stylesheet" href="./mlton.css" type="text/css"/>
</head>
<body class="article">
<div id="banner">
<div id="banner-home">
<a href="./Home">MLton 20130715</a>
</div>
</div>
<div id="header">
<h1>SyntacticConventions</h1>
<div id="toc">
  <div id="toctitle">Table of Contents</div>
  <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>Here are a number of syntactic conventions useful for programming in
SML.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_general">General</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
A line of code never exceeds 80 columns.
</p>
</li>
<li>
<p>
Only split a syntactic entity across multiple lines if it doesn&#8217;t fit on one line within 80 columns.
</p>
</li>
<li>
<p>
Use alphabetical order wherever possible.
</p>
</li>
<li>
<p>
Avoid redundant parentheses.
</p>
</li>
<li>
<p>
When using <span class="monospaced">:</span>, there is no space before the colon, and a single space after it.
</p>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_identifiers">Identifiers</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
Variables, record labels and type constructors begin with and use
small letters, using capital letters to separate words.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">cost</span><span class="w"></span>
<span class="n">maxValue</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Variables that represent collections of objects (lists, arrays,
vectors, &#8230;) are often suffixed with an <span class="monospaced">s</span>.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">xs</span><span class="w"></span>
<span class="n">employees</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Constructors, structure identifiers, and functor identifiers begin
with a capital letter.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">Queue</span><span class="w"></span>
<span class="n">LinkedList</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Signature identifiers are in all capitals, using <span class="monospaced">_</span> to separate
words.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">LIST</span><span class="w"></span>
<span class="n">BINARY_HEAP</span><span class="w"></span>
</pre></div></div></div>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_types">Types</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
Alphabetize record labels.  In a record type, there are spaces after
colons and commas, but not before colons or commas, or at the
delimiters <span class="monospaced">{</span> and <span class="monospaced">}</span>.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">{</span><span class="n">bar</span><span class="p">:</span><span class="w"> </span><span class="n">int</span><span class="p">,</span><span class="w"> </span><span class="n">foo</span><span class="p">:</span><span class="w"> </span><span class="n">int</span><span class="p">}</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Only split a record type across multiple lines if it doesn&#8217;t fit on
one line. If a record type must be split over multiple lines, put one
field per line.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">{</span><span class="n">bar</span><span class="p">:</span><span class="w"> </span><span class="n">int</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="n">foo</span><span class="p">:</span><span class="w"> </span><span class="n">real</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">real</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="n">zoo</span><span class="p">:</span><span class="w"> </span><span class="n">bool</span><span class="p">}</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
In a tuple type, there are spaces before and after each <span class="monospaced">*</span>.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">int</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">bool</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">real</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Only split a tuple type across multiple lines if it doesn&#8217;t fit on
one line.  In a tuple type split over multiple lines, there is one
type per line, and the <span class="monospaced">*</span>-s go at the beginning of the lines.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">int</span><span class="w"></span>
<span class="n">*</span><span class="w"> </span><span class="n">bool</span><span class="w"></span>
<span class="n">*</span><span class="w"> </span><span class="n">real</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>It may also be useful to parenthesize to make the grouping more
apparent.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="n">int</span><span class="w"></span>
<span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">bool</span><span class="w"></span>
<span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">real</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
In an arrow type split over multiple lines, put the arrow at the
beginning of its line.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">int</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">real</span><span class="w"></span>
<span class="p">-&gt;</span><span class="w"> </span><span class="n">bool</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>It may also be useful to parenthesize to make the grouping more
apparent.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="n">int</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">real</span><span class="w"></span>
<span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">bool</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Avoid redundant parentheses.
</p>
</li>
<li>
<p>
Arrow types associate to the right, so write
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">a</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">c</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>not</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">a</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="p">(</span><span class="n">b</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">c</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Type constructor application associates to the left, so write
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">int</span><span class="w"> </span><span class="n">ref</span><span class="w"> </span><span class="n">list</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>not</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="n">int</span><span class="w"> </span><span class="n">ref</span><span class="p">)</span><span class="w"> </span><span class="n">list</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Type constructor application binds more tightly than a tuple type,
so write
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">int</span><span class="w"> </span><span class="n">list</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">bool</span><span class="w"> </span><span class="n">list</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>not</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="n">int</span><span class="w"> </span><span class="n">list</span><span class="p">)</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="p">(</span><span class="n">bool</span><span class="w"> </span><span class="n">list</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Tuple types bind more tightly than arrow types, so write
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">int</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">bool</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">real</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>not</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="n">int</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">bool</span><span class="p">)</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">real</span><span class="w"></span>
</pre></div></div></div>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_core">Core</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
A core expression or declaration split over multiple lines does not
contain any blank lines.
</p>
</li>
<li>
<p>
A record field selector has no space between the <span class="monospaced">#</span> and the record
label.  So, write
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">#</span><span class="n">foo</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>not</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">#</span><span class="w"> </span><span class="n">foo</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A tuple has a space after each comma, but not before, and not at the
delimiters <span class="monospaced">(</span> and <span class="monospaced">)</span>.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="n">e1</span><span class="p">,</span><span class="w"> </span><span class="n">e2</span><span class="p">,</span><span class="w"> </span><span class="n">e3</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A tuple split over multiple lines has one element per line, and the
commas go at the end of the lines.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="n">e1</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="n">e2</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="n">e3</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A list has a space after each comma, but not before, and not at the
delimiters <span class="monospaced">[</span> and <span class="monospaced">]</span>.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">[</span><span class="n">e1</span><span class="p">,</span><span class="w"> </span><span class="n">e2</span><span class="p">,</span><span class="w"> </span><span class="n">e3</span><span class="p">]</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A list split over multiple lines has one element per line, and the
commas at the end of the lines.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">[</span><span class="n">e1</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="n">e2</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="n">e3</span><span class="p">]</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A record has spaces before and after <span class="monospaced">=</span>, a space after each comma,
but not before, and not at the delimiters <span class="monospaced">{</span> and <span class="monospaced">}</span>.  Field names
appear in alphabetical order.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">{</span><span class="n">bar</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="mi">13</span><span class="p">,</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">true</span><span class="p">}</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A sequence expression has a space after each semicolon, but not before.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="n">e1</span><span class="p">;</span><span class="w"> </span><span class="n">e2</span><span class="p">;</span><span class="w"> </span><span class="n">e3</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A sequence expression split over multiple lines has one expression
per line, and the semicolons at the beginning of lines.  Lisp and
Scheme programmers may find this hard to read at first.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">(</span><span class="n">e1</span><span class="w"></span>
<span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
<span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="n">e3</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p><em>Rationale</em>: this makes it easy to visually spot the beginning of each
expression, which becomes more valuable as the expressions themselves
are split across multiple lines.</p></div>
</li>
<li>
<p>
An application expression has a space between the function and the
argument.  There are no parens unless the argument is a tuple (in
which case the parens are really part of the tuple, not the
application).
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">f</span><span class="w"> </span><span class="n">a</span><span class="w"></span>
<span class="n">f</span><span class="w"> </span><span class="p">(</span><span class="n">a1</span><span class="p">,</span><span class="w"> </span><span class="n">a2</span><span class="p">,</span><span class="w"> </span><span class="n">a3</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Avoid redundant parentheses.  Application associates to left, so
write
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">f</span><span class="w"> </span><span class="n">a1</span><span class="w"> </span><span class="n">a2</span><span class="w"> </span><span class="n">a3</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>not</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="p">((</span><span class="n">f</span><span class="w"> </span><span class="n">a1</span><span class="p">)</span><span class="w"> </span><span class="n">a2</span><span class="p">)</span><span class="w"> </span><span class="n">a3</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Infix operators have a space before and after the operator.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">x</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="n">y</span><span class="w"></span>
<span class="n">x</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="n">-</span><span class="w"> </span><span class="n">z</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Avoid redundant parentheses.  Use <a href="OperatorPrecedence">OperatorPrecedence</a>.  So, write
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">x</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">z</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>not</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">x</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="p">(</span><span class="n">y</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">z</span><span class="p">)</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
An <span class="monospaced">andalso</span> expression split over multiple lines has the <span class="monospaced">andalso</span>
at the beginning of subsequent lines.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">e1</span><span class="w"></span>
<span class="k">andalso</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
<span class="k">andalso</span><span class="w"> </span><span class="n">e3</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A <span class="monospaced">case</span> expression is indented as follows
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">case</span><span class="w"> </span><span class="n">e1</span><span class="w"> </span><span class="k">of</span><span class="w"></span>
<span class="w">   </span><span class="n">p1</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">e1</span><span class="w"></span>
<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="n">p2</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="n">p3</span><span class="w"> </span><span class="p">=&gt;</span><span class="w"> </span><span class="n">e3</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A <span class="monospaced">datatype</span>'s constructors are alphabetized.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">datatype</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="n">C</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A <span class="monospaced">datatype</span> declaration has a space before and after each <span class="monospaced">|</span>.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">datatype</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="k">of</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="n">C</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A <span class="monospaced">datatype</span> split over multiple lines has one constructor per line,
with the <span class="monospaced">|</span> at the beginning of lines and the constructors beginning
3 columns to the right of the <span class="monospaced">datatype</span>.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">datatype</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="n">A</span><span class="w"></span>
<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="n">B</span><span class="w"></span>
<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="n">C</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A <span class="monospaced">fun</span> declaration may start its body on the subsequent line,
indented 3 spaces.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">fun</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">let</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="n">z</span><span class="w"></span>
<span class="w">   </span><span class="k">in</span><span class="w"></span>
<span class="w">      </span><span class="n">z</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
An <span class="monospaced">if</span> expression is indented as follows.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">if</span><span class="w"> </span><span class="n">e1</span><span class="w"></span>
<span class="w">   </span><span class="k">then</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
<span class="k">else</span><span class="w"> </span><span class="n">e3</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A sequence of <span class="monospaced">if</span>-<span class="monospaced">then</span>-<span class="monospaced">else</span>-s is indented as follows.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">if</span><span class="w"> </span><span class="n">e1</span><span class="w"></span>
<span class="w">   </span><span class="k">then</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
<span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">e3</span><span class="w"></span>
<span class="w">   </span><span class="k">then</span><span class="w"> </span><span class="n">e4</span><span class="w"></span>
<span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">e5</span><span class="w"></span>
<span class="w">   </span><span class="k">then</span><span class="w"> </span><span class="n">e6</span><span class="w"></span>
<span class="k">else</span><span class="w"> </span><span class="n">e7</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A <span class="monospaced">let</span> expression has the <span class="monospaced">let</span>, <span class="monospaced">in</span>, and <span class="monospaced">end</span> on their own
lines, starting in the same column.  Declarations and the body are
indented 3 spaces.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">let</span><span class="w"></span>
<span class="w">   </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="mi">13</span><span class="w"></span>
<span class="w">   </span><span class="k">val</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="mi">14</span><span class="w"></span>
<span class="k">in</span><span class="w"></span>
<span class="w">   </span><span class="n">x</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="n">y</span><span class="w"></span>
<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A <span class="monospaced">local</span> declaration has the <span class="monospaced">local</span>, <span class="monospaced">in</span>, and <span class="monospaced">end</span> on their own
lines, starting in the same column.  Declarations are indented 3
spaces.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">local</span><span class="w"></span>
<span class="w">   </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="mi">13</span><span class="w"></span>
<span class="k">in</span><span class="w"></span>
<span class="w">   </span><span class="k">val</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">x</span><span class="w"></span>
<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
An <span class="monospaced">orelse</span> expression split over multiple lines has the <span class="monospaced">orelse</span> at
the beginning of subsequent lines.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="n">e1</span><span class="w"></span>
<span class="k">orelse</span><span class="w"> </span><span class="n">e2</span><span class="w"></span>
<span class="k">orelse</span><span class="w"> </span><span class="n">e3</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A <span class="monospaced">val</span> declaration has a space before and after the <span class="monospaced">=</span>.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">val</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">e</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A <span class="monospaced">val</span> declaration can start the expression on the subsequent line,
indented 3 spaces.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">val</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">if</span><span class="w"> </span><span class="n">e1</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="n">e2</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="n">e3</span><span class="w"></span>
</pre></div></div></div>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_signatures">Signatures</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
A <span class="monospaced">signature</span> declaration is indented as follows.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">signature</span><span class="w"> </span><span class="n">FOO</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="p">:</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p><em>Exception</em>: a signature declaration in a file to itself can omit the
indentation to save horizontal space.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">signature</span><span class="w"> </span><span class="n">FOO</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="k">sig</span><span class="w"></span>

<span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="p">:</span><span class="w"> </span><span class="n">int</span><span class="w"></span>

<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>In this case, there should be a blank line after the <span class="monospaced">sig</span> and before
the <span class="monospaced">end</span>.</p></div>
</li>
<li>
<p>
A <span class="monospaced">val</span> specification has a space after the colon, but not before.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="p">:</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p><em>Exception</em>: in the case of operators (like <span class="monospaced">+</span>), there is a space
before the colon to avoid lexing the colon as part of the operator.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">val</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">t</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
Alphabetize specifications in signatures.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">sig</span><span class="w"></span>
<span class="w">   </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="p">:</span><span class="w"> </span><span class="n">int</span><span class="w"></span>
<span class="w">   </span><span class="k">val</span><span class="w"> </span><span class="n">y</span><span class="p">:</span><span class="w"> </span><span class="n">bool</span><span class="w"></span>
<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_structures">Structures</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
A <span class="monospaced">structure</span> declaration has a space on both sides of the <span class="monospaced">=</span>.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">structure</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">Bar</span><span class="w"></span>
</pre></div></div></div>
</li>
<li>
<p>
A <span class="monospaced">structure</span> declaration split over multiple lines is indented as
follows.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">structure</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">struct</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="mi">13</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p><em>Exception</em>: a structure declaration in a file to itself can omit the
indentation to save horizontal space.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">structure</span><span class="w"> </span><span class="n">S</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="k">struct</span><span class="w"></span>

<span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="mi">13</span><span class="w"></span>

<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>In this case, there should be a blank line after the <span class="monospaced">struct</span> and
before the <span class="monospaced">end</span>.</p></div>
</li>
<li>
<p>
Declarations in a <span class="monospaced">struct</span> are separated by blank lines.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">struct</span><span class="w"></span>
<span class="w">   </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">      </span><span class="k">let</span><span class="w"></span>
<span class="w">         </span><span class="n">y</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="mi">13</span><span class="w"></span>
<span class="w">      </span><span class="k">in</span><span class="w"></span>
<span class="w">         </span><span class="n">y</span><span class="w"> </span><span class="n">+</span><span class="w"> </span><span class="mi">1</span><span class="w"></span>
<span class="w">      </span><span class="k">end</span><span class="w"></span>

<span class="w">   </span><span class="k">val</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="mi">14</span><span class="w"></span>
<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_functors">Functors</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
A <span class="monospaced">functor</span> declaration has spaces after each <span class="monospaced">:</span> (or <span class="monospaced">:&gt;</span>) but not
before, and a space before and after the <span class="monospaced">=</span>.  It is indented as
follows.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">functor</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">(</span><span class="n">S</span><span class="p">:</span><span class="w"> </span><span class="n">FOO_ARG</span><span class="p">):</span><span class="w"> </span><span class="n">FOO</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">struct</span><span class="w"></span>
<span class="w">       </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">S</span><span class="p">.</span><span class="n">x</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p><em>Exception</em>: a functor declaration in a file to itself can omit the
indentation to save horizontal space.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">functor</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">(</span><span class="n">S</span><span class="p">:</span><span class="w"> </span><span class="n">FOO_ARG</span><span class="p">):</span><span class="w"> </span><span class="n">FOO</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="k">struct</span><span class="w"></span>

<span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="n">S</span><span class="p">.</span><span class="n">x</span><span class="w"></span>

<span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>In this case, there should be a blank line after the <span class="monospaced">struct</span>
and before the <span class="monospaced">end</span>.</p></div>
</li>
</ul></div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
</div>
<div id="footer-badges">
</div>
</div>
</body>
</html>
