Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / mlton-guide.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
3 <?asciidoc-toc?>
4 <?asciidoc-numbered?>
5
6 <article lang="en">
7 <articleinfo>
8 <title>MLton Guide (20180207)</title>
9 </articleinfo>
10 <abstract>
11 <simpara>This is the guide for MLton, an open-source, whole-program, optimizing Standard ML compiler.</simpara>
12 <simpara>This guide was generated automatically from the MLton website, available online at <ulink url="http://mlton.org">http://mlton.org</ulink>. It is up to date for MLton 20180207.</simpara>
13 </abstract>
14 <section id="Home">
15 <title>MLton</title>
16 <section id="_what_is_mlton">
17 <title>What is MLton?</title>
18 <simpara>MLton is an open-source, whole-program, optimizing
19 <link linkend="StandardML">Standard ML</link> compiler.</simpara>
20 </section>
21 <section id="_what_8217_s_new">
22 <title>What&#8217;s new?</title>
23 <itemizedlist>
24 <listitem>
25 <simpara>
26 20180207: Please try out our latest release, <link linkend="Release20180207">MLton 20180207</link>.
27 </simpara>
28 </listitem>
29 <listitem>
30 <simpara>
31 20140730: <ulink url="http://www.cs.rit.edu/%7emtf">Matthew Fluet</ulink> and
32 <ulink url="http://www.cse.buffalo.edu/%7elziarek">Lukasz Ziarek</ulink> have been
33 awarded an <ulink url="http://www.nsf.gov/funding/pgm_summ.jsp?pims_id=12810">NSF
34 CISE Research Infrastructure (CRI)</ulink> grant titled "Positioning MLton
35 for Next-Generation Programming Languages Research;" read the award
36 abstracts
37 (<ulink url="http://www.nsf.gov/awardsearch/showAward?AWD_ID=1405770">Award&#160;#1405770</ulink>
38 and
39 <ulink url="http://www.nsf.gov/awardsearch/showAward?AWD_ID=1405614">Award&#160;#1405614</ulink>)
40 for more details.
41 </simpara>
42 </listitem>
43 </itemizedlist>
44 </section>
45 <section id="_next_steps">
46 <title>Next steps</title>
47 <itemizedlist>
48 <listitem>
49 <simpara>
50 Read about MLton&#8217;s <link linkend="Features">Features</link>.
51 </simpara>
52 </listitem>
53 <listitem>
54 <simpara>
55 Look at <link linkend="Documentation">Documentation</link>.
56 </simpara>
57 </listitem>
58 <listitem>
59 <simpara>
60 See some <link linkend="Users">Users</link> of MLton.
61 </simpara>
62 </listitem>
63 <listitem>
64 <simpara>
65 <ulink url="https://sourceforge.net/projects/mlton/files/mlton/20180207">Download</ulink> MLton.
66 </simpara>
67 </listitem>
68 <listitem>
69 <simpara>
70 Meet the MLton <link linkend="Developers">Developers</link>.
71 </simpara>
72 </listitem>
73 <listitem>
74 <simpara>
75 Get involved with MLton <link linkend="Development">Development</link>.
76 </simpara>
77 </listitem>
78 <listitem>
79 <simpara>
80 User-maintained <link linkend="FAQ">FAQ</link>.
81 </simpara>
82 </listitem>
83 <listitem>
84 <simpara>
85 <link linkend="Contact">Contact</link> us.
86 </simpara>
87 </listitem>
88 </itemizedlist>
89 <simpara><?asciidoc-pagebreak?></simpara>
90 </section>
91 </section>
92 <section id="AdamGoode">
93 <title>AdamGoode</title>
94 <itemizedlist>
95 <listitem>
96 <simpara>
97 I maintain the Fedora package of MLton, in <ulink url="https://admin.fedoraproject.org/pkgdb/packages/name/mlton">Fedora</ulink>.
98 </simpara>
99 </listitem>
100 <listitem>
101 <simpara>
102 I have contributed some patches for Makefiles and PDF documentation building.
103 </simpara>
104 </listitem>
105 </itemizedlist>
106 <simpara><?asciidoc-pagebreak?></simpara>
107 </section>
108 <section id="AdmitsEquality">
109 <title>AdmitsEquality</title>
110 <simpara>A <link linkend="TypeConstructor">TypeConstructor</link> admits equality if whenever it is applied to
111 equality types, the result is an <link linkend="EqualityType">EqualityType</link>. This notion enables
112 one to determine whether a type constructor application yields an
113 equality type solely from the application, without looking at the
114 definition of the type constructor. It helps to ensure that
115 <link linkend="PolymorphicEquality">PolymorphicEquality</link> is only applied to sensible values.</simpara>
116 <simpara>The definition of admits equality depends on whether the type
117 constructor was declared by a <literal>type</literal> definition or a
118 <literal>datatype</literal> declaration.</simpara>
119 <section id="_type_definitions">
120 <title>Type definitions</title>
121 <simpara>For type definition</simpara>
122 <programlisting language="sml" linenumbering="unnumbered">type ('a1, ..., 'an) t = ...</programlisting>
123 <simpara>type constructor <literal>t</literal> admits equality if the right-hand side of the
124 definition is an equality type after replacing <literal>'a1</literal>, &#8230;,
125 <literal>'an</literal> by equality types (it doesn&#8217;t matter which equality types
126 are chosen).</simpara>
127 <simpara>For a nullary type definition, this amounts to the right-hand side
128 being an equality type. For example, after the definition</simpara>
129 <programlisting language="sml" linenumbering="unnumbered">type t = bool * int</programlisting>
130 <simpara>type constructor <literal>t</literal> admits equality because <literal>bool * int</literal> is
131 an equality type. On the other hand, after the definition</simpara>
132 <programlisting language="sml" linenumbering="unnumbered">type t = bool * int * real</programlisting>
133 <simpara>type constructor <literal>t</literal> does not admit equality, because <literal>real</literal>
134 is not an equality type.</simpara>
135 <simpara>For another example, after the definition</simpara>
136 <programlisting language="sml" linenumbering="unnumbered">type 'a t = bool * 'a</programlisting>
137 <simpara>type constructor <literal>t</literal> admits equality because <literal>bool * int</literal>
138 is an equality type (we could have chosen any equality type other than
139 <literal>int</literal>).</simpara>
140 <simpara>On the other hand, after the definition</simpara>
141 <programlisting language="sml" linenumbering="unnumbered">type 'a t = real * 'a</programlisting>
142 <simpara>type constructor <literal>t</literal> does not admit equality because
143 <literal>real * int</literal> is not equality type.</simpara>
144 <simpara>We can check that a type constructor admits equality using an
145 <literal>eqtype</literal> specification.</simpara>
146 <programlisting language="sml" linenumbering="unnumbered">structure Ok: sig eqtype 'a t end =
147 struct
148 type 'a t = bool * 'a
149 end</programlisting>
150 <programlisting language="sml" linenumbering="unnumbered">structure Bad: sig eqtype 'a t end =
151 struct
152 type 'a t = real * int * 'a
153 end</programlisting>
154 <simpara>On <literal>structure Bad</literal>, MLton reports the following error.</simpara>
155 <screen>Error: z.sml 1.16-1.34.
156 Type in structure disagrees with signature (admits equality): t.
157 structure: type 'a t = [real] * _ * _
158 defn at: z.sml 3.15-3.15
159 signature: [eqtype] 'a t
160 spec at: z.sml 1.30-1.30</screen>
161 <simpara>The <literal>structure:</literal> section provides an explanation of why the type
162 did not admit equality, highlighting the problematic component
163 (<literal>real</literal>).</simpara>
164 </section>
165 <section id="_datatype_declarations">
166 <title>Datatype declarations</title>
167 <simpara>For a type constructor declared by a datatype declaration to admit
168 equality, every <link linkend="Variant">variant</link> of the datatype must admit equality. For
169 example, the following datatype admits equality because <literal>bool</literal> and
170 <literal>char * int</literal> are equality types.</simpara>
171 <programlisting language="sml" linenumbering="unnumbered">datatype t = A of bool | B of char * int</programlisting>
172 <simpara>Nullary constructors trivially admit equality, so that the following
173 datatype admits equality.</simpara>
174 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B | C</programlisting>
175 <simpara>For a parameterized datatype constructor to admit equality, we
176 consider each <link linkend="Variant">variant</link> as a type definition, and require that the
177 definition admit equality. For example, for the datatype</simpara>
178 <programlisting language="sml" linenumbering="unnumbered">datatype 'a t = A of bool * 'a | B of 'a</programlisting>
179 <simpara>the type definitions</simpara>
180 <programlisting language="sml" linenumbering="unnumbered">type 'a tA = bool * 'a
181 type 'a tB = 'a</programlisting>
182 <simpara>both admit equality. Thus, type constructor <literal>t</literal> admits equality.</simpara>
183 <simpara>On the other hand, the following datatype does not admit equality.</simpara>
184 <programlisting language="sml" linenumbering="unnumbered">datatype 'a t = A of bool * 'a | B of real * 'a</programlisting>
185 <simpara>As with type definitions, we can check using an <literal>eqtype</literal>
186 specification.</simpara>
187 <programlisting language="sml" linenumbering="unnumbered">structure Bad: sig eqtype 'a t end =
188 struct
189 datatype 'a t = A of bool * 'a | B of real * 'a
190 end</programlisting>
191 <simpara>MLton reports the following error.</simpara>
192 <screen>Error: z.sml 1.16-1.34.
193 Type in structure disagrees with signature (admits equality): t.
194 structure: datatype 'a t = B of [real] * _ | ...
195 defn at: z.sml 3.19-3.19
196 signature: [eqtype] 'a t
197 spec at: z.sml 1.30-1.30</screen>
198 <simpara>MLton indicates the problematic constructor (<literal>B</literal>), as well as
199 the problematic component of the constructor&#8217;s argument.</simpara>
200 <section id="_recursive_datatypes">
201 <title>Recursive datatypes</title>
202 <simpara>A recursive datatype like</simpara>
203 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B of int * t</programlisting>
204 <simpara>introduces a new problem, since in order to decide whether <literal>t</literal>
205 admits equality, we need to know for the <literal>B</literal> <link linkend="Variant">variant</link> whether
206 <literal>t</literal> admits equality. The <link linkend="DefinitionOfStandardML">Definition</link>
207 answers this question by requiring a type constructor to admit
208 equality if it is consistent to do so. So, in our above example, if
209 we assume that <literal>t</literal> admits equality, then the <link linkend="Variant">variant</link>
210 <literal>B of int * t</literal> admits equality. Then, since the <literal>A</literal> <link linkend="Variant">variant</link>
211 trivially admits equality, so does the type constructor <literal>t</literal>.
212 Thus, it was consistent to assume that <literal>t</literal> admits equality, and
213 so, <literal>t</literal> does admit equality.</simpara>
214 <simpara>On the other hand, in the following declaration</simpara>
215 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B of real * t</programlisting>
216 <simpara>if we assume that <literal>t</literal> admits equality, then the <literal>B</literal> <link linkend="Variant">variant</link>
217 does not admit equality. Hence, the type constructor <literal>t</literal> does not
218 admit equality, and our assumption was inconsistent. Hence, <literal>t</literal>
219 does not admit equality.</simpara>
220 <simpara>The same kind of reasoning applies to mutually recursive datatypes as
221 well. For example, the following defines both <literal>t</literal> and <literal>u</literal> to
222 admit equality.</simpara>
223 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B of u
224 and u = C | D of t</programlisting>
225 <simpara>But the following defines neither <literal>t</literal> nor <literal>u</literal> to admit
226 equality.</simpara>
227 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B of u * real
228 and u = C | D of t</programlisting>
229 <simpara>As always, we can check whether a type admits equality using an
230 <literal>eqtype</literal> specification.</simpara>
231 <programlisting language="sml" linenumbering="unnumbered">structure Bad: sig eqtype t eqtype u end =
232 struct
233 datatype t = A | B of u * real
234 and u = C | D of t
235 end</programlisting>
236 <simpara>MLton reports the following error.</simpara>
237 <screen>Error: z.sml 1.16-1.40.
238 Type in structure disagrees with signature (admits equality): t.
239 structure: datatype t = B of [_str.u] * [real] | ...
240 defn at: z.sml 3.16-3.16
241 signature: [eqtype] t
242 spec at: z.sml 1.27-1.27
243 Error: z.sml 1.16-1.40.
244 Type in structure disagrees with signature (admits equality): u.
245 structure: datatype u = D of [_str.t] | ...
246 defn at: z.sml 4.11-4.11
247 signature: [eqtype] u
248 spec at: z.sml 1.36-1.36</screen>
249 <simpara><?asciidoc-pagebreak?></simpara>
250 </section>
251 </section>
252 </section>
253 <section id="Alice">
254 <title>Alice</title>
255 <simpara><ulink url="http://www.ps.uni-saarland.de/alice">Alice ML</ulink> is an extension of SML with
256 concurrency, dynamic typing, components, distribution, and constraint
257 solving.</simpara>
258 <simpara><?asciidoc-pagebreak?></simpara>
259 </section>
260 <section id="AllocateRegisters">
261 <title>AllocateRegisters</title>
262 <simpara><link linkend="AllocateRegisters">AllocateRegisters</link> is an analysis pass for the <link linkend="RSSA">RSSA</link>
263 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="ToMachine">ToMachine</link>.</simpara>
264 <section id="_description">
265 <title>Description</title>
266 <simpara>Computes an allocation of <link linkend="RSSA">RSSA</link> variables as <link linkend="Machine">Machine</link> register
267 or stack operands.</simpara>
268 </section>
269 <section id="_implementation">
270 <title>Implementation</title>
271 <itemizedlist>
272 <listitem>
273 <simpara>
274 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/allocate-registers.sig"><literal>allocate-registers.sig</literal></ulink>
275 </simpara>
276 </listitem>
277 <listitem>
278 <simpara>
279 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/allocate-registers.fun"><literal>allocate-registers.fun</literal></ulink>
280 </simpara>
281 </listitem>
282 </itemizedlist>
283 </section>
284 <section id="_details_and_notes">
285 <title>Details and Notes</title>
286 <simpara></simpara>
287 <simpara><?asciidoc-pagebreak?></simpara>
288 </section>
289 </section>
290 <section id="AndreiFormiga">
291 <title>AndreiFormiga</title>
292 <simpara>I&#8217;m a graduate student just back in academia. I study concurrent and parallel systems, with a great deal of interest in programming languages (theory, design, implementation). I happen to like functional languages.</simpara>
293 <simpara>I use the nickname tautologico on #sml and my email is andrei DOT formiga AT gmail DOT com.</simpara>
294 <simpara><?asciidoc-pagebreak?></simpara>
295 </section>
296 <section id="ArrayLiteral">
297 <title>ArrayLiteral</title>
298 <simpara><link linkend="StandardML">Standard ML</link> does not have a syntax for array literals or
299 vector literals. The only way to write down an array is like</simpara>
300 <programlisting language="sml" linenumbering="unnumbered">Array.fromList [w, x, y, z]</programlisting>
301 <simpara>No SML compiler produces efficient code for the above expression. The
302 generated code allocates a list and then converts it to an array. To
303 alleviate this, one could write down the same array using
304 <literal>Array.tabulate</literal>, or even using <literal>Array.array</literal> and <literal>Array.update</literal>, but
305 that is syntactically unwieldy.</simpara>
306 <simpara>Fortunately, using <link linkend="Fold">Fold</link>, it is possible to define constants <literal>A</literal>,
307 and <literal>&grave;</literal> so that one can write down an array like:</simpara>
308 <programlisting language="sml" linenumbering="unnumbered">A `w `x `y `z $</programlisting>
309 <simpara>This is as syntactically concise as the <literal>fromList</literal> expression.
310 Furthermore, MLton, at least, will generate the efficient code as if
311 one had written down a use of <literal>Array.array</literal> followed by four uses of
312 <literal>Array.update</literal>.</simpara>
313 <simpara>Along with <literal>A</literal> and <literal>&grave;</literal>, one can define a constant <literal>V</literal> that makes
314 it possible to define vector literals with the same syntax, e.g.,</simpara>
315 <programlisting language="sml" linenumbering="unnumbered">V `w `x `y `z $</programlisting>
316 <simpara>Note that the same element indicator, <literal>&grave;</literal>, serves for both array
317 and vector literals. Of course, the <literal>$</literal> is the end-of-arguments
318 marker always used with <link linkend="Fold">Fold</link>. The only difference between an
319 array literal and vector literal is the <literal>A</literal> or <literal>V</literal> at the beginning.</simpara>
320 <simpara>Here is the implementation of <literal>A</literal>, <literal>V</literal>, and <literal>&grave;</literal>. We place them
321 in a structure and use signature abstraction to hide the type of the
322 accumulator. See <link linkend="Fold">Fold</link> for more on this technique.</simpara>
323 <programlisting language="sml" linenumbering="unnumbered">structure Literal:&gt;
324 sig
325 type 'a z
326 val A: ('a z, 'a z, 'a array, 'd) Fold.t
327 val V: ('a z, 'a z, 'a vector, 'd) Fold.t
328 val ` : ('a, 'a z, 'a z, 'b, 'c, 'd) Fold.step1
329 end =
330 struct
331 type 'a z = int * 'a option * ('a array -&gt; unit)
332
333 val A =
334 fn z =&gt;
335 Fold.fold
336 ((0, NONE, ignore),
337 fn (n, opt, fill) =&gt;
338 case opt of
339 NONE =&gt;
340 Array.tabulate (0, fn _ =&gt; raise Fail "array0")
341 | SOME x =&gt;
342 let
343 val a = Array.array (n, x)
344 val () = fill a
345 in
346 a
347 end)
348 z
349
350 val V = fn z =&gt; Fold.post (A, Array.vector) z
351
352 val ` =
353 fn z =&gt;
354 Fold.step1
355 (fn (x, (i, opt, fill)) =&gt;
356 (i + 1,
357 SOME x,
358 fn a =&gt; (Array.update (a, i, x); fill a)))
359 z
360 end</programlisting>
361 <simpara>The idea of the code is for the fold to accumulate a count of the
362 number of elements, a sample element, and a function that fills in all
363 the elements. When the fold is complete, the finishing function
364 allocates the array, applies the fill function, and returns the array.
365 The only difference between <literal>A</literal> and <literal>V</literal> is at the very end; <literal>A</literal> just
366 returns the array, while <literal>V</literal> converts it to a vector using
367 post-composition, which is further described on the <link linkend="Fold">Fold</link> page.</simpara>
368 <simpara><?asciidoc-pagebreak?></simpara>
369 </section>
370 <section id="AST">
371 <title>AST</title>
372 <simpara><link linkend="AST">AST</link> is the <link linkend="IntermediateLanguage">IntermediateLanguage</link> produced by the <link linkend="FrontEnd">FrontEnd</link>
373 and translated by <link linkend="Elaborate">Elaborate</link> to <link linkend="CoreML">CoreML</link>.</simpara>
374 <section id="_description_2">
375 <title>Description</title>
376 <simpara>The abstract syntax tree produced by the <link linkend="FrontEnd">FrontEnd</link>.</simpara>
377 </section>
378 <section id="_implementation_2">
379 <title>Implementation</title>
380 <itemizedlist>
381 <listitem>
382 <simpara>
383 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ast/ast-programs.sig"><literal>ast-programs.sig</literal></ulink>
384 </simpara>
385 </listitem>
386 <listitem>
387 <simpara>
388 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ast/ast-programs.fun"><literal>ast-programs.fun</literal></ulink>
389 </simpara>
390 </listitem>
391 <listitem>
392 <simpara>
393 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ast/ast-modules.sig"><literal>ast-modules.sig</literal></ulink>
394 </simpara>
395 </listitem>
396 <listitem>
397 <simpara>
398 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ast/ast-modules.fun"><literal>ast-modules.fun</literal></ulink>
399 </simpara>
400 </listitem>
401 <listitem>
402 <simpara>
403 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ast/ast-core.sig"><literal>ast-core.sig</literal></ulink>
404 </simpara>
405 </listitem>
406 <listitem>
407 <simpara>
408 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ast/ast-core.fun"><literal>ast-core.fun</literal></ulink>
409 </simpara>
410 </listitem>
411 <listitem>
412 <simpara>
413 <ulink url="https://github.com/MLton/mlton/tree/master/mlton/ast"><literal>ast</literal></ulink>
414 </simpara>
415 </listitem>
416 </itemizedlist>
417 </section>
418 <section id="_type_checking">
419 <title>Type Checking</title>
420 <simpara>The <link linkend="AST">AST</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> has no independent type
421 checker. Type inference is performed on an AST program as part of
422 <link linkend="Elaborate">Elaborate</link>.</simpara>
423 </section>
424 <section id="_details_and_notes_2">
425 <title>Details and Notes</title>
426 <section id="_source_locations">
427 <title>Source locations</title>
428 <simpara>MLton makes use of a relatively clean method for annotating the
429 abstract syntax tree with source location information. Every source
430 program phrase is "wrapped" with the <literal>WRAPPED</literal> interface:</simpara>
431 <programlisting language="sml" linenumbering="unnumbered">signature WRAPPED =
432 sig
433 type node'
434 type obj
435
436 val dest: obj -&gt; node' * Region.t
437 val makeRegion': node' * SourcePos.t * SourcePos.t -&gt; obj
438 val makeRegion: node' * Region.t -&gt; obj
439 val node: obj -&gt; node'
440 val region: obj -&gt; Region.t
441 end</programlisting>
442 <simpara>The key idea is that <literal>node'</literal> is the type of an unannotated syntax
443 phrase and <literal>obj</literal> is the type of its annotated counterpart. In the
444 implementation, every <literal>node'</literal> is annotated with a <literal>Region.t</literal>
445 (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/control/region.sig"><literal>region.sig</literal></ulink>,
446 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/control/region.sml"><literal>region.sml</literal></ulink>), which describes the
447 syntax phrase&#8217;s left source position and right source position, where
448 <literal>SourcePos.t</literal> (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/control/source-pos.sig"><literal>source-pos.sig</literal></ulink>,
449 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/control/source-pos.sml"><literal>source-pos.sml</literal></ulink>) denotes a
450 particular file, line, and column. A typical use of the <literal>WRAPPED</literal>
451 interface is illustrated by the following code:</simpara>
452 <programlisting language="sml" linenumbering="unnumbered"> datatype node =
453 App of Longcon.t * t
454 | Const of Const.t
455 | Constraint of t * Type.t
456 | FlatApp of t vector
457 | Layered of {constraint: Type.t option,
458 fixop: Fixop.t,
459 pat: t,
460 var: Var.t}
461 | List of t vector
462 | Paren of t
463 | Or of t vector
464 | Record of {flexible: bool,
465 items: (Record.Field.t * Region.t * Item.t) vector}
466 | Tuple of t vector
467 | Var of {fixop: Fixop.t,
468 name: Longvid.t}
469 | Vector of t vector
470 | Wild</programlisting>
471 <simpara>Thus, AST nodes are cleanly separated from source locations. By way
472 of contrast, consider the approach taken by <link linkend="SMLNJ">SML/NJ</link> (and also
473 by the <link linkend="CKitLibrary">CKit Library</link>). Each datatype denoting a syntax
474 phrase dedicates a special constructor for annotating source
475 locations:</simpara>
476 <programlisting language="sml" linenumbering="unnumbered">datatype pat = WildPat (* empty pattern *)
477 | AppPat of {constr:pat,argument:pat} (* application *)
478 | MarkPat of pat * region (* mark a pattern *)</programlisting>
479 <simpara>The main drawback of this approach is that static type checking is not
480 sufficient to guarantee that the AST emitted from the front-end is
481 properly annotated.</simpara>
482 <simpara><?asciidoc-pagebreak?></simpara>
483 </section>
484 </section>
485 </section>
486 <section id="BasisLibrary">
487 <title>BasisLibrary</title>
488 <simpara>The <link linkend="StandardML">Standard ML</link> Basis Library is a collection of modules
489 dealing with basic types, input/output, OS interfaces, and simple
490 datatypes. It is intended as a portable library usable across all
491 implementations of SML. For the official online version of the Basis
492 Library specification, see <ulink url="http://www.standardml.org/Basis">http://www.standardml.org/Basis</ulink>.
493 <link linkend="References_GansnerReppy04">The Standard ML Basis Library</link> is a book
494 version that includes all of the online version and more. For a
495 reverse chronological list of changes to the specification, see
496 <ulink url="http://www.standardml.org/Basis/history.html">http://www.standardml.org/Basis/history.html</ulink>.</simpara>
497 <simpara>MLton implements all of the required portions of the Basis Library.
498 MLton also implements many of the optional structures. You can obtain
499 a complete and current list of what&#8217;s available using
500 <literal>mlton -show-basis</literal> (see <link linkend="ShowBasis">ShowBasis</link>). By default, MLton makes the
501 Basis Library available to user programs. You can also
502 <link linkend="MLBasisAvailableLibraries">access the Basis Library</link> from
503 <link linkend="MLBasis">ML Basis</link> files.</simpara>
504 <simpara>Below is a complete list of what MLton implements.</simpara>
505 <section id="_top_level_types_and_constructors">
506 <title>Top-level types and constructors</title>
507 <simpara><literal>eqtype 'a array</literal></simpara>
508 <simpara><literal>datatype bool = false | true</literal></simpara>
509 <simpara><literal>eqtype char</literal></simpara>
510 <simpara><literal>type exn</literal></simpara>
511 <simpara><literal>eqtype int</literal></simpara>
512 <simpara><literal>datatype 'a list = nil | :: of ('a * 'a list)</literal></simpara>
513 <simpara><literal>datatype 'a option = NONE | SOME of 'a</literal></simpara>
514 <simpara><literal>datatype order = EQUAL | GREATER | LESS</literal></simpara>
515 <simpara><literal>type real</literal></simpara>
516 <simpara><literal>datatype 'a ref = ref of 'a</literal></simpara>
517 <simpara><literal>eqtype string</literal></simpara>
518 <simpara><literal>type substring</literal></simpara>
519 <simpara><literal>eqtype unit</literal></simpara>
520 <simpara><literal>eqtype 'a vector</literal></simpara>
521 <simpara><literal>eqtype word</literal></simpara>
522 </section>
523 <section id="_top_level_exception_constructors">
524 <title>Top-level exception constructors</title>
525 <simpara><literal>Bind</literal></simpara>
526 <simpara><literal>Chr</literal></simpara>
527 <simpara><literal>Div</literal></simpara>
528 <simpara><literal>Domain</literal></simpara>
529 <simpara><literal>Empty</literal></simpara>
530 <simpara><literal>Fail of string</literal></simpara>
531 <simpara><literal>Match</literal></simpara>
532 <simpara><literal>Option</literal></simpara>
533 <simpara><literal>Overflow</literal></simpara>
534 <simpara><literal>Size</literal></simpara>
535 <simpara><literal>Span</literal></simpara>
536 <simpara><literal>Subscript</literal></simpara>
537 </section>
538 <section id="_top_level_values">
539 <title>Top-level values</title>
540 <simpara>MLton does not implement the optional top-level value
541 <literal>use: string -&gt; unit</literal>, which conflicts with whole-program
542 compilation because it allows new code to be loaded dynamically.</simpara>
543 <simpara>MLton implements all other top-level values:</simpara>
544 <simpara><literal>!</literal>,
545 <literal>:=</literal>,
546 <literal>&lt;&gt;</literal>,
547 <literal>=</literal>,
548 <literal>@</literal>,
549 <literal>^</literal>,
550 <literal>app</literal>,
551 <literal>before</literal>,
552 <literal>ceil</literal>,
553 <literal>chr</literal>,
554 <literal>concat</literal>,
555 <literal>exnMessage</literal>,
556 <literal>exnName</literal>,
557 <literal>explode</literal>,
558 <literal>floor</literal>,
559 <literal>foldl</literal>,
560 <literal>foldr</literal>,
561 <literal>getOpt</literal>,
562 <literal>hd</literal>,
563 <literal>ignore</literal>,
564 <literal>implode</literal>,
565 <literal>isSome</literal>,
566 <literal>length</literal>,
567 <literal>map</literal>,
568 <literal>not</literal>,
569 <literal>null</literal>,
570 <literal>o</literal>,
571 <literal>ord</literal>,
572 <literal>print</literal>,
573 <literal>real</literal>,
574 <literal>rev</literal>,
575 <literal>round</literal>,
576 <literal>size</literal>,
577 <literal>str</literal>,
578 <literal>substring</literal>,
579 <literal>tl</literal>,
580 <literal>trunc</literal>,
581 <literal>valOf</literal>,
582 <literal>vector</literal></simpara>
583 </section>
584 <section id="_overloaded_identifiers">
585 <title>Overloaded identifiers</title>
586 <simpara><literal>*</literal>,
587 <literal>+</literal>,
588 <literal>-</literal>,
589 <literal>/</literal>,
590 <literal>&lt;</literal>,
591 <literal>&lt;=</literal>,
592 <literal>&gt;</literal>,
593 <literal>&gt;=</literal>,
594 <literal>~</literal>,
595 <literal>abs</literal>,
596 <literal>div</literal>,
597 <literal>mod</literal></simpara>
598 </section>
599 <section id="_top_level_signatures">
600 <title>Top-level signatures</title>
601 <simpara><literal>ARRAY</literal></simpara>
602 <simpara><literal>ARRAY2</literal></simpara>
603 <simpara><literal>ARRAY_SLICE</literal></simpara>
604 <simpara><literal>BIN_IO</literal></simpara>
605 <simpara><literal>BIT_FLAGS</literal></simpara>
606 <simpara><literal>BOOL</literal></simpara>
607 <simpara><literal>BYTE</literal></simpara>
608 <simpara><literal>CHAR</literal></simpara>
609 <simpara><literal>COMMAND_LINE</literal></simpara>
610 <simpara><literal>DATE</literal></simpara>
611 <simpara><literal>GENERAL</literal></simpara>
612 <simpara><literal>GENERIC_SOCK</literal></simpara>
613 <simpara><literal>IEEE_REAL</literal></simpara>
614 <simpara><literal>IMPERATIVE_IO</literal></simpara>
615 <simpara><literal>INET_SOCK</literal></simpara>
616 <simpara><literal>INTEGER</literal></simpara>
617 <simpara><literal>INT_INF</literal></simpara>
618 <simpara><literal>IO</literal></simpara>
619 <simpara><literal>LIST</literal></simpara>
620 <simpara><literal>LIST_PAIR</literal></simpara>
621 <simpara><literal>MATH</literal></simpara>
622 <simpara><literal>MONO_ARRAY</literal></simpara>
623 <simpara><literal>MONO_ARRAY2</literal></simpara>
624 <simpara><literal>MONO_ARRAY_SLICE</literal></simpara>
625 <simpara><literal>MONO_VECTOR</literal></simpara>
626 <simpara><literal>MONO_VECTOR_SLICE</literal></simpara>
627 <simpara><literal>NET_HOST_DB</literal></simpara>
628 <simpara><literal>NET_PROT_DB</literal></simpara>
629 <simpara><literal>NET_SERV_DB</literal></simpara>
630 <simpara><literal>OPTION</literal></simpara>
631 <simpara><literal>OS</literal></simpara>
632 <simpara><literal>OS_FILE_SYS</literal></simpara>
633 <simpara><literal>OS_IO</literal></simpara>
634 <simpara><literal>OS_PATH</literal></simpara>
635 <simpara><literal>OS_PROCESS</literal></simpara>
636 <simpara><literal>PACK_REAL</literal></simpara>
637 <simpara><literal>PACK_WORD</literal></simpara>
638 <simpara><literal>POSIX</literal></simpara>
639 <simpara><literal>POSIX_ERROR</literal></simpara>
640 <simpara><literal>POSIX_FILE_SYS</literal></simpara>
641 <simpara><literal>POSIX_IO</literal></simpara>
642 <simpara><literal>POSIX_PROCESS</literal></simpara>
643 <simpara><literal>POSIX_PROC_ENV</literal></simpara>
644 <simpara><literal>POSIX_SIGNAL</literal></simpara>
645 <simpara><literal>POSIX_SYS_DB</literal></simpara>
646 <simpara><literal>POSIX_TTY</literal></simpara>
647 <simpara><literal>PRIM_IO</literal></simpara>
648 <simpara><literal>REAL</literal></simpara>
649 <simpara><literal>SOCKET</literal></simpara>
650 <simpara><literal>STREAM_IO</literal></simpara>
651 <simpara><literal>STRING</literal></simpara>
652 <simpara><literal>STRING_CVT</literal></simpara>
653 <simpara><literal>SUBSTRING</literal></simpara>
654 <simpara><literal>TEXT</literal></simpara>
655 <simpara><literal>TEXT_IO</literal></simpara>
656 <simpara><literal>TEXT_STREAM_IO</literal></simpara>
657 <simpara><literal>TIME</literal></simpara>
658 <simpara><literal>TIMER</literal></simpara>
659 <simpara><literal>UNIX</literal></simpara>
660 <simpara><literal>UNIX_SOCK</literal></simpara>
661 <simpara><literal>VECTOR</literal></simpara>
662 <simpara><literal>VECTOR_SLICE</literal></simpara>
663 <simpara><literal>WORD</literal></simpara>
664 </section>
665 <section id="_top_level_structures">
666 <title>Top-level structures</title>
667 <simpara><literal>structure Array: ARRAY</literal></simpara>
668 <simpara><literal>structure Array2: ARRAY2</literal></simpara>
669 <simpara><literal>structure ArraySlice: ARRAY_SLICE</literal></simpara>
670 <simpara><literal>structure BinIO: BIN_IO</literal></simpara>
671 <simpara><literal>structure BinPrimIO: PRIM_IO</literal></simpara>
672 <simpara><literal>structure Bool: BOOL</literal></simpara>
673 <simpara><literal>structure BoolArray: MONO_ARRAY</literal></simpara>
674 <simpara><literal>structure BoolArray2: MONO_ARRAY2</literal></simpara>
675 <simpara><literal>structure BoolArraySlice: MONO_ARRAY_SLICE</literal></simpara>
676 <simpara><literal>structure BoolVector: MONO_VECTOR</literal></simpara>
677 <simpara><literal>structure BoolVectorSlice: MONO_VECTOR_SLICE</literal></simpara>
678 <simpara><literal>structure Byte: BYTE</literal></simpara>
679 <simpara><literal>structure Char: CHAR</literal></simpara>
680 <itemizedlist>
681 <listitem>
682 <simpara>
683 <literal>Char</literal> characters correspond to ISO-8859-1. The <literal>Char</literal> functions do not depend on locale.
684 </simpara>
685 </listitem>
686 </itemizedlist>
687 <simpara><literal>structure CharArray: MONO_ARRAY</literal></simpara>
688 <simpara><literal>structure CharArray2: MONO_ARRAY2</literal></simpara>
689 <simpara><literal>structure CharArraySlice: MONO_ARRAY_SLICE</literal></simpara>
690 <simpara><literal>structure CharVector: MONO_VECTOR</literal></simpara>
691 <simpara><literal>structure CharVectorSlice: MONO_VECTOR_SLICE</literal></simpara>
692 <simpara><literal>structure CommandLine: COMMAND_LINE</literal></simpara>
693 <simpara><literal>structure Date: DATE</literal></simpara>
694 <itemizedlist>
695 <listitem>
696 <simpara>
697 <literal>Date.fromString</literal> and <literal>Date.scan</literal> accept a space in addition to a zero for the first character of the day of the month. The Basis Library specification only allows a zero.
698 </simpara>
699 </listitem>
700 </itemizedlist>
701 <simpara><literal>structure FixedInt: INTEGER</literal></simpara>
702 <simpara><literal>structure General: GENERAL</literal></simpara>
703 <simpara><literal>structure GenericSock: GENERIC_SOCK</literal></simpara>
704 <simpara><literal>structure IEEEReal: IEEE_REAL</literal></simpara>
705 <simpara><literal>structure INetSock: INET_SOCK</literal></simpara>
706 <simpara><literal>structure IO: IO</literal></simpara>
707 <simpara><literal>structure Int: INTEGER</literal></simpara>
708 <simpara><literal>structure Int1: INTEGER</literal></simpara>
709 <simpara><literal>structure Int2: INTEGER</literal></simpara>
710 <simpara><literal>structure Int3: INTEGER</literal></simpara>
711 <simpara><literal>structure Int4: INTEGER</literal></simpara>
712 <simpara>&#8230;</simpara>
713 <simpara><literal>structure Int31: INTEGER</literal></simpara>
714 <simpara><literal>structure Int32: INTEGER</literal></simpara>
715 <simpara><literal>structure Int64: INTEGER</literal></simpara>
716 <simpara><literal>structure IntArray: MONO_ARRAY</literal></simpara>
717 <simpara><literal>structure IntArray2: MONO_ARRAY2</literal></simpara>
718 <simpara><literal>structure IntArraySlice: MONO_ARRAY_SLICE</literal></simpara>
719 <simpara><literal>structure IntVector: MONO_VECTOR</literal></simpara>
720 <simpara><literal>structure IntVectorSlice: MONO_VECTOR_SLICE</literal></simpara>
721 <simpara><literal>structure Int8: INTEGER</literal></simpara>
722 <simpara><literal>structure Int8Array: MONO_ARRAY</literal></simpara>
723 <simpara><literal>structure Int8Array2: MONO_ARRAY2</literal></simpara>
724 <simpara><literal>structure Int8ArraySlice: MONO_ARRAY_SLICE</literal></simpara>
725 <simpara><literal>structure Int8Vector: MONO_VECTOR</literal></simpara>
726 <simpara><literal>structure Int8VectorSlice: MONO_VECTOR_SLICE</literal></simpara>
727 <simpara><literal>structure Int16: INTEGER</literal></simpara>
728 <simpara><literal>structure Int16Array: MONO_ARRAY</literal></simpara>
729 <simpara><literal>structure Int16Array2: MONO_ARRAY2</literal></simpara>
730 <simpara><literal>structure Int16ArraySlice: MONO_ARRAY_SLICE</literal></simpara>
731 <simpara><literal>structure Int16Vector: MONO_VECTOR</literal></simpara>
732 <simpara><literal>structure Int16VectorSlice: MONO_VECTOR_SLICE</literal></simpara>
733 <simpara><literal>structure Int32: INTEGER</literal></simpara>
734 <simpara><literal>structure Int32Array: MONO_ARRAY</literal></simpara>
735 <simpara><literal>structure Int32Array2: MONO_ARRAY2</literal></simpara>
736 <simpara><literal>structure Int32ArraySlice: MONO_ARRAY_SLICE</literal></simpara>
737 <simpara><literal>structure Int32Vector: MONO_VECTOR</literal></simpara>
738 <simpara><literal>structure Int32VectorSlice: MONO_VECTOR_SLICE</literal></simpara>
739 <simpara><literal>structure Int64Array: MONO_ARRAY</literal></simpara>
740 <simpara><literal>structure Int64Array2: MONO_ARRAY2</literal></simpara>
741 <simpara><literal>structure Int64ArraySlice: MONO_ARRAY_SLICE</literal></simpara>
742 <simpara><literal>structure Int64Vector: MONO_VECTOR</literal></simpara>
743 <simpara><literal>structure Int64VectorSlice: MONO_VECTOR_SLICE</literal></simpara>
744 <simpara><literal>structure IntInf: INT_INF</literal></simpara>
745 <simpara><literal>structure LargeInt: INTEGER</literal></simpara>
746 <simpara><literal>structure LargeIntArray: MONO_ARRAY</literal></simpara>
747 <simpara><literal>structure LargeIntArray2: MONO_ARRAY2</literal></simpara>
748 <simpara><literal>structure LargeIntArraySlice: MONO_ARRAY_SLICE</literal></simpara>
749 <simpara><literal>structure LargeIntVector: MONO_VECTOR</literal></simpara>
750 <simpara><literal>structure LargeIntVectorSlice: MONO_VECTOR_SLICE</literal></simpara>
751 <simpara><literal>structure LargeReal: REAL</literal></simpara>
752 <simpara><literal>structure LargeRealArray: MONO_ARRAY</literal></simpara>
753 <simpara><literal>structure LargeRealArray2: MONO_ARRAY2</literal></simpara>
754 <simpara><literal>structure LargeRealArraySlice: MONO_ARRAY_SLICE</literal></simpara>
755 <simpara><literal>structure LargeRealVector: MONO_VECTOR</literal></simpara>
756 <simpara><literal>structure LargeRealVectorSlice: MONO_VECTOR_SLICE</literal></simpara>
757 <simpara><literal>structure LargeWord: WORD</literal></simpara>
758 <simpara><literal>structure LargeWordArray: MONO_ARRAY</literal></simpara>
759 <simpara><literal>structure LargeWordArray2: MONO_ARRAY2</literal></simpara>
760 <simpara><literal>structure LargeWordArraySlice: MONO_ARRAY_SLICE</literal></simpara>
761 <simpara><literal>structure LargeWordVector: MONO_VECTOR</literal></simpara>
762 <simpara><literal>structure LargeWordVectorSlice: MONO_VECTOR_SLICE</literal></simpara>
763 <simpara><literal>structure List: LIST</literal></simpara>
764 <simpara><literal>structure ListPair: LIST_PAIR</literal></simpara>
765 <simpara><literal>structure Math: MATH</literal></simpara>
766 <simpara><literal>structure NetHostDB: NET_HOST_DB</literal></simpara>
767 <simpara><literal>structure NetProtDB: NET_PROT_DB</literal></simpara>
768 <simpara><literal>structure NetServDB: NET_SERV_DB</literal></simpara>
769 <simpara><literal>structure OS: OS</literal></simpara>
770 <simpara><literal>structure Option: OPTION</literal></simpara>
771 <simpara><literal>structure PackReal32Big: PACK_REAL</literal></simpara>
772 <simpara><literal>structure PackReal32Little: PACK_REAL</literal></simpara>
773 <simpara><literal>structure PackReal64Big: PACK_REAL</literal></simpara>
774 <simpara><literal>structure PackReal64Little: PACK_REAL</literal></simpara>
775 <simpara><literal>structure PackRealBig: PACK_REAL</literal></simpara>
776 <simpara><literal>structure PackRealLittle: PACK_REAL</literal></simpara>
777 <simpara><literal>structure PackWord16Big: PACK_WORD</literal></simpara>
778 <simpara><literal>structure PackWord16Little: PACK_WORD</literal></simpara>
779 <simpara><literal>structure PackWord32Big: PACK_WORD</literal></simpara>
780 <simpara><literal>structure PackWord32Little: PACK_WORD</literal></simpara>
781 <simpara><literal>structure PackWord64Big: PACK_WORD</literal></simpara>
782 <simpara><literal>structure PackWord64Little: PACK_WORD</literal></simpara>
783 <simpara><literal>structure Position: INTEGER</literal></simpara>
784 <simpara><literal>structure Posix: POSIX</literal></simpara>
785 <simpara><literal>structure Real: REAL</literal></simpara>
786 <simpara><literal>structure RealArray: MONO_ARRAY</literal></simpara>
787 <simpara><literal>structure RealArray2: MONO_ARRAY2</literal></simpara>
788 <simpara><literal>structure RealArraySlice: MONO_ARRAY_SLICE</literal></simpara>
789 <simpara><literal>structure RealVector: MONO_VECTOR</literal></simpara>
790 <simpara><literal>structure RealVectorSlice: MONO_VECTOR_SLICE</literal></simpara>
791 <simpara><literal>structure Real32: REAL</literal></simpara>
792 <simpara><literal>structure Real32Array: MONO_ARRAY</literal></simpara>
793 <simpara><literal>structure Real32Array2: MONO_ARRAY2</literal></simpara>
794 <simpara><literal>structure Real32ArraySlice: MONO_ARRAY_SLICE</literal></simpara>
795 <simpara><literal>structure Real32Vector: MONO_VECTOR</literal></simpara>
796 <simpara><literal>structure Real32VectorSlice: MONO_VECTOR_SLICE</literal></simpara>
797 <simpara><literal>structure Real64: REAL</literal></simpara>
798 <simpara><literal>structure Real64Array: MONO_ARRAY</literal></simpara>
799 <simpara><literal>structure Real64Array2: MONO_ARRAY2</literal></simpara>
800 <simpara><literal>structure Real64ArraySlice: MONO_ARRAY_SLICE</literal></simpara>
801 <simpara><literal>structure Real64Vector: MONO_VECTOR</literal></simpara>
802 <simpara><literal>structure Real64VectorSlice: MONO_VECTOR_SLICE</literal></simpara>
803 <simpara><literal>structure Socket: SOCKET</literal></simpara>
804 <itemizedlist>
805 <listitem>
806 <simpara>
807 The Basis Library specification requires functions like
808 <literal>Socket.sendVec</literal> to raise an exception if they fail. However, on some
809 platforms, sending to a socket that hasn&#8217;t yet been connected causes a
810 <literal>SIGPIPE</literal> signal, which invokes the default signal handler for
811 <literal>SIGPIPE</literal> and causes the program to terminate. If you want the
812 exception to be raised, you can ignore <literal>SIGPIPE</literal> by adding the
813 following to your program.
814 </simpara>
815 <programlisting language="sml" linenumbering="unnumbered">let
816 open MLton.Signal
817 in
818 setHandler (Posix.Signal.pipe, Handler.ignore)
819 end</programlisting>
820 </listitem>
821 </itemizedlist>
822 <simpara><literal>structure String: STRING</literal></simpara>
823 <itemizedlist>
824 <listitem>
825 <simpara>
826 The <literal>String</literal> functions do not depend on locale.
827 </simpara>
828 </listitem>
829 </itemizedlist>
830 <simpara><literal>structure StringCvt: STRING_CVT</literal></simpara>
831 <simpara><literal>structure Substring: SUBSTRING</literal></simpara>
832 <simpara><literal>structure SysWord: WORD</literal></simpara>
833 <simpara><literal>structure Text: TEXT</literal></simpara>
834 <simpara><literal>structure TextIO: TEXT_IO</literal></simpara>
835 <simpara><literal>structure TextPrimIO: PRIM_IO</literal></simpara>
836 <simpara><literal>structure Time: TIME</literal></simpara>
837 <simpara><literal>structure Timer: TIMER</literal></simpara>
838 <simpara><literal>structure Unix: UNIX</literal></simpara>
839 <simpara><literal>structure UnixSock: UNIX_SOCK</literal></simpara>
840 <simpara><literal>structure Vector: VECTOR</literal></simpara>
841 <simpara><literal>structure VectorSlice: VECTOR_SLICE</literal></simpara>
842 <simpara><literal>structure Word: WORD</literal></simpara>
843 <simpara><literal>structure Word1: WORD</literal></simpara>
844 <simpara><literal>structure Word2: WORD</literal></simpara>
845 <simpara><literal>structure Word3: WORD</literal></simpara>
846 <simpara><literal>structure Word4: WORD</literal></simpara>
847 <simpara>&#8230;</simpara>
848 <simpara><literal>structure Word31: WORD</literal></simpara>
849 <simpara><literal>structure Word32: WORD</literal></simpara>
850 <simpara><literal>structure Word64: WORD</literal></simpara>
851 <simpara><literal>structure WordArray: MONO_ARRAY</literal></simpara>
852 <simpara><literal>structure WordArray2: MONO_ARRAY2</literal></simpara>
853 <simpara><literal>structure WordArraySlice: MONO_ARRAY_SLICE</literal></simpara>
854 <simpara><literal>structure WordVectorSlice: MONO_VECTOR_SLICE</literal></simpara>
855 <simpara><literal>structure WordVector: MONO_VECTOR</literal></simpara>
856 <simpara><literal>structure Word8Array: MONO_ARRAY</literal></simpara>
857 <simpara><literal>structure Word8Array2: MONO_ARRAY2</literal></simpara>
858 <simpara><literal>structure Word8ArraySlice: MONO_ARRAY_SLICE</literal></simpara>
859 <simpara><literal>structure Word8Vector: MONO_VECTOR</literal></simpara>
860 <simpara><literal>structure Word8VectorSlice: MONO_VECTOR_SLICE</literal></simpara>
861 <simpara><literal>structure Word16Array: MONO_ARRAY</literal></simpara>
862 <simpara><literal>structure Word16Array2: MONO_ARRAY2</literal></simpara>
863 <simpara><literal>structure Word16ArraySlice: MONO_ARRAY_SLICE</literal></simpara>
864 <simpara><literal>structure Word16Vector: MONO_VECTOR</literal></simpara>
865 <simpara><literal>structure Word16VectorSlice: MONO_VECTOR_SLICE</literal></simpara>
866 <simpara><literal>structure Word32Array: MONO_ARRAY</literal></simpara>
867 <simpara><literal>structure Word32Array2: MONO_ARRAY2</literal></simpara>
868 <simpara><literal>structure Word32ArraySlice: MONO_ARRAY_SLICE</literal></simpara>
869 <simpara><literal>structure Word32Vector: MONO_VECTOR</literal></simpara>
870 <simpara><literal>structure Word32VectorSlice: MONO_VECTOR_SLICE</literal></simpara>
871 <simpara><literal>structure Word64Array: MONO_ARRAY</literal></simpara>
872 <simpara><literal>structure Word64Array2: MONO_ARRAY2</literal></simpara>
873 <simpara><literal>structure Word64ArraySlice: MONO_ARRAY_SLICE</literal></simpara>
874 <simpara><literal>structure Word64Vector: MONO_VECTOR</literal></simpara>
875 <simpara><literal>structure Word64VectorSlice: MONO_VECTOR_SLICE</literal></simpara>
876 </section>
877 <section id="_top_level_functors">
878 <title>Top-level functors</title>
879 <simpara><literal>ImperativeIO</literal></simpara>
880 <simpara><literal>PrimIO</literal></simpara>
881 <simpara><literal>StreamIO</literal></simpara>
882 <itemizedlist>
883 <listitem>
884 <simpara>
885 MLton&#8217;s <literal>StreamIO</literal> functor takes structures <literal>ArraySlice</literal> and
886 <literal>VectorSlice</literal> in addition to the arguments specified in the Basis
887 Library specification.
888 </simpara>
889 </listitem>
890 </itemizedlist>
891 </section>
892 <section id="_type_equivalences">
893 <title>Type equivalences</title>
894 <simpara>The following types are equivalent.</simpara>
895 <screen>FixedInt = Int64.int
896 LargeInt = IntInf.int
897 LargeReal.real = Real64.real
898 LargeWord = Word64.word</screen>
899 <simpara>The default <literal>int</literal>, <literal>real</literal>, and <literal>word</literal> types may be set by the
900 <literal>-default-type <emphasis>type</emphasis></literal> <link linkend="CompileTimeOptions">compile-time option</link>.
901 By default, the following types are equivalent:</simpara>
902 <screen>int = Int.int = Int32.int
903 real = Real.real = Real64.real
904 word = Word.word = Word32.word</screen>
905 </section>
906 <section id="_real_and_math_functions">
907 <title>Real and Math functions</title>
908 <simpara>The <literal>Real</literal>, <literal>Real32</literal>, and <literal>Real64</literal> modules are implemented
909 using the <literal>C</literal> math library, so the SML functions will reflect the
910 behavior of the underlying library function. We have made some effort
911 to unify the differences between the math libraries on different
912 platforms, and in particular to handle exceptional cases according to
913 the Basis Library specification. However, there will be differences
914 due to different numerical algorithms and cases we may have missed.
915 Please submit a <link linkend="Bug">bug report</link> if you encounter an error in
916 the handling of an exceptional case.</simpara>
917 <simpara>On x86, real arithmetic is implemented internally using 80 bits of
918 precision. Using higher precision for intermediate results in
919 computations can lead to different results than if all the computation
920 is done at 32 or 64 bits. If you require strict IEEE compliance, you
921 can compile with <literal>-ieee-fp true</literal>, which will cause intermediate
922 results to be stored after each operation. This may cause a
923 substantial performance penalty.</simpara>
924 <simpara><?asciidoc-pagebreak?></simpara>
925 </section>
926 </section>
927 <section id="Bug">
928 <title>Bug</title>
929 <simpara>To report a bug, please send mail to
930 <ulink url="mailto:mlton-devel@mlton.org"><literal>mlton-devel@mlton.org</literal></ulink>. Please include
931 the complete SML program that caused the problem and a log of a
932 compile of the program with <literal>-verbose 2</literal>. For large programs (over
933 256K), please send an email containing the discussion text and a link
934 to any large files.</simpara>
935 <simpara>There are some <link linkend="UnresolvedBugs">UnresolvedBugs</link> that we don&#8217;t plan to fix.</simpara>
936 <simpara>We also maintain a list of bugs found with each release.</simpara>
937 <itemizedlist>
938 <listitem>
939 <simpara>
940 <link linkend="Bugs20130715">Bugs20130715</link>
941 </simpara>
942 </listitem>
943 <listitem>
944 <simpara>
945 <link linkend="Bugs20100608">Bugs20100608</link>
946 </simpara>
947 </listitem>
948 <listitem>
949 <simpara>
950 <link linkend="Bugs20070826">Bugs20070826</link>
951 </simpara>
952 </listitem>
953 <listitem>
954 <simpara>
955 <link linkend="Bugs20051202">Bugs20051202</link>
956 </simpara>
957 </listitem>
958 <listitem>
959 <simpara>
960 <link linkend="Bugs20041109">Bugs20041109</link>
961 </simpara>
962 </listitem>
963 </itemizedlist>
964 <simpara><?asciidoc-pagebreak?></simpara>
965 </section>
966 <section id="Bugs20041109">
967 <title>Bugs20041109</title>
968 <simpara>Here are the known bugs in <link linkend="Release20041109">MLton 20041109</link>, listed
969 in reverse chronological order of date reported.</simpara>
970 <itemizedlist>
971 <listitem>
972 <simpara>
973 <anchor id="Bugs20041109_bug17" xreflabel="[Bugs20041109_bug17]"/>
974 <literal>MLton.Finalizable.touch</literal> doesn&#8217;t necessarily keep values alive
975 long enough. Our SVN has a patch to the compiler. You must rebuild
976 the compiler in order for the patch to take effect.
977 </simpara>
978 <simpara>Thanks to Florian Weimer for reporting this bug.</simpara>
979 </listitem>
980 <listitem>
981 <simpara>
982 <anchor id="Bugs20041109_bug16" xreflabel="[Bugs20041109_bug16]"/>
983 A bug in an optimization pass may incorrectly transform a program
984 to flatten ref cells into their containing data structure, yielding a
985 type-error in the transformed program. Our CVS has a
986 <ulink url="http://mlton.org/cgi-bin/viewcvs.cgi/mlton/mlton/mlton/ssa/ref-flatten.fun.diff?r1=1.35&amp;r2=1.37">patch</ulink>
987 to the compiler. You must rebuild the compiler in order for the
988 patch to take effect.
989 </simpara>
990 <simpara>Thanks to <link linkend="VesaKarvonen">VesaKarvonen</link> for reporting this bug.</simpara>
991 </listitem>
992 <listitem>
993 <simpara>
994 <anchor id="Bugs20041109_bug15" xreflabel="[Bugs20041109_bug15]"/>
995 A bug in the front end mistakenly allows unary constructors to be
996 used without an argument in patterns. For example, the following
997 program is accepted, and triggers a large internal error.
998 </simpara>
999 <programlisting language="sml" linenumbering="unnumbered">fun f x = case x of SOME =&gt; true | _ =&gt; false</programlisting>
1000 <simpara>We have fixed the problem in our CVS.</simpara>
1001 <simpara>Thanks to William Lovas for reporting this bug.</simpara>
1002 </listitem>
1003 <listitem>
1004 <simpara>
1005 <anchor id="Bugs20041109_bug14" xreflabel="[Bugs20041109_bug14]"/>
1006 A bug in <literal>Posix.IO.{getlk,setlk,setlkw}</literal> causes a link-time error:
1007 <literal>undefined reference to Posix_IO_FLock_typ</literal>
1008 Our CVS has a
1009 <ulink url="http://mlton.org/cgi-bin/viewcvs.cgi/mlton/mlton/basis-library/posix/primitive.sml.diff?r1=1.34&amp;r2=1.35">patch</ulink>
1010 to the Basis Library implementation.
1011 </simpara>
1012 <simpara>Thanks to Adam Chlipala for reporting this bug.</simpara>
1013 </listitem>
1014 <listitem>
1015 <simpara>
1016 <anchor id="Bugs20041109_bug13" xreflabel="[Bugs20041109_bug13]"/>
1017 A bug can cause programs compiled with <literal>-profile alloc</literal> to
1018 segfault. Our CVS has a
1019 <ulink url="http://mlton.org/cgi-bin/viewcvs.cgi/mlton/mlton/mlton/backend/ssa-to-rssa.fun.diff?r1=1.106&amp;r2=1.107">patch</ulink>
1020 to the compiler. You must rebuild the compiler in order for the
1021 patch to take effect.
1022 </simpara>
1023 <simpara>Thanks to John Reppy for reporting this bug.</simpara>
1024 </listitem>
1025 <listitem>
1026 <simpara>
1027 <anchor id="Bugs20041109_bug12" xreflabel="[Bugs20041109_bug12]"/>
1028 A bug in an optimization pass may incorrectly flatten ref cells
1029 into their containing data structure, breaking the sharing between
1030 the cells. Our CVS has a
1031 <ulink url="http://mlton.org/cgi-bin/viewcvs.cgi/mlton/mlton/mlton/ssa/ref-flatten.fun.diff?r1=1.32&amp;r2=1.33">patch</ulink>
1032 to the compiler. You must rebuild the compiler in order for the
1033 patch to take effect.
1034 </simpara>
1035 <simpara>Thanks to Paul Govereau for reporting this bug.</simpara>
1036 </listitem>
1037 <listitem>
1038 <simpara>
1039 <anchor id="Bugs20041109_bug11" xreflabel="[Bugs20041109_bug11]"/>
1040 Some arrays or vectors, such as <literal>(char * char) vector</literal>, are
1041 incorrectly implemented, and will conflate the first and second
1042 components of each element. Our CVS has a
1043 <ulink url="http://mlton.org/cgi-bin/viewcvs.cgi/mlton/mlton/mlton/backend/packed-representation.fun.diff?r1=1.32&amp;r2=1.33">patch</ulink>
1044 to the compiler. You must rebuild the compiler in order for the
1045 patch to take effect.
1046 </simpara>
1047 <simpara>Thanks to Scott Cruzen for reporting this bug.</simpara>
1048 </listitem>
1049 <listitem>
1050 <simpara>
1051 <anchor id="Bugs20041109_bug10" xreflabel="[Bugs20041109_bug10]"/>
1052 <literal>Socket.Ctl.getLINGER</literal> and <literal>Socket.Ctl.setLINGER</literal>
1053 mistakenly raise <literal>Subscript</literal>.
1054 Our CVS has a
1055 <ulink url="http://mlton.org/cgi-bin/viewcvs.cgi/mlton/mlton/basis-library/net/socket.sml.diff?r1=1.14&amp;r2=1.15">patch</ulink>
1056 to the Basis Library implementation.
1057 </simpara>
1058 <simpara>Thanks to Ray Racine for reporting the bug.</simpara>
1059 </listitem>
1060 <listitem>
1061 <simpara>
1062 <anchor id="Bugs20041109_bug09" xreflabel="[Bugs20041109_bug09]"/>
1063 <link linkend="ConcurrentML">CML</link> <literal>Mailbox.send</literal> makes a call in the wrong atomic context.
1064 Our CVS has a <ulink url="http://mlton.org/cgi-bin/viewcvs.cgi/mlton/mlton/lib/cml/core-cml/mailbox.sml.diff?r1=1.3&amp;r2=1.4">patch</ulink>
1065 to the CML implementation.
1066 </simpara>
1067 </listitem>
1068 <listitem>
1069 <simpara>
1070 <anchor id="Bugs20041109_bug08" xreflabel="[Bugs20041109_bug08]"/>
1071 <literal>OS.Path.joinDirFile</literal> and <literal>OS.Path.toString</literal> did not
1072 raise <literal>InvalidArc</literal> when they were supposed to. They now do.
1073 Our CVS has a <ulink url="http://mlton.org/cgi-bin/viewcvs.cgi/mlton/mlton/basis-library/system/path.sml.diff?r1=1.8&amp;r2=1.11">patch</ulink>
1074 to the Basis Library implementation.
1075 </simpara>
1076 <simpara>Thanks to Andreas Rossberg for reporting the bug.</simpara>
1077 </listitem>
1078 <listitem>
1079 <simpara>
1080 <anchor id="Bugs20041109_bug07" xreflabel="[Bugs20041109_bug07]"/>
1081 The front end incorrectly disallows sequences of expressions
1082 (separated by semicolons) after a topdec has already been processed.
1083 For example, the following is incorrectly rejected.
1084 </simpara>
1085 <programlisting language="sml" linenumbering="unnumbered">val x = 0;
1086 ignore x;
1087 ignore x;</programlisting>
1088 <simpara>We have fixed the problem in our CVS.</simpara>
1089 <simpara>Thanks to Andreas Rossberg for reporting the bug.</simpara>
1090 </listitem>
1091 <listitem>
1092 <simpara>
1093 <anchor id="Bugs20041109_bug06" xreflabel="[Bugs20041109_bug06]"/>
1094 The front end incorrectly disallows expansive <literal>val</literal>
1095 declarations that bind a type variable that doesn&#8217;t occur in the
1096 type of the value being bound. For example, the following is
1097 incorrectly rejected.
1098 </simpara>
1099 <programlisting language="sml" linenumbering="unnumbered">val 'a x = let exception E of 'a in () end</programlisting>
1100 <simpara>We have fixed the problem in our CVS.</simpara>
1101 <simpara>Thanks to Andreas Rossberg for reporting this bug.</simpara>
1102 </listitem>
1103 <listitem>
1104 <simpara>
1105 <anchor id="Bugs20041109_bug05" xreflabel="[Bugs20041109_bug05]"/>
1106 The x86 codegen fails to account for the possibility that a 64-bit
1107 move could interfere with itself (as simulated by 32-bit moves). We
1108 have fixed the problem in our CVS.
1109 </simpara>
1110 <simpara>Thanks to Scott Cruzen for reporting this bug.</simpara>
1111 </listitem>
1112 <listitem>
1113 <simpara>
1114 <anchor id="Bugs20041109_bug04" xreflabel="[Bugs20041109_bug04]"/>
1115 <literal>NetHostDB.scan</literal> and <literal>NetHostDB.fromString</literal> incorrectly
1116 raise an exception on internet addresses whose last component is a
1117 zero, e.g <literal>0.0.0.0</literal>. Our CVS has a
1118 <ulink url="http://mlton.org/cgi-bin/viewcvs.cgi/mlton/mlton/basis-library/net/net-host-db.sml.diff?r1=1.12&amp;r2=1.13">patch</ulink> to the Basis Library implementation.
1119 </simpara>
1120 <simpara>Thanks to Scott Cruzen for reporting this bug.</simpara>
1121 </listitem>
1122 <listitem>
1123 <simpara>
1124 <anchor id="Bugs20041109_bug03" xreflabel="[Bugs20041109_bug03]"/>
1125 <literal>StreamIO.inputLine</literal> has an off-by-one error causing it to drop
1126 the first character after a newline in some situations. Our CVS has a
1127 <ulink url="http://mlton.org/cgi-bin/viewcvs.cgi/mlton/mlton/basis-library/io/stream-io.fun.diff?r1=text&amp;tr1=1.29&amp;r2=text&amp;tr2=1.30&amp;diff_format=h">patch</ulink>.
1128 to the Basis Library implementation.
1129 </simpara>
1130 <simpara>Thanks to Scott Cruzen for reporting this bug.</simpara>
1131 </listitem>
1132 <listitem>
1133 <simpara>
1134 <anchor id="Bugs20041109_bug02" xreflabel="[Bugs20041109_bug02]"/>
1135 <literal>BinIO.getInstream</literal> and <literal>TextIO.getInstream</literal> are
1136 implemented incorrectly. This also impacts the behavior of
1137 <literal>BinIO.scanStream</literal> and <literal>TextIO.scanStream</literal>. If you (directly
1138 or indirectly) realize a <literal>TextIO.StreamIO.instream</literal> and do not
1139 (directly or indirectly) call <literal>TextIO.setInstream</literal> with a derived
1140 stream, you may lose input data. We have fixed the problem in our
1141 CVS.
1142 </simpara>
1143 <simpara>Thanks to <link linkend="WesleyTerpstra">WesleyTerpstra</link> for reporting this bug.</simpara>
1144 </listitem>
1145 <listitem>
1146 <simpara>
1147 <anchor id="Bugs20041109_bug01" xreflabel="[Bugs20041109_bug01]"/>
1148 <literal>Posix.ProcEnv.setpgid</literal> doesn&#8217;t work. If you compile a program
1149 that uses it, you will get a link time error
1150 </simpara>
1151 <screen>undefined reference to `Posix_ProcEnv_setpgid'</screen>
1152 <simpara>The bug is due to <literal>Posix_ProcEnv_setpgid</literal> being omitted from the
1153 MLton runtime. We fixed the problem in our CVS by adding the
1154 following definition to <literal>runtime/Posix/ProcEnv/ProcEnv.c</literal></simpara>
1155 <programlisting language="c" linenumbering="unnumbered">Int Posix_ProcEnv_setpgid (Pid p, Gid g) {
1156 return setpgid (p, g);
1157 }</programlisting>
1158 <simpara>Thanks to Tom Murphy for reporting this bug.</simpara>
1159 </listitem>
1160 </itemizedlist>
1161 <simpara><?asciidoc-pagebreak?></simpara>
1162 </section>
1163 <section id="Bugs20051202">
1164 <title>Bugs20051202</title>
1165 <simpara>Here are the known bugs in <link linkend="Release20051202">MLton 20051202</link>, listed
1166 in reverse chronological order of date reported.</simpara>
1167 <itemizedlist>
1168 <listitem>
1169 <simpara>
1170 <anchor id="Bugs20051202_bug16" xreflabel="[Bugs20051202_bug16]"/>
1171 Bug in the <ulink url="http://www.standardml.org/Basis/real.html#SIG:REAL.fmt:VAL"><literal>Real<emphasis>&lt;N&gt;</emphasis>.fmt</literal></ulink>, <ulink url="http://www.standardml.org/Basis/real.html#SIG:REAL.fromString:VAL"><literal>Real<emphasis>&lt;N&gt;</emphasis>.fromString</literal></ulink>, <ulink url="http://www.standardml.org/Basis/real.html#SIG:REAL.scan:VAL"><literal>Real<emphasis>&lt;N&gt;</emphasis>.scan</literal></ulink>, and <ulink url="http://www.standardml.org/Basis/real.html#SIG:REAL.toString:VAL"><literal>Real<emphasis>&lt;N&gt;</emphasis>.toString</literal></ulink> functions of the <link linkend="BasisLibrary">Basis Library</link> implementation. These functions were using <literal>TO_NEAREST</literal> semantics, but should obey the current rounding mode. (Only <literal>Real<emphasis>&lt;N&gt;</emphasis>.fmt StringCvt.EXACT</literal>, <literal>Real<emphasis>&lt;N&gt;</emphasis>.fromDecimal</literal>, and <literal>Real<emphasis>&lt;N&gt;</emphasis>.toDecimal</literal> are specified to override the current rounding mode with <literal>TO_NEAREST</literal> semantics.)
1172 </simpara>
1173 <simpara>Thanks to Sean McLaughlin for the bug report.</simpara>
1174 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r5827"><literal>r5827</literal></ulink>.</simpara>
1175 </listitem>
1176 <listitem>
1177 <simpara>
1178 <anchor id="Bugs20051202_bug15" xreflabel="[Bugs20051202_bug15]"/>
1179 Bug in the treatment of floating-point operations. Floating-point operations depend on the current rounding mode, but were being treated as pure.
1180 </simpara>
1181 <simpara>Thanks to Sean McLaughlin for the bug report.</simpara>
1182 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r5794"><literal>r5794</literal></ulink>.</simpara>
1183 </listitem>
1184 <listitem>
1185 <simpara>
1186 <anchor id="Bugs20051202_bug14" xreflabel="[Bugs20051202_bug14]"/>
1187 Bug in the <ulink url="http://www.standardml.org/Basis/real.html#SIG:REAL.toInt:VAL"><literal>Real32.toInt</literal></ulink> function of the <link linkend="BasisLibrary">Basis Library</link> implementation could lead incorrect results when applied to a <literal>Real32.real</literal> value numerically close to <literal>valOf(Int.maxInt)</literal>.
1188 </simpara>
1189 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r5764"><literal>r5764</literal></ulink>.</simpara>
1190 </listitem>
1191 <listitem>
1192 <simpara>
1193 <anchor id="Bugs20051202_bug13" xreflabel="[Bugs20051202_bug13]"/>
1194 The <ulink url="http://www.standardml.org/Basis/socket.html"><literal>Socket</literal></ulink> structure of the <link linkend="BasisLibrary">Basis Library</link> implementation used <literal>andb</literal> rather than <literal>orb</literal> to unmarshal socket options (for <literal>Socket.Ctl.get<emphasis>&lt;OPT&gt;</emphasis></literal> functions).
1195 </simpara>
1196 <simpara>Thanks to Anders Petersson for the bug report and patch.</simpara>
1197 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r5735"><literal>r5735</literal></ulink>.</simpara>
1198 </listitem>
1199 <listitem>
1200 <simpara>
1201 <anchor id="Bugs20051202_bug12" xreflabel="[Bugs20051202_bug12]"/>
1202 Bug in the <ulink url="http://www.standardml.org/Basis/date.html"><literal>Date</literal></ulink> structure of the <link linkend="BasisLibrary">Basis Library</link> implementation yielded some functions that would erroneously raise <literal>Date</literal> when applied to a year before 1900.
1203 </simpara>
1204 <simpara>Thanks to Joe Hurd for the bug report.</simpara>
1205 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r5732"><literal>r5732</literal></ulink>.</simpara>
1206 </listitem>
1207 <listitem>
1208 <simpara>
1209 <anchor id="Bugs20051202_bug11" xreflabel="[Bugs20051202_bug11]"/>
1210 Bug in monomorphisation pass could exhibit the error <literal>Type error: type mismatch</literal>.
1211 </simpara>
1212 <simpara>Thanks to Vesa Karvonen for the bug report.</simpara>
1213 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r5731"><literal>r5731</literal></ulink>.</simpara>
1214 </listitem>
1215 <listitem>
1216 <simpara>
1217 <anchor id="Bugs20051202_bug10" xreflabel="[Bugs20051202_bug10]"/>
1218 The <ulink url="http://www.standardml.org/Basis/pack-float.html#SIG:PACK_REAL.toBytes:VAL"><literal>PackReal<emphasis>&lt;N&gt;</emphasis>.toBytes</literal></ulink> function in the <link linkend="BasisLibrary">Basis Library</link> implementation incorrectly shared (and mutated) the result vector.
1219 </simpara>
1220 <simpara>Thanks to Eric McCorkle for the bug report and patch.</simpara>
1221 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r5281"><literal>r5281</literal></ulink>.</simpara>
1222 </listitem>
1223 <listitem>
1224 <simpara>
1225 <anchor id="Bugs20051202_bug09" xreflabel="[Bugs20051202_bug09]"/>
1226 Bug in elaboration of FFI forms. Using a unary FFI types (e.g., <literal>array</literal>, <literal>ref</literal>, <literal>vector</literal>) in places where <literal>MLton.Pointer.t</literal> was required would lead to an internal error <literal>TypeError</literal>.
1227 </simpara>
1228 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r4890"><literal>r4890</literal></ulink>.</simpara>
1229 </listitem>
1230 <listitem>
1231 <simpara>
1232 <anchor id="Bugs20051202_bug08" xreflabel="[Bugs20051202_bug08]"/>
1233 The <ulink url="http://www.standardml.org/Basis/mono-vector.html"><literal>MONO_VECTOR</literal></ulink> signature of the <link linkend="BasisLibrary">Basis Library</link> implementation incorrectly omits the specification of <literal>find</literal>.
1234 </simpara>
1235 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r4707"><literal>r4707</literal></ulink>.</simpara>
1236 </listitem>
1237 <listitem>
1238 <simpara>
1239 <anchor id="Bugs20051202_bug07" xreflabel="[Bugs20051202_bug07]"/>
1240 The optimizer reports an internal error (<literal>TypeError</literal>) when an imported C function is called but not used.
1241 </simpara>
1242 <simpara>Thanks to "jq" for the bug report.</simpara>
1243 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r4690"><literal>r4690</literal></ulink>.</simpara>
1244 </listitem>
1245 <listitem>
1246 <simpara>
1247 <anchor id="Bugs20051202_bug06" xreflabel="[Bugs20051202_bug06]"/>
1248 Bug in pass to flatten data structures.
1249 </simpara>
1250 <simpara>Thanks to Joe Hurd for the bug report.</simpara>
1251 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r4662"><literal>r4662</literal></ulink>.</simpara>
1252 </listitem>
1253 <listitem>
1254 <simpara>
1255 <anchor id="Bugs20051202_bug05" xreflabel="[Bugs20051202_bug05]"/>
1256 The native codegen&#8217;s implementation of the C-calling convention failed to widen 16-bit arguments to 32-bits.
1257 </simpara>
1258 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r4631"><literal>r4631</literal></ulink>.</simpara>
1259 </listitem>
1260 <listitem>
1261 <simpara>
1262 <anchor id="Bugs20051202_bug04" xreflabel="[Bugs20051202_bug04]"/>
1263 The <ulink url="http://www.standardml.org/Basis/pack-float.html"><literal>PACK_REAL</literal></ulink> structures of the <link linkend="BasisLibrary">Basis Library</link> implementation used byte, rather than element, indexing.
1264 </simpara>
1265 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r4411"><literal>r4411</literal></ulink>.</simpara>
1266 </listitem>
1267 <listitem>
1268 <simpara>
1269 <anchor id="Bugs20051202_bug03" xreflabel="[Bugs20051202_bug03]"/>
1270 <literal>MLton.share</literal> could cause a segmentation fault.
1271 </simpara>
1272 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r4400"><literal>r4400</literal></ulink>.</simpara>
1273 </listitem>
1274 <listitem>
1275 <simpara>
1276 <anchor id="Bugs20051202_bug02" xreflabel="[Bugs20051202_bug02]"/>
1277 The SSA simplifier could eliminate an irredundant test.
1278 </simpara>
1279 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r4370"><literal>r4370</literal></ulink>.</simpara>
1280 </listitem>
1281 <listitem>
1282 <simpara>
1283 <anchor id="Bugs20051202_bug01" xreflabel="[Bugs20051202_bug01]"/>
1284 A program with a very large number of functors could exhibit the error <literal>ElaborateEnv.functorClosure: firstTycons</literal>.
1285 </simpara>
1286 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r4344"><literal>r4344</literal></ulink>.</simpara>
1287 </listitem>
1288 </itemizedlist>
1289 <simpara><?asciidoc-pagebreak?></simpara>
1290 </section>
1291 <section id="Bugs20070826">
1292 <title>Bugs20070826</title>
1293 <simpara>Here are the known bugs in <link linkend="Release20070826">MLton 20070826</link>, listed
1294 in reverse chronological order of date reported.</simpara>
1295 <itemizedlist>
1296 <listitem>
1297 <simpara>
1298 <anchor id="Bugs20070826_bug25" xreflabel="[Bugs20070826_bug25]"/>
1299 Bug in the mark-compact garbage collector where the C library&#8217;s <literal>memcpy</literal> was used to move objects during the compaction phase; this could lead to heap corruption and segmentation faults with newer versions of gcc and/or glibc, which assume that src and dst in a <literal>memcpy</literal> do not overlap.
1300 </simpara>
1301 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7461"><literal>r7461</literal></ulink>.</simpara>
1302 </listitem>
1303 <listitem>
1304 <simpara>
1305 <anchor id="Bugs20070826_bug24" xreflabel="[Bugs20070826_bug24]"/>
1306 Bug in elaboration of <literal>datatype</literal> declarations with <literal>withtype</literal> bindings.
1307 </simpara>
1308 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7434"><literal>r7434</literal></ulink>.</simpara>
1309 </listitem>
1310 <listitem>
1311 <simpara>
1312 <anchor id="Bugs20070826_bug23" xreflabel="[Bugs20070826_bug23]"/>
1313 Performance bug in <link linkend="RefFlatten">RefFlatten</link> optimization pass.
1314 </simpara>
1315 <simpara>Thanks to Reactive Systems for the bug report.</simpara>
1316 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7379"><literal>r7379</literal></ulink>.</simpara>
1317 </listitem>
1318 <listitem>
1319 <simpara>
1320 <anchor id="Bugs20070826_bug22" xreflabel="[Bugs20070826_bug22]"/>
1321 Performance bug in <link linkend="SimplifyTypes">SimplifyTypes</link> optimization pass.
1322 </simpara>
1323 <simpara>Thanks to Reactive Systems for the bug report.</simpara>
1324 <simpara>Fixed by revisions <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7377"><literal>r7377</literal></ulink> and <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7378"><literal>r7378</literal></ulink>.</simpara>
1325 </listitem>
1326 <listitem>
1327 <simpara>
1328 <anchor id="Bugs20070826_bug21" xreflabel="[Bugs20070826_bug21]"/>
1329 Bug in amd64 codegen register allocation of indirect C calls.
1330 </simpara>
1331 <simpara>Thanks to David Hansel for the bug report.</simpara>
1332 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7368"><literal>r7368</literal></ulink>.</simpara>
1333 </listitem>
1334 <listitem>
1335 <simpara>
1336 <anchor id="Bugs20070826_bug20" xreflabel="[Bugs20070826_bug20]"/>
1337 Bug in <literal>IntInf.scan</literal> and <literal>IntInf.fromString</literal> where leading spaces were only accepted if the stream had an explicit sign character.
1338 </simpara>
1339 <simpara>Thanks to David Hansel for the bug report.</simpara>
1340 <simpara>Fixed by revisions <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7227"><literal>r7227</literal></ulink> and <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7230"><literal>r7230</literal></ulink>.</simpara>
1341 </listitem>
1342 <listitem>
1343 <simpara>
1344 <anchor id="Bugs20070826_bug19" xreflabel="[Bugs20070826_bug19]"/>
1345 Bug in <literal>IntInf.~&gt;&gt;</literal> that could cause a <literal>glibc</literal> assertion.
1346 </simpara>
1347 <simpara>Fixed by revisions <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7083"><literal>r7083</literal></ulink>, <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7084"><literal>r7084</literal></ulink>, and <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7085"><literal>r7085</literal></ulink>.</simpara>
1348 </listitem>
1349 <listitem>
1350 <simpara>
1351 <anchor id="Bugs20070826_bug18" xreflabel="[Bugs20070826_bug18]"/>
1352 Bug in the return type of <literal>MLton.Process.reap</literal>.
1353 </simpara>
1354 <simpara>Thanks to Risto Saarelma for the bug report.</simpara>
1355 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7029"><literal>r7029</literal></ulink>.</simpara>
1356 </listitem>
1357 <listitem>
1358 <simpara>
1359 <anchor id="Bugs20070826_bug17" xreflabel="[Bugs20070826_bug17]"/>
1360 Bug in <literal>MLton.size</literal> and <literal>MLton.share</literal> when tracing the current stack.
1361 </simpara>
1362 <simpara>Fixed by revisions <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6978"><literal>r6978</literal></ulink>, <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6981"><literal>r6981</literal></ulink>, <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6988"><literal>r6988</literal></ulink>, <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6989"><literal>r6989</literal></ulink>, and <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6990"><literal>r6990</literal></ulink>.</simpara>
1363 </listitem>
1364 <listitem>
1365 <simpara>
1366 <anchor id="Bugs20070826_bug16" xreflabel="[Bugs20070826_bug16]"/>
1367 Bug in nested <literal>_export</literal>/<literal>_import</literal> functions.
1368 </simpara>
1369 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6919"><literal>r6919</literal></ulink>.</simpara>
1370 </listitem>
1371 <listitem>
1372 <simpara>
1373 <anchor id="Bugs20070826_bug15" xreflabel="[Bugs20070826_bug15]"/>
1374 Bug in the name mangling of <literal>_import</literal>-ed functions with the <literal>stdcall</literal> convention.
1375 </simpara>
1376 <simpara>Thanks to Lars Bergstrom for the bug report.</simpara>
1377 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6672"><literal>r6672</literal></ulink>.</simpara>
1378 </listitem>
1379 <listitem>
1380 <simpara>
1381 <anchor id="Bugs20070826_bug14" xreflabel="[Bugs20070826_bug14]"/>
1382 Bug in Windows code to page the heap to disk when unable to grow the heap to a desired size.
1383 </simpara>
1384 <simpara>Thanks to Sami Evangelista for the bug report.</simpara>
1385 <simpara>Fixed by revisions <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6600"><literal>r6600</literal></ulink> and <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6624"><literal>r6624</literal></ulink>.</simpara>
1386 </listitem>
1387 <listitem>
1388 <simpara>
1389 <anchor id="Bugs20070826_bug13" xreflabel="[Bugs20070826_bug13]"/>
1390 Bug in \*NIX code to page the heap to disk when unable to grow the heap to a desired size.
1391 </simpara>
1392 <simpara>Thanks to Nicolas Bertolotti for the bug report and patch.</simpara>
1393 <simpara>Fixed by revisions <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6596"><literal>r6596</literal></ulink> and <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6600"><literal>r6600</literal></ulink>.</simpara>
1394 </listitem>
1395 <listitem>
1396 <simpara>
1397 <anchor id="Bugs20070826_bug12" xreflabel="[Bugs20070826_bug12]"/>
1398 Space-safety bug in pass to <link linkend="RefFlatten">flatten refs</link> into containing data structure.
1399 </simpara>
1400 <simpara>Thanks to Daniel Spoonhower for the bug report and initial diagnosis and patch.</simpara>
1401 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6395"><literal>r6395</literal></ulink>.</simpara>
1402 </listitem>
1403 <listitem>
1404 <simpara>
1405 <anchor id="Bugs20070826_bug11" xreflabel="[Bugs20070826_bug11]"/>
1406 Bug in the frontend that rejected <literal>op longvid</literal> patterns and expressions.
1407 </simpara>
1408 <simpara>Thanks to Florian Weimer for the bug report.</simpara>
1409 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6347"><literal>r6347</literal></ulink>.</simpara>
1410 </listitem>
1411 <listitem>
1412 <simpara>
1413 <anchor id="Bugs20070826_bug10" xreflabel="[Bugs20070826_bug10]"/>
1414 Bug in the <ulink url="http://www.standardml.org/Basis/imperative-io.html#SIG:IMPERATIVE_IO.canInput:VAL"><literal>IMPERATIVE_IO.canInput</literal></ulink> function of the <link linkend="BasisLibrary">Basis Library</link> implementation.
1415 </simpara>
1416 <simpara>Thanks to Ville Laurikari for the bug report.</simpara>
1417 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6261"><literal>r6261</literal></ulink>.</simpara>
1418 </listitem>
1419 <listitem>
1420 <simpara>
1421 <anchor id="Bugs20070826_bug09" xreflabel="[Bugs20070826_bug09]"/>
1422 Bug in algebraic simplification of real primitives. <ulink url="http://www.standardml.org/Basis/real.html#SIG:REAL.\|@LTE\|:VAL"><literal>REAL<emphasis>&lt;N&gt;</emphasis>.&lt;=(x, x)</literal></ulink> is <literal>false</literal> when <literal>x</literal> is NaN.
1423 </simpara>
1424 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6242"><literal>r6242</literal></ulink>.</simpara>
1425 </listitem>
1426 <listitem>
1427 <simpara>
1428 <anchor id="Bugs20070826_bug08" xreflabel="[Bugs20070826_bug08]"/>
1429 Bug in the FFI visible representation of <literal>Int16.int ref</literal> (and references of other primitive types smaller than 32-bits) on big-endian platforms.
1430 </simpara>
1431 <simpara>Thanks to Dave Herman for the bug report.</simpara>
1432 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6267"><literal>r6267</literal></ulink>.</simpara>
1433 </listitem>
1434 <listitem>
1435 <simpara>
1436 <anchor id="Bugs20070826_bug07" xreflabel="[Bugs20070826_bug07]"/>
1437 Bug in type inference of flexible records. This would later cause the compiler to raise the <literal>TypeError</literal> exception.
1438 </simpara>
1439 <simpara>Thanks to Wesley Terpstra for the bug report.</simpara>
1440 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6229"><literal>r6229</literal></ulink>.</simpara>
1441 </listitem>
1442 <listitem>
1443 <simpara>
1444 <anchor id="Bugs20070826_bug06" xreflabel="[Bugs20070826_bug06]"/>
1445 Bug in cross-compilation of <literal>gdtoa</literal> library.
1446 </simpara>
1447 <simpara>Thanks to Wesley Terpstra for the bug report and patch.</simpara>
1448 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6620"><literal>r6620</literal></ulink>.</simpara>
1449 </listitem>
1450 <listitem>
1451 <simpara>
1452 <anchor id="Bugs20070826_bug05" xreflabel="[Bugs20070826_bug05]"/>
1453 Bug in pass to <link linkend="RefFlatten">flatten refs</link> into containing data structure.
1454 </simpara>
1455 <simpara>Thanks to Ruy Ley-Wild for the bug report.</simpara>
1456 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6191"><literal>r6191</literal></ulink>.</simpara>
1457 </listitem>
1458 <listitem>
1459 <simpara>
1460 <anchor id="Bugs20070826_bug04" xreflabel="[Bugs20070826_bug04]"/>
1461 Bug in the handling of weak pointers by the mark-compact garbage collector.
1462 </simpara>
1463 <simpara>Thanks to Sean McLaughlin for the bug report and Florian Weimer for the initial diagnosis.</simpara>
1464 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6183"><literal>r6183</literal></ulink>.</simpara>
1465 </listitem>
1466 <listitem>
1467 <simpara>
1468 <anchor id="Bugs20070826_bug03" xreflabel="[Bugs20070826_bug03]"/>
1469 Bug in the elaboration of structures with signature constraints. This would later cause the compiler to raise the <literal>TypeError</literal> exception.
1470 </simpara>
1471 <simpara>Thanks to Vesa Karvonen for the bug report.</simpara>
1472 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6046"><literal>r6046</literal></ulink>.</simpara>
1473 </listitem>
1474 <listitem>
1475 <simpara>
1476 <anchor id="Bugs20070826_bug02" xreflabel="[Bugs20070826_bug02]"/>
1477 Bug in the interaction of <literal>_export</literal>-ed functions and signal handlers.
1478 </simpara>
1479 <simpara>Thanks to Sean McLaughlin for the bug report.</simpara>
1480 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6013"><literal>r6013</literal></ulink>.</simpara>
1481 </listitem>
1482 <listitem>
1483 <simpara>
1484 <anchor id="Bugs20070826_bug01" xreflabel="[Bugs20070826_bug01]"/>
1485 Bug in the implementation of <literal>_export</literal>-ed functions using the <literal>char</literal> type, leading to a linker error.
1486 </simpara>
1487 <simpara>Thanks to Katsuhiro Ueno for the bug report.</simpara>
1488 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r5999"><literal>r5999</literal></ulink>.</simpara>
1489 </listitem>
1490 </itemizedlist>
1491 <simpara><?asciidoc-pagebreak?></simpara>
1492 </section>
1493 <section id="Bugs20100608">
1494 <title>Bugs20100608</title>
1495 <simpara>Here are the known bugs in <link linkend="Release20100608">MLton 20100608</link>, listed
1496 in reverse chronological order of date reported.</simpara>
1497 <itemizedlist>
1498 <listitem>
1499 <simpara>
1500 <anchor id="Bugs20100608_bug11" xreflabel="[Bugs20100608_bug11]"/>
1501 Bugs in <literal>REAL.signBit</literal>, <literal>REAL.copySign</literal>, and <literal>REAL.toDecimal</literal>/<literal>REAL.fromDecimal</literal>.
1502 </simpara>
1503 <simpara>Thanks to Phil Clayton for the bug report and examples.</simpara>
1504 <simpara>Fixed by revisions <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7571"><literal>r7571</literal></ulink>, <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7572"><literal>r7572</literal></ulink>, and <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7573"><literal>r7573</literal></ulink>.</simpara>
1505 </listitem>
1506 <listitem>
1507 <simpara>
1508 <anchor id="Bugs20100608_bug10" xreflabel="[Bugs20100608_bug10]"/>
1509 Bug in elaboration of type variables with and without equality status.
1510 </simpara>
1511 <simpara>Thanks to Rob Simmons for the bug report and examples.</simpara>
1512 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7565"><literal>r7565</literal></ulink>.</simpara>
1513 </listitem>
1514 <listitem>
1515 <simpara>
1516 <anchor id="Bugs20100608_bug09" xreflabel="[Bugs20100608_bug09]"/>
1517 Bug in <link linkend="Redundant">redundant</link> <link linkend="SSA">SSA</link> optimization.
1518 </simpara>
1519 <simpara>Thanks to Lars Magnusson for the bug report and example.</simpara>
1520 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7561"><literal>r7561</literal></ulink>.</simpara>
1521 </listitem>
1522 <listitem>
1523 <simpara>
1524 <anchor id="Bugs20100608_bug08" xreflabel="[Bugs20100608_bug08]"/>
1525 Bug in <link linkend="SSA">SSA</link>/<link linkend="SSA2">SSA2</link> <link linkend="Shrink">shrinker</link> that could erroneously turn a non-tail function call with a <literal>Bug</literal> transfer as its continuation into a tail function call.
1526 </simpara>
1527 <simpara>Thanks to Lars Bergstrom for the bug report.</simpara>
1528 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7546"><literal>r7546</literal></ulink>.</simpara>
1529 </listitem>
1530 <listitem>
1531 <simpara>
1532 <anchor id="Bugs20100608_bug07" xreflabel="[Bugs20100608_bug07]"/>
1533 Bug in translation from <link linkend="SSA2">SSA2</link> to <link linkend="RSSA">RSSA</link> with <literal>case</literal> expressions over non-primitive-sized words.
1534 </simpara>
1535 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7544"><literal>r7544</literal></ulink>.</simpara>
1536 </listitem>
1537 <listitem>
1538 <simpara>
1539 <anchor id="Bugs20100608_bug06" xreflabel="[Bugs20100608_bug06]"/>
1540 Bug with <link linkend="SSA">SSA</link>/<link linkend="SSA2">SSA2</link> type checking of case expressions over words.
1541 </simpara>
1542 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7542"><literal>r7542</literal></ulink>.</simpara>
1543 </listitem>
1544 <listitem>
1545 <simpara>
1546 <anchor id="Bugs20100608_bug05" xreflabel="[Bugs20100608_bug05]"/>
1547 Bug with treatment of <literal>as</literal>-patterns, which should not allow the redefinition of constructor status.
1548 </simpara>
1549 <simpara>Thanks to Michael Norrish for the bug report.</simpara>
1550 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7530"><literal>r7530</literal></ulink>.</simpara>
1551 </listitem>
1552 <listitem>
1553 <simpara>
1554 <anchor id="Bugs20100608_bug04" xreflabel="[Bugs20100608_bug04]"/>
1555 Bug with treatment of <literal>nan</literal> in <link linkend="CommonSubexp">common subexpression elimination</link> <link linkend="SSA">SSA</link> optimization.
1556 </simpara>
1557 <simpara>Thanks to Alexandre Hamez for the bug report.</simpara>
1558 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7503"><literal>r7503</literal></ulink>.</simpara>
1559 </listitem>
1560 <listitem>
1561 <simpara>
1562 <anchor id="Bugs20100608_bug03" xreflabel="[Bugs20100608_bug03]"/>
1563 Bug in translation from <link linkend="SSA2">SSA2</link> to <link linkend="RSSA">RSSA</link> with weak pointers.
1564 </simpara>
1565 <simpara>Thanks to Alexandre Hamez for the bug report.</simpara>
1566 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7502"><literal>r7502</literal></ulink>.</simpara>
1567 </listitem>
1568 <listitem>
1569 <simpara>
1570 <anchor id="Bugs20100608_bug02" xreflabel="[Bugs20100608_bug02]"/>
1571 Bug in amd64 codegen calling convention for varargs C calls.
1572 </simpara>
1573 <simpara>Thanks to <link linkend="HenryCejtin">HenryCejtin</link> for the bug report and <link linkend="WesleyTerpstra">WesleyTerpstra</link> for the initial diagnosis.</simpara>
1574 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7501"><literal>r7501</literal></ulink>.</simpara>
1575 </listitem>
1576 <listitem>
1577 <simpara>
1578 <anchor id="Bugs20100608_bug01" xreflabel="[Bugs20100608_bug01]"/>
1579 Bug in comment-handling in lexer for <link linkend="MLYacc">MLYacc</link>'s input language.
1580 </simpara>
1581 <simpara>Thanks to Michael Norrish for the bug report and patch.</simpara>
1582 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r7500"><literal>r7500</literal></ulink>.</simpara>
1583 </listitem>
1584 <listitem>
1585 <simpara>
1586 <anchor id="Bugs20100608_bug00" xreflabel="[Bugs20100608_bug00]"/>
1587 Bug in elaboration of function clauses with different numbers of arguments that would raise an uncaught <literal>Subscript</literal> exception.
1588 </simpara>
1589 <simpara>Fixed by revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r75497"><literal>r75497</literal></ulink>.</simpara>
1590 </listitem>
1591 </itemizedlist>
1592 <simpara><?asciidoc-pagebreak?></simpara>
1593 </section>
1594 <section id="Bugs20130715">
1595 <title>Bugs20130715</title>
1596 <simpara>Here are the known bugs in <link linkend="Release20130715">MLton 20130715</link>, listed
1597 in reverse chronological order of date reported.</simpara>
1598 <itemizedlist>
1599 <listitem>
1600 <simpara>
1601 <anchor id="Bugs20130715_bug06" xreflabel="[Bugs20130715_bug06]"/>
1602 Bug with simultaneous <literal>sharing</literal> of multiple structures.
1603 </simpara>
1604 <simpara>Fixed by commit <ulink url="https://github.com/MLton/mlton/commit/9cb5164f6"><literal>9cb5164f6</literal></ulink>.</simpara>
1605 </listitem>
1606 <listitem>
1607 <simpara>
1608 <anchor id="Bugs20130715_bug05" xreflabel="[Bugs20130715_bug05]"/>
1609 Minor bug with exception replication.
1610 </simpara>
1611 <simpara>Fixed by commit <ulink url="https://github.com/MLton/mlton/commit/1c89c42f6"><literal>1c89c42f6</literal></ulink>.</simpara>
1612 </listitem>
1613 <listitem>
1614 <simpara>
1615 <anchor id="Bugs20130715_bug04" xreflabel="[Bugs20130715_bug04]"/>
1616 Minor bug erroneously accepting symbolic identifiers for strid, sigid, and fctid
1617 and erroneously accepting symbolic identifiers before <literal>.</literal> in long identifiers.
1618 </simpara>
1619 <simpara>Fixed by commit <ulink url="https://github.com/MLton/mlton/commit/9a56be647"><literal>9a56be647</literal></ulink>.</simpara>
1620 </listitem>
1621 <listitem>
1622 <simpara>
1623 <anchor id="Bugs20130715_bug03" xreflabel="[Bugs20130715_bug03]"/>
1624 Minor bug in precedence parsing of function clauses.
1625 </simpara>
1626 <simpara>Fixed by commit <ulink url="https://github.com/MLton/mlton/commit/1a6d25ec9"><literal>1a6d25ec9</literal></ulink>.</simpara>
1627 </listitem>
1628 <listitem>
1629 <simpara>
1630 <anchor id="Bugs20130715_bug02" xreflabel="[Bugs20130715_bug02]"/>
1631 Performance bug in creation of worker threads to service calls of <literal>_export</literal>-ed
1632 functions.
1633 </simpara>
1634 <simpara>Thanks to Bernard Berthomieu for the bug report.</simpara>
1635 <simpara>Fixed by commit <ulink url="https://github.com/MLton/mlton/commit/97c2bdf1d"><literal>97c2bdf1d</literal></ulink>.</simpara>
1636 </listitem>
1637 <listitem>
1638 <simpara>
1639 <anchor id="Bugs20130715_bug01" xreflabel="[Bugs20130715_bug01]"/>
1640 Bug in <literal>MLton.IntInf.fromRep</literal> that could yield values that violate the <literal>IntInf</literal>
1641 representation invariants.
1642 </simpara>
1643 <simpara>Thanks to Rob Simmons for the bug report.</simpara>
1644 <simpara>Fixed by commit <ulink url="https://github.com/MLton/mlton/commit/3add91eda"><literal>3add91eda</literal></ulink>.</simpara>
1645 </listitem>
1646 <listitem>
1647 <simpara>
1648 <anchor id="Bugs20130715_bug00" xreflabel="[Bugs20130715_bug00]"/>
1649 Bug in equality status of some arrays, vectors, and slices in Basis Library
1650 implementation.
1651 </simpara>
1652 <simpara>Fixed by commit <ulink url="https://github.com/MLton/mlton/commit/a7ed9cbf1"><literal>a7ed9cbf1</literal></ulink>.</simpara>
1653 </listitem>
1654 </itemizedlist>
1655 <simpara><?asciidoc-pagebreak?></simpara>
1656 </section>
1657 <section id="Bugs20180207">
1658 <title>Bugs20180207</title>
1659 <simpara>Here are the known bugs in <link linkend="Release20180207">MLton 20180207</link>, listed
1660 in reverse chronological order of date reported.</simpara>
1661 <simpara><?asciidoc-pagebreak?></simpara>
1662 </section>
1663 <section id="CallGraph">
1664 <title>CallGraph</title>
1665 <simpara>For easier visualization of <link linkend="Profiling">profiling</link> data, <literal>mlprof</literal> can
1666 create a call graph of the program in dot format, from which you can
1667 use the <ulink url="http://www.research.att.com/sw/tools/graphviz/">graphviz</ulink>
1668 software package to create a PostScript or PNG graph. For example,</simpara>
1669 <screen>mlprof -call-graph foo.dot foo mlmon.out</screen>
1670 <simpara>will create <literal>foo.dot</literal> with a complete call graph. For each source
1671 function, there will be one node in the graph that contains the
1672 function name (and source position with <literal>-show-line true</literal>), as
1673 well as the percentage of ticks. If you want to create a call graph
1674 for your program without any profiling data, you can simply call
1675 <literal>mlprof</literal> without any <literal>mlmon.out</literal> files, as in</simpara>
1676 <screen>mlprof -call-graph foo.dot foo</screen>
1677 <simpara>Because SML has higher-order functions, the call graph is is dependent
1678 on MLton&#8217;s analysis of which functions call each other. This analysis
1679 depends on many implementation details and might display spurious
1680 edges that a human could conclude are impossible. However, in
1681 practice, the call graphs tend to be very accurate.</simpara>
1682 <simpara>Because call graphs can get big, <literal>mlprof</literal> provides the <literal>-keep</literal> option
1683 to specify the nodes that you would like to see. This option also
1684 controls which functions appear in the table that <literal>mlprof</literal> prints.
1685 The argument to <literal>-keep</literal> is an expression describing a set of source
1686 functions (i.e. graph nodes). The expression <emphasis>e</emphasis> should be of the
1687 following form.</simpara>
1688 <itemizedlist>
1689 <listitem>
1690 <simpara>
1691 <literal>all</literal>
1692 </simpara>
1693 </listitem>
1694 <listitem>
1695 <simpara>
1696 <literal>"<emphasis>s</emphasis>"</literal>
1697 </simpara>
1698 </listitem>
1699 <listitem>
1700 <simpara>
1701 <literal>(and <emphasis>e &#8230;</emphasis>)</literal>
1702 </simpara>
1703 </listitem>
1704 <listitem>
1705 <simpara>
1706 <literal>(from <emphasis>e</emphasis>)</literal>
1707 </simpara>
1708 </listitem>
1709 <listitem>
1710 <simpara>
1711 <literal>(not <emphasis>e</emphasis>)</literal>
1712 </simpara>
1713 </listitem>
1714 <listitem>
1715 <simpara>
1716 <literal>(or <emphasis>e</emphasis>)</literal>
1717 </simpara>
1718 </listitem>
1719 <listitem>
1720 <simpara>
1721 <literal>(pred <emphasis>e</emphasis>)</literal>
1722 </simpara>
1723 </listitem>
1724 <listitem>
1725 <simpara>
1726 <literal>(succ <emphasis>e</emphasis>)</literal>
1727 </simpara>
1728 </listitem>
1729 <listitem>
1730 <simpara>
1731 <literal>(thresh <emphasis>x</emphasis>)</literal>
1732 </simpara>
1733 </listitem>
1734 <listitem>
1735 <simpara>
1736 <literal>(thresh-gc <emphasis>x</emphasis>)</literal>
1737 </simpara>
1738 </listitem>
1739 <listitem>
1740 <simpara>
1741 <literal>(thresh-stack <emphasis>x</emphasis>)</literal>
1742 </simpara>
1743 </listitem>
1744 <listitem>
1745 <simpara>
1746 <literal>(to <emphasis>e</emphasis>)</literal>
1747 </simpara>
1748 </listitem>
1749 </itemizedlist>
1750 <simpara>In the grammar, <literal>all</literal> denotes the set of all nodes. <literal>"<emphasis>s</emphasis>"</literal> is
1751 a regular expression denoting the set of functions whose name
1752 (followed by a space and the source position) has a prefix matching
1753 the regexp. The <literal>and</literal>, <literal>not</literal>, and <literal>or</literal> expressions denote
1754 intersection, complement, and union, respectively. The <literal>pred</literal> and
1755 <literal>succ</literal> expressions add the set of immediate predecessors or successors
1756 to their argument, respectively. The <literal>from</literal> and <literal>to</literal> expressions
1757 denote the set of nodes that have paths from or to the set of nodes
1758 denoted by their arguments, respectively. Finally, <literal>thresh</literal>,
1759 <literal>thresh-gc</literal>, and <literal>thresh-stack</literal> denote the set of nodes whose
1760 percentage of ticks, gc ticks, or stack ticks, respectively, is
1761 greater than or equal to the real number <emphasis>x</emphasis>.</simpara>
1762 <simpara>For example, if you want to see the entire call graph for a program,
1763 you can use <literal>-keep all</literal> (this is the default). If you want to see
1764 all nodes reachable from function <literal>foo</literal> in your program, you would
1765 use <literal>-keep '(from "foo")'</literal>. Or, if you want to see all the
1766 functions defined in subdirectory <literal>bar</literal> of your project that used
1767 at least 1% of the ticks, you would use</simpara>
1768 <screen>-keep '(and ".*/bar/" (thresh 1.0))'</screen>
1769 <simpara>To see all functions with ticks above a threshold, you can also use
1770 <literal>-thresh x</literal>, which is an abbreviation for <literal>-keep '(thresh x)'</literal>. You
1771 can not use multiple <literal>-keep</literal> arguments or both <literal>-keep</literal> and <literal>-thresh</literal>.
1772 When you use <literal>-keep</literal> to display a subset of the functions, <literal>mlprof</literal>
1773 will add dashed edges to the call graph to indicate a path in the
1774 original call graph from one function to another.</simpara>
1775 <simpara>When compiling with <literal>-profile-stack true</literal>, you can use <literal>mlprof -gray
1776 true</literal> to make the nodes darker or lighter depending on whether their
1777 stack percentage is higher or lower.</simpara>
1778 <simpara>MLton&#8217;s optimizer may duplicate source functions for any of a number
1779 of reasons (functor duplication, monomorphisation, polyvariance,
1780 inlining). By default, all duplicates of a function are treated as
1781 one. If you would like to treat the duplicates separately, you can
1782 use <literal>mlprof -split <emphasis>regexp</emphasis></literal>, which will cause all duplicates of
1783 functions whose name has a prefix matching the regular expression to
1784 be treated separately. This can be especially useful for higher-order
1785 utility functions like <literal>General.o</literal>.</simpara>
1786 <section id="_caveats">
1787 <title>Caveats</title>
1788 <simpara>Technically speaking, <literal>mlprof</literal> produces a call-stack graph rather than
1789 a call graph, because it describes the set of possible call stacks.
1790 The difference is in how tail calls are displayed. For example if <literal>f</literal>
1791 nontail calls <literal>g</literal> and <literal>g</literal> tail calls <literal>h</literal>, then the call-stack graph
1792 has edges from <literal>f</literal> to <literal>g</literal> and <literal>f</literal> to <literal>h</literal>, while the call graph has
1793 edges from <literal>f</literal> to <literal>g</literal> and <literal>g</literal> to <literal>h</literal>. That is, a tail call from <literal>g</literal>
1794 to <literal>h</literal> removes <literal>g</literal> from the call stack and replaces it with <literal>h</literal>.</simpara>
1795 <simpara><?asciidoc-pagebreak?></simpara>
1796 </section>
1797 </section>
1798 <section id="CallingFromCToSML">
1799 <title>CallingFromCToSML</title>
1800 <simpara>MLton&#8217;s <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link> allows programs to <emphasis>export</emphasis> SML
1801 functions to be called from C. Suppose you would like export from SML
1802 a function of type <literal>real * char -&gt; int</literal> as the C function <literal>foo</literal>.
1803 MLton extends the syntax of SML to allow expressions like the
1804 following:</simpara>
1805 <screen>_export "foo": (real * char -&gt; int) -&gt; unit;</screen>
1806 <simpara>The above expression exports a C function named <literal>foo</literal>, with
1807 prototype</simpara>
1808 <programlisting language="c" linenumbering="unnumbered">Int32 foo (Real64 x0, Char x1);</programlisting>
1809 <simpara>The <literal>_export</literal> expression denotes a function of type
1810 <literal>(real * char -&gt; int) -&gt; unit</literal> that when called with a function
1811 <literal>f</literal>, arranges for the exported <literal>foo</literal> function to call <literal>f</literal>
1812 when <literal>foo</literal> is called. So, for example, the following exports and
1813 defines <literal>foo</literal>.</simpara>
1814 <programlisting language="sml" linenumbering="unnumbered">val e = _export "foo": (real * char -&gt; int) -&gt; unit;
1815 val _ = e (fn (x, c) =&gt; 13 + Real.floor x + Char.ord c)</programlisting>
1816 <simpara>The general form of an <literal>_export</literal> expression is</simpara>
1817 <screen>_export "C function name" attr... : cFuncTy -&gt; unit;</screen>
1818 <simpara>The type and the semicolon are not optional. As with <literal>_import</literal>, a
1819 sequence of attributes may follow the function name.</simpara>
1820 <simpara>MLton&#8217;s <literal>-export-header</literal> option generates a C header file with
1821 prototypes for all of the functions exported from SML. Include this
1822 header file in your C files to type check calls to functions exported
1823 from SML. This header file includes <literal>typedef</literal>s for the
1824 <link linkend="ForeignFunctionInterfaceTypes">types that can be passed between SML and C</link>.</simpara>
1825 <section id="_example">
1826 <title>Example</title>
1827 <simpara>Suppose that <literal>export.sml</literal> is</simpara>
1828 <programlisting language="sml" linenumbering="unnumbered">val e = _export "f": (int * real * char -&gt; char) -&gt; unit;
1829 val _ = e (fn (i, r, _) =&gt;
1830 (print (concat ["i = ", Int.toString i,
1831 " r = ", Real.toString r, "\n"])
1832 ; #"g"))
1833 val g = _import "g" public reentrant: unit -&gt; unit;
1834 val _ = g ()
1835 val _ = g ()
1836
1837 val e = _export "f2": (Word8.word -&gt; word array) -&gt; unit;
1838 val _ = e (fn w =&gt;
1839 Array.tabulate (10, fn _ =&gt; Word.fromLargeWord (Word8.toLargeWord w)))
1840 val g2 = _import "g2" public reentrant: unit -&gt; word array;
1841 val a = g2 ()
1842 val _ = print (concat ["0wx", Word.toString (Array.sub (a, 0)), "\n"])
1843
1844 val e = _export "f3": (unit -&gt; unit) -&gt; unit;
1845 val _ = e (fn () =&gt; print "hello\n");
1846 val g3 = _import "g3" public reentrant: unit -&gt; unit;
1847 val _ = g3 ()
1848
1849 (* This example demonstrates mutual recursion between C and SML. *)
1850 val e = _export "f4": (int -&gt; unit) -&gt; unit;
1851 val g4 = _import "g4" public reentrant: int -&gt; unit;
1852 val _ = e (fn i =&gt; if i = 0 then () else g4 (i - 1))
1853 val _ = g4 13
1854
1855 val (_, zzzSet) = _symbol "zzz" alloc: (unit -&gt; int) * (int -&gt; unit);
1856 val () = zzzSet 42
1857 val g5 = _import "g5" public: unit -&gt; unit;
1858 val _ = g5 ()
1859
1860 val _ = print "success\n"</programlisting>
1861 <simpara>Note that the the <literal>reentrant</literal> attribute is used for <literal>_import</literal>-ing the
1862 C functions that will call the <literal>_export</literal>-ed SML functions.</simpara>
1863 <simpara>Create the header file with <literal>-export-header</literal>.</simpara>
1864 <screen>% mlton -default-ann 'allowFFI true' \
1865 -export-header export.h \
1866 -stop tc \
1867 export.sml</screen>
1868 <simpara><literal>export.h</literal> now contains the following C prototypes.</simpara>
1869 <screen>Int8 f (Int32 x0, Real64 x1, Int8 x2);
1870 Pointer f2 (Word8 x0);
1871 void f3 ();
1872 void f4 (Int32 x0);
1873 extern Int32 zzz;</screen>
1874 <simpara>Use <literal>export.h</literal> in a C program, <literal>ffi-export.c</literal>, as follows.</simpara>
1875 <programlisting language="c" linenumbering="unnumbered">#include &lt;stdio.h&gt;
1876 #include "export.h"
1877
1878 /* Functions in C are by default PUBLIC symbols */
1879 void g () {
1880 Char8 c;
1881
1882 fprintf (stderr, "g starting\n");
1883 c = f (13, 17.15, 'a');
1884 fprintf (stderr, "g done char = %c\n", c);
1885 }
1886
1887 Pointer g2 () {
1888 Pointer res;
1889 fprintf (stderr, "g2 starting\n");
1890 res = f2 (0xFF);
1891 fprintf (stderr, "g2 done\n");
1892 return res;
1893 }
1894
1895 void g3 () {
1896 fprintf (stderr, "g3 starting\n");
1897 f3 ();
1898 fprintf (stderr, "g3 done\n");
1899 }
1900
1901 void g4 (Int32 i) {
1902 fprintf (stderr, "g4 (%d)\n", i);
1903 f4 (i);
1904 }
1905
1906 void g5 () {
1907 fprintf (stderr, "g5 ()\n");
1908 fprintf (stderr, "zzz = %i\n", zzz);
1909 fprintf (stderr, "g5 done\n");
1910 }</programlisting>
1911 <simpara>Compile <literal>ffi-export.c</literal> and <literal>export.sml</literal>.</simpara>
1912 <screen>% gcc -c ffi-export.c
1913 % mlton -default-ann 'allowFFI true' \
1914 export.sml ffi-export.o</screen>
1915 <simpara>Finally, run <literal>export</literal>.</simpara>
1916 <screen>% ./export
1917 g starting
1918 ...
1919 g4 (0)
1920 success</screen>
1921 </section>
1922 <section id="_download">
1923 <title>Download</title>
1924 <itemizedlist>
1925 <listitem>
1926 <simpara>
1927 <ulink url="https://raw.github.com/MLton/mlton/master/doc/examples/ffi/export.sml"><literal>export.sml</literal></ulink>
1928 </simpara>
1929 </listitem>
1930 <listitem>
1931 <simpara>
1932 <ulink url="https://raw.github.com/MLton/mlton/master/doc/examples/ffi/ffi-export.c"><literal>ffi-export.c</literal></ulink>
1933 </simpara>
1934 </listitem>
1935 </itemizedlist>
1936 <simpara><?asciidoc-pagebreak?></simpara>
1937 </section>
1938 </section>
1939 <section id="CallingFromSMLToC">
1940 <title>CallingFromSMLToC</title>
1941 <simpara>MLton&#8217;s <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link> allows an SML program to <emphasis>import</emphasis>
1942 C functions. Suppose you would like to import from C a function with
1943 the following prototype:</simpara>
1944 <programlisting language="c" linenumbering="unnumbered">int foo (double d, char c);</programlisting>
1945 <simpara>MLton extends the syntax of SML to allow expressions like the following:</simpara>
1946 <screen>_import "foo": real * char -&gt; int;</screen>
1947 <simpara>This expression denotes a function of type <literal>real * char -&gt; int</literal> whose
1948 behavior is implemented by calling the C function whose name is <literal>foo</literal>.
1949 Thinking in terms of C, imagine that there are C variables <literal>d</literal> of type
1950 <literal>double</literal>, <literal>c</literal> of type <literal>unsigned char</literal>, and <literal>i</literal> of type <literal>int</literal>. Then,
1951 the C statement <literal>i = foo (d, c)</literal> is executed and <literal>i</literal> is returned.</simpara>
1952 <simpara>The general form of an <literal>_import</literal> expression is:</simpara>
1953 <screen>_import "C function name" attr... : cFuncTy;</screen>
1954 <simpara>The type and the semicolon are not optional.</simpara>
1955 <simpara>The function name is followed by a (possibly empty) sequence of
1956 attributes, analogous to C <literal>__attribute__</literal> specifiers.</simpara>
1957 <section id="_example_2">
1958 <title>Example</title>
1959 <simpara><literal>import.sml</literal> imports the C function <literal>ffi</literal> and the C variable <literal>FFI_INT</literal>
1960 as follows.</simpara>
1961 <programlisting language="sml" linenumbering="unnumbered">(* main.sml *)
1962
1963 (* Declare ffi to be implemented by calling the C function ffi. *)
1964 val ffi = _import "ffi" public: real array * int * int ref * char ref * int -&gt; char;
1965 open Array
1966
1967 val size = 10
1968 val a = tabulate (size, fn i =&gt; real i)
1969 val ri = ref 0
1970 val rc = ref #"0"
1971 val n = 17
1972
1973 (* Call the C function *)
1974 val c = ffi (a, Array.length a, ri, rc, n)
1975
1976 (* FFI_INT is declared as public in ffi-import.c *)
1977 val (nGet, nSet) = _symbol "FFI_INT" public: (unit -&gt; int) * (int -&gt; unit);
1978
1979 val _ = print (concat [Int.toString (nGet ()), "\n"])
1980
1981 val _ =
1982 print (if c = #"c" andalso !ri = 45 andalso !rc = c
1983 then "success\n"
1984 else "fail\n")</programlisting>
1985 <simpara><literal>ffi-import.c</literal> is</simpara>
1986 <programlisting language="c" linenumbering="unnumbered">#include "export.h"
1987
1988 Int32 FFI_INT = 13;
1989 Word32 FFI_WORD = 0xFF;
1990 Bool FFI_BOOL = 1;
1991 Real64 FFI_REAL = 3.14159;
1992
1993 Char8 ffi (Pointer a1, Int32 a1len, Pointer a2, Pointer a3, Int32 n) {
1994 double *ds = (double*)a1;
1995 int *pi = (int*)a2;
1996 char *pc = (char*)a3;
1997 int i;
1998 double sum;
1999
2000 sum = 0.0;
2001 for (i = 0; i &lt; a1len; ++i) {
2002 sum += ds[i];
2003 ds[i] += n;
2004 }
2005 *pi = (int)sum;
2006 *pc = 'c';
2007 return 'c';
2008 }</programlisting>
2009 <simpara>Compile and run the program.</simpara>
2010 <screen>% mlton -default-ann 'allowFFI true' -export-header export.h import.sml ffi-import.c
2011 % ./import
2012 13
2013 success</screen>
2014 </section>
2015 <section id="_download_2">
2016 <title>Download</title>
2017 <itemizedlist>
2018 <listitem>
2019 <simpara>
2020 <ulink url="https://raw.github.com/MLton/mlton/master/doc/examples/ffi/import.sml"><literal>import.sml</literal></ulink>
2021 </simpara>
2022 </listitem>
2023 <listitem>
2024 <simpara>
2025 <ulink url="https://raw.github.com/MLton/mlton/master/doc/examples/ffi/ffi-import.c"><literal>ffi-import.c</literal></ulink>
2026 </simpara>
2027 </listitem>
2028 </itemizedlist>
2029 </section>
2030 <section id="_next_steps_2">
2031 <title>Next Steps</title>
2032 <itemizedlist>
2033 <listitem>
2034 <simpara>
2035 <link linkend="CallingFromSMLToCFunctionPointer">CallingFromSMLToCFunctionPointer</link>
2036 </simpara>
2037 </listitem>
2038 </itemizedlist>
2039 <simpara><?asciidoc-pagebreak?></simpara>
2040 </section>
2041 </section>
2042 <section id="CallingFromSMLToCFunctionPointer">
2043 <title>CallingFromSMLToCFunctionPointer</title>
2044 <simpara>Just as MLton can <link linkend="CallingFromSMLToC">directly call C functions</link>, it
2045 is possible to make indirect function calls; that is, function calls
2046 through a function pointer. MLton extends the syntax of SML to allow
2047 expressions like the following:</simpara>
2048 <screen>_import * : MLton.Pointer.t -&gt; real * char -&gt; int;</screen>
2049 <simpara>This expression denotes a function of type</simpara>
2050 <programlisting language="sml" linenumbering="unnumbered">MLton.Pointer.t -&gt; real * char -&gt; int</programlisting>
2051 <simpara>whose behavior is implemented by calling the C function at the address
2052 denoted by the <literal>MLton.Pointer.t</literal> argument, and supplying the C
2053 function two arguments, a <literal>double</literal> and an <literal>int</literal>. The C function
2054 pointer may be obtained, for example, by the dynamic linking loader
2055 (<literal>dlopen</literal>, <literal>dlsym</literal>, &#8230;).</simpara>
2056 <simpara>The general form of an indirect <literal>_import</literal> expression is:</simpara>
2057 <screen>_import * attr... : cPtrTy -&gt; cFuncTy;</screen>
2058 <simpara>The type and the semicolon are not optional.</simpara>
2059 <section id="_example_3">
2060 <title>Example</title>
2061 <simpara>This example uses <literal>dlopen</literal> and friends (imported using normal
2062 <literal>_import</literal>) to dynamically load the math library (<literal>libm</literal>) and call the
2063 <literal>cos</literal> function. Suppose <literal>iimport.sml</literal> contains the following.</simpara>
2064 <programlisting language="sml" linenumbering="unnumbered">signature DYN_LINK =
2065 sig
2066 type hndl
2067 type mode
2068 type fptr
2069
2070 val dlopen : string * mode -&gt; hndl
2071 val dlsym : hndl * string -&gt; fptr
2072 val dlclose : hndl -&gt; unit
2073
2074 val RTLD_LAZY : mode
2075 val RTLD_NOW : mode
2076 end
2077
2078 structure DynLink :&gt; DYN_LINK =
2079 struct
2080 type hndl = MLton.Pointer.t
2081 type mode = Word32.word
2082 type fptr = MLton.Pointer.t
2083
2084 (* These symbols come from a system libray, so the default import scope
2085 * of external is correct.
2086 *)
2087 val dlopen =
2088 _import "dlopen" : string * mode -&gt; hndl;
2089 val dlerror =
2090 _import "dlerror": unit -&gt; MLton.Pointer.t;
2091 val dlsym =
2092 _import "dlsym" : hndl * string -&gt; fptr;
2093 val dlclose =
2094 _import "dlclose" : hndl -&gt; Int32.int;
2095
2096 val RTLD_LAZY = 0wx00001 (* Lazy function call binding. *)
2097 val RTLD_NOW = 0wx00002 (* Immediate function call binding. *)
2098
2099 val dlerror = fn () =&gt;
2100 let
2101 val addr = dlerror ()
2102 in
2103 if addr = MLton.Pointer.null
2104 then NONE
2105 else let
2106 fun loop (index, cs) =
2107 let
2108 val w = MLton.Pointer.getWord8 (addr, index)
2109 val c = Byte.byteToChar w
2110 in
2111 if c = #"\000"
2112 then SOME (implode (rev cs))
2113 else loop (index + 1, c::cs)
2114 end
2115 in
2116 loop (0, [])
2117 end
2118 end
2119
2120 val dlopen = fn (filename, mode) =&gt;
2121 let
2122 val filename = filename ^ "\000"
2123 val hndl = dlopen (filename, mode)
2124 in
2125 if hndl = MLton.Pointer.null
2126 then raise Fail (case dlerror () of
2127 NONE =&gt; "???"
2128 | SOME s =&gt; s)
2129 else hndl
2130 end
2131
2132 val dlsym = fn (hndl, symbol) =&gt;
2133 let
2134 val symbol = symbol ^ "\000"
2135 val fptr = dlsym (hndl, symbol)
2136 in
2137 case dlerror () of
2138 NONE =&gt; fptr
2139 | SOME s =&gt; raise Fail s
2140 end
2141
2142 val dlclose = fn hndl =&gt;
2143 if MLton.Platform.OS.host = MLton.Platform.OS.Darwin
2144 then () (* Darwin reports the following error message if you
2145 * try to close a dynamic library.
2146 * "dynamic libraries cannot be closed"
2147 * So, we disable dlclose on Darwin.
2148 *)
2149 else
2150 let
2151 val res = dlclose hndl
2152 in
2153 if res = 0
2154 then ()
2155 else raise Fail (case dlerror () of
2156 NONE =&gt; "???"
2157 | SOME s =&gt; s)
2158 end
2159 end
2160
2161 val dll =
2162 let
2163 open MLton.Platform.OS
2164 in
2165 case host of
2166 Cygwin =&gt; "cygwin1.dll"
2167 | Darwin =&gt; "libm.dylib"
2168 | _ =&gt; "libm.so"
2169 end
2170
2171 val hndl = DynLink.dlopen (dll, DynLink.RTLD_LAZY)
2172
2173 local
2174 val double_to_double =
2175 _import * : DynLink.fptr -&gt; real -&gt; real;
2176 val cos_fptr = DynLink.dlsym (hndl, "cos")
2177 in
2178 val cos = double_to_double cos_fptr
2179 end
2180
2181 val _ = print (concat [" Math.cos(2.0) = ", Real.toString (Math.cos 2.0), "\n",
2182 "libm.so::cos(2.0) = ", Real.toString (cos 2.0), "\n"])
2183
2184 val _ = DynLink.dlclose hndl</programlisting>
2185 <simpara>Compile and run <literal>iimport.sml</literal>.</simpara>
2186 <screen>% mlton -default-ann 'allowFFI true' \
2187 -target-link-opt linux -ldl \
2188 -target-link-opt solaris -ldl \
2189 iimport.sml
2190 % iimport
2191 Math.cos(2.0) = ~0.416146836547
2192 libm.so::cos(2.0) = ~0.416146836547</screen>
2193 <simpara>This example also shows the <literal>-target-link-opt</literal> option, which uses the
2194 switch when linking only when on the specified platform. Compile with
2195 <literal>-verbose 1</literal> to see in more detail what&#8217;s being passed to <literal>gcc</literal>.</simpara>
2196 </section>
2197 <section id="_download_3">
2198 <title>Download</title>
2199 <itemizedlist>
2200 <listitem>
2201 <simpara>
2202 <ulink url="https://raw.github.com/MLton/mlton/master/doc/examples/ffi/iimport.sml"><literal>iimport.sml</literal></ulink>
2203 </simpara>
2204 </listitem>
2205 </itemizedlist>
2206 <simpara><?asciidoc-pagebreak?></simpara>
2207 </section>
2208 </section>
2209 <section id="CCodegen">
2210 <title>CCodegen</title>
2211 <simpara>The <link linkend="CCodegen">CCodegen</link> is a <link linkend="Codegen">code generator</link> that translates the
2212 <link linkend="Machine">Machine</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> to C, which is further optimized
2213 and compiled to native object code by <literal>gcc</literal> (or another C compiler).</simpara>
2214 <section id="_implementation_3">
2215 <title>Implementation</title>
2216 <itemizedlist>
2217 <listitem>
2218 <simpara>
2219 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/codegen/c-codegen/c-codegen.sig"><literal>c-codegen.sig</literal></ulink>
2220 </simpara>
2221 </listitem>
2222 <listitem>
2223 <simpara>
2224 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/codegen/c-codegen/c-codegen.fun"><literal>c-codegen.fun</literal></ulink>
2225 </simpara>
2226 </listitem>
2227 </itemizedlist>
2228 </section>
2229 <section id="_details_and_notes_3">
2230 <title>Details and Notes</title>
2231 <simpara>The <link linkend="CCodegen">CCodegen</link> is the original <link linkend="Codegen">code generator</link> for MLton.</simpara>
2232 <simpara><?asciidoc-pagebreak?></simpara>
2233 </section>
2234 </section>
2235 <section id="Changelog">
2236 <title>Changelog</title>
2237 <itemizedlist>
2238 <listitem>
2239 <simpara>
2240 <ulink url="https://github.com/MLton/mlton/blob/master/CHANGELOG.adoc"><literal>CHANGELOG.adoc</literal></ulink>
2241 </simpara>
2242 </listitem>
2243 </itemizedlist>
2244 <screen>= CHANGELOG
2245
2246 == Version 20180206
2247
2248 Here are the changes from version 20130715 to version 20180206.
2249
2250 === Summary
2251
2252 * Compiler.
2253 ** Added an experimental LLVM codegen (`-codegen llvm`); requires LLVM tools
2254 (`llvm-as`, `opt`, `llc`) version &amp;ge; 3.7.
2255 ** Made many substantial cosmetic improvements to front-end diagnostic
2256 messages, especially with respect to source location regions, type inference
2257 for `fun` and `val rec` declarations, signature constraints applied to a
2258 structure, `sharing type` specifications and `where type` signature
2259 expressions, type constructor or type variable escaping scope, and
2260 nonexhaustive pattern matching.
2261 ** Fixed minor bugs with exception replication, precedence parsing of function
2262 clauses, and simultaneous `sharing` of multiple structures.
2263 ** Made compilation deterministic (eliminate output executable name from
2264 compile-time specified `@MLton` runtime arguments; deterministically generate
2265 magic constant for executable).
2266 ** Updated `-show-basis` (recursively expand structures in environments,
2267 displaying components with long identifiers; append `(* @ region *)`
2268 annotations to items shown in environment).
2269 ** Forced amd64 codegen to generate PIC on amd64-linux targets.
2270 * Runtime.
2271 ** Added `gc-summary-file file` runtime option.
2272 ** Reorganized runtime support for `IntInf` operations so that programs that
2273 do not use `IntInf` compile to executables with no residual dependency on GMP.
2274 ** Changed heap representation to store forwarding pointer for an object in
2275 the object header (rather than in the object data and setting the header to a
2276 sentinel value).
2277 * Language.
2278 ** Added support for selected SuccessorML features; see
2279 http://mlton.org/SuccessorML for details.
2280 ** Added `(*#showBasis "file" *)` directive; see
2281 http://mlton.org/ShowBasisDirective for details.
2282 ** FFI:
2283 *** Added `pure`, `impure`, and `reentrant` attributes to `_import`. An
2284 unattributed `_import` is treated as `impure`. A `pure` `_import` may be
2285 subject to more aggressive optimizations (common subexpression elimination,
2286 dead-code elimination). An `_import`-ed C function that (directly or
2287 indirectly) calls an `_export`-ed SML function should be attributed
2288 `reentrant`.
2289 ** ML Basis annotations.
2290 *** Added `allowSuccessorML {false|true}` to enable all SuccessorML features
2291 and other annotations to enable specific SuccessorML features; see
2292 http://mlton.org/SuccessorML for details.
2293 *** Split `nonexhaustiveMatch {warn|error|igore}` and `redundantMatch
2294 {warn|error|ignore}` into `nonexhaustiveMatch` and `redundantMatch`
2295 (controls diagnostics for `case` expressions, `fn` expressions, and `fun`
2296 declarations (which may raise `Match` on failure)) and `nonexhaustiveBind`
2297 and `redundantBind` (controls diagnostics for `val` declarations (which may
2298 raise `Bind` on failure)).
2299 *** Added `valrecConstr {warn|error|ignore}` to report when a `val rec` (or
2300 `fun`) declaration redefines an identifier that previously had constructor
2301 status.
2302 * Libraries.
2303 ** Basis Library.
2304 *** Improved performance of `Array.copy`, `Array.copyVec`, `Vector.append`,
2305 `String.^`, `String.concat`, `String.concatWith`, and other related
2306 functions by using `memmove` rather than element-by-element constructions.
2307 ** `Unsafe` structure.
2308 *** Added unsafe operations for array uninitialization and raw arrays; see
2309 https://github.com/MLton/mlton/pull/207 for details.
2310 ** Other libraries.
2311 *** Updated: ckit library, MLLPT library, MLRISC library, SML/NJ library
2312 * Tools.
2313 ** mlnlffigen
2314 *** Updated to warn and skip (rather than abort) when encountering functions
2315 with `struct`/`union` argument or return type.
2316
2317 === Details
2318
2319 * 2018-02-6
2320 ** Remove ancient and unused `cmcat` tool.
2321
2322 * 2018-02-03
2323 ** Upgrade `gdtoa.tgz`.
2324
2325 * 2018-02-02
2326 ** Remove docs from `all` target of `./Makefile`; this eliminates the
2327 `all-no-docs` target (which was frequently used in favor of `all`).
2328
2329 * 2018-01-31
2330 ** Use C compiler with `-std=gnu11` (rather than `-std=gnu99`).
2331 ** Revert rudimentary support for `./configure`; the support was so minimal
2332 that it seems unhelpful to pretend that there are exhaustive compatibility
2333 checks being performed. All of the basic configuration can be accomplished
2334 with simple `make` variable definitions.
2335
2336 * 2018-01-25
2337 ** Remove (expert, undocumented) `-debug-format` option; the same effect can
2338 be achieved with `-as-opt` and `-cc-opt`.
2339 ** Propagate C compiler from `./configure` to `mlton` script.
2340
2341 * 2018-01-24
2342 ** Extend `-target-*-opt` options to support `arch-os` pairs.
2343 ** Remove `./package/rpm/*` and corresponding targets in `./Makefile`;
2344 upstream MLton has not produced RPMs for years.
2345
2346 * 2018-01-24
2347 ** Slightly improve performance of `Vector.concat` and
2348 `String.{concat,concatWith,tokens,fields}` by avoiding `List.map`-s.
2349
2350 * 2018-01-23
2351 ** Restore, but deprecate, `-drop-pass` compile-time expert option.
2352
2353 * 2018-01-19
2354 ** Update SML/NJ libraries to SML/NJ 110.82.
2355
2356 * 2017-12-29
2357 ** Add support for `(*#showBasis "file" *)` directives. This feature is
2358 meant to facilitate auto-completion via
2359 https://github.com/MatthewFluet/company-mlton[`company-mlton`] and similar
2360 tools.
2361
2362 * 2017-12-20
2363 ** Update performance comparison on website. Thanks to Curtis Dunham for the
2364 pull request.
2365
2366 * 2017-12-17
2367 ** Updates to `-show-basis`:
2368 *** `-show-basis-flat`: Recursively expand structures in environments,
2369 displaying components with long identifiers.
2370 *** `-show-basis-def`: Appends `(* @ region *)` annotations to items shown
2371 in environment.
2372 *** `-show-basis-compact`: Tries to optimize vertical space (at the expense
2373 of long lines).
2374
2375 * 2017-12-11
2376 ** Drop `_BSD_SOURCE` and `_POSIX_C_SOURCE` feature macros in
2377 `./runtime/cenv.h`.
2378
2379 * 2017-12-10
2380 ** Add a `Dockerfile` to build/test MLton. Thanks to Richard Laughlin for the
2381 pull request.
2382
2383 * 2017-12-06
2384 ** Remove `$PREFIX` and `$prefix` from top-level `Makefile.in`; use
2385 `./configure --prefix path`. Thanks to Richard Laughlin for the pull
2386 request.
2387
2388 * 2017-12-03
2389 ** Fix heap invariant predicates.
2390
2391 * 2017-11-15
2392 ** Eliminate the use of (some) global mutable state for signal handling.
2393
2394 * 2017-11-14
2395 ** Store forwarding pointer for an object in the object header (rather than in
2396 the object data and setting the header to a sentinel value).
2397
2398 * 2017-11-02
2399 ** Updates to stack management in backend:
2400 *** Improve `Allocation.Stack.get`.
2401 *** Do not force `Cont` block arguments to stack.
2402
2403 * 2017-10-30
2404 ** In `signature SSA_TO_RSSA_STRUCTS` share by `Rssa.Atoms = Ssa.Atoms`. This
2405 is the idiom used elsewhere in the compiler, rather than sharing individual
2406 sub-structures of `Atoms`.
2407 ** Minor updates to `DirectedGraph` and `Tree` in MLton library.
2408
2409 * 2017-10-23
2410 ** Add `-seed-rand w` compile-time option, to seed the pseudo-random number
2411 generator.
2412 ** Add a new MachineShuffle pass (disabled by default) that shuffles the
2413 collection of chunks within the program and shuffles the collection of blocks
2414 within a chunk. With the `-seed-rand w` compile-time option, can be used to
2415 generate executables with distinct code placements.
2416
2417 * 2017-10-23
2418 ** Use a relative path in the `mlton` script, rather than an absolute path.
2419 The absolute path needed to be set to the intended installation directory,
2420 which made it difficult to install a binary release in a local directory.
2421 Undertaken by Maksim Yegorov at RIT supported by NSF CISE Research
2422 Infrastructure (CRI) award.
2423
2424 * 2017-10-21
2425 ** Add unsafe operations for array uninitialization and raw arrays.
2426 *** Rename `Array_uninit: SeqIndex.int -&gt; 'a array` primitive to
2427 `Array_alloc: SeqIndex.int -&gt; 'a array`.
2428 *** Add `Array_uninit: 'a array * SeqIndex.int -&gt; unit` primitive to set all
2429 objptrs in the element at the given index to a bogus non-objptr value
2430 (`0wx1`). One motivation for this primitive is to support space-efficient
2431 polymorphic resizeable arrays. When shrinking a resizeable array, we would
2432 like to "`NULL`" out the elements that are no longer part of the logical
2433 array, in order to avoid a (logical) space leak.
2434 *** Add `Array_uninitIsNop: 'a array -&gt; bool` primitive to answer if the
2435 `Array_uninit` primitive applied to the same array would be a nop (i.e., if
2436 the array has no objptrs in the elements). This can be used to skip a
2437 bulk-`Array_uninit` loop when it is known that the `Array_uninit` operations
2438 would be nops.
2439 *** Add `Array_allocRaw: SeqIndex.int -&gt; 'a array` primitive to allocate an
2440 array, but with a header that indicates that the array has no objptrs. Add
2441 `Array_toArray: 'a array -&gt; 'a array` primitive to update the header of an
2442 `Array_allocRaw` allocated array to reveal the objptrs. One motiviation for
2443 this primitive is that, in a parallel setting, the uninitialization of an
2444 array can be a sequential bottleneck. The `Array_allocRaw` is a constant
2445 time operation and the subsequent `Array_uninit` operations can be performed
2446 in parallel.
2447 *** Extend `structure Unsafe.Array` with additional operations. See
2448 `./basis-library/sml-nj/unsafe.sig`.
2449
2450 * 2017-10-20
2451 ** Introduce ShareZeroVec SSA optimization to share zero-length vectors after
2452 coercion-based optimizations. Undertaken by Maksim Yegorov at RIT supported
2453 by NSF CISE Research Infrastructure (CRI) award.
2454
2455 * 2017-10-18
2456 ** New canonicalization strategy for CommonSubexp SSA optimization.
2457 Previously, the canonicalization of commutative arithmetic primitives was
2458 sensitive to variable hashes (created by an unseeded pseudo-random number
2459 generator); now, the canonicalization of commutative arithmetic primitives is
2460 sensitive to relative definition order of variables.
2461
2462 * 2017-10-12
2463 ** Fix bug in runtime argument option parsing.
2464
2465 * 2017-10-05
2466 ** Many updates and improvements to diagnostic messages. See
2467 https://github.com/MLton/mlton/pull/195 for details.
2468
2469 * 2017-09-27
2470 ** Add rudimentary support for `./configure`; in particular, support
2471 `--with-gmp-lib` and `--with-gmp-include` to set location of GMP and
2472 `--prefix` to specify an install prefix. Undertaken by Maksim Yegorov at RIT
2473 supported by NSF CISE Research Infrastructure (CRI) award.
2474
2475 * 2017-08-21
2476 ** Introduce `Array_copyArray: 'a array * SeqIndex.int * 'a array *
2477 SeqIndex.int * SeqIndex.int -&gt; unit` and `Array_copyVector: 'a array *
2478 SeqIndex.int * 'a vector * SeqIndex.int * SeqIndex.int -&gt; unit` primitives
2479 which are used to implement a number of array and vector construction
2480 functions, particularly `append`, `concat`, and `concatWith`. The primitives
2481 compile to `memmove` operations, which (significantly) outperforms MLton's
2482 element-by-element construction for large sequences. Undertaken by Bryan Camp
2483 at RIT supported by NSF CISE Research Infrastructure (CRI) award.
2484
2485 * 2017-07-25
2486 ** Force PIC generation on amd64-linux targets. Thanks to Kuen-Bang Hou
2487 (Favonia) for the pull request.
2488
2489 * 2017-07-11
2490 ** Generalize the `subWord` primitives to
2491 +
2492 ----
2493 | WordArray_subWord of {seqSize:WordSize.t, eleSize: WordSize.t}
2494 | WordArray_updateWord of {seqSize: WordSize.t, eleSize: WordSize.t}
2495 | WordVector_subWord of {seqSize: WordSize.t, eleSize: WordSize.t}
2496 ----
2497 +
2498 Undertaken by Bryan Camp at RIT supported by NSF CISE Research Infrastructure
2499 (CRI) award.
2500
2501 * 2017-07-11
2502 ** Add a parser combinator library (`structure StreamParser`) to the MLton
2503 Library. Undertaken by Jason Carr at RIT supported by NSF CISE Research
2504 Infrastructure (CRI) award.
2505 ** Add a parser for the SXML IR (`structure ParseSxml`). Undertaken by Jason
2506 Carr at RIT supported by NSF CISE Research Infrastructure (CRI) award.
2507 ** Allow compilation to start with a `.sxml` file. Undertaken by Jason Carr
2508 at RIT supported by NSF CISE Research Infrastructure (CRI) award.
2509
2510 * 2017-06-29
2511 ** Replace `-drop-pass regex` compile-time option with `-disable-pass regex`
2512 compile option and add `-enable-pass regex` compile option. Various XML,
2513 SXML, SSA, SSA2, RSSA, and Machine IR optimization passes are initialized with
2514 a default status, which can be overriden by `-{disable,enable}-pass`. In
2515 particular, it is now easy to add a work-in-progress (and potentially buggy)
2516 pass to the simplification pipeline with `execute = false` default status, to
2517 be selectively executed with `-enable-pass`. Undertaken by Bryan Camp at RIT
2518 supported by NSF CISE Research Infrastructure (CRI) award.
2519 ** Add LoopUnswitch and LoopUnroll SSA optimizations (undertaken by Matthew
2520 Surawski as an RIT CS MS Capstone Project). Initial evaluation demonstrates
2521 some non-trivial performance gains, no non-trivial performance losses, and
2522 only minor code size increases, but currently disabled pending a more thorough
2523 evaluation.
2524
2525 * 2017-05-23
2526 ** Expand the set of MLB annotations:
2527 *** `nonexhaustiveBind`, `nonexhaustiveExnBind`, `redundantBind`: controls
2528 diagnostics for `val` declarations (which may raise `Bind` on failure).
2529 *** `nonexhaustiveMatch`, `nonexhaustiveExnMatch`, `redundantMatch`:
2530 controls diagnostics for `case` expressions, `fn` expressions, and `fun`
2531 declarations (which may raise `Match` on failure).
2532 *** `nonexhaustiveRaise`, `nonexhaustiveExnRaise`, `redundantRaise`:
2533 controls diagnostics for `handle` expressions (which implicitly re-raise on
2534 failure). Note that `nonexhaustiveRaise` and `nonexhaustiveExnRaise`
2535 default to `ignore`. The combination of `nonexhaustiveRaise warn` and
2536 `nonexhaustiveExnRaise ignore` can be useful for finding handlers that
2537 handle some, but not all, values of an exception variant.
2538 ** Make a number of improvements to diagnostic messages:
2539 *** Display nonexhaustive exception patterns as `_ : exn`, rather than
2540 `e`.
2541 *** Normalize nonexhaustive patterns by sorting (e.g., by `ConApp` name).
2542 *** Report complete enumeration of unhandled constants, rather than a single
2543 example.
2544 *** Report nonexhaustive patterns of record type as records, rather than as
2545 tuples.
2546
2547 * 2017-04-20
2548 ** Updates to SSA, SSA2, and RSSA IR support infrastructure
2549 *** Display more context when reporting SSA and SSA2 IR type errors.
2550 *** Add `-layout-width n` compile expert option to control the target width
2551 for the pretty printer.
2552 *** Make cosmetic improvments to SSA and SSA2 IR display (uses of global
2553 variables bound to small constants and conapps are commented with the
2554 corresponding value; include loop forest for functions with `-keep dot`).
2555 *** Improve RSSA constant folding and copy propagation.
2556 *** Limit Machine IR `Globals` to variables used outside of the `main`
2557 function.
2558
2559 * 2017-04-15
2560 ** Add `gc-summary-file file` runtime option.
2561
2562 * 2017-04-15
2563 ** Rename and add `smlnj-mlton-x{2,4,8,16}` top-level `Makefile` targets.
2564 ** Update SML/NJ librarys to SML/NJ 110.80 (making use of supported
2565 SuccessorML features).
2566 ** Not support for SML/NJ extensions via SuccessorML MLB annotations on
2567 website.
2568
2569 * 2017-04-14
2570 ** Add support for vector expressions (`#[e1, e2, ..., en]`) and vector
2571 patterns (`#[p1, p2, ..., pn]`) and add `Vector_vector` n-ary primitive.
2572 Initial support for vector expressions and the `Vector_vector` primitive were
2573 undertaken by Krishna Ravikumar as an RIT CS MS Capstone Project.
2574
2575 * 2017-03-29
2576 ** Update DOS eol handling and tweak error messages in lexer.
2577
2578 * 2017-03-27
2579 ** Correct off-by-one error in column numbers. Thanks to Jacob Zimmerman for
2580 the error report and pull request.
2581
2582 * 2017-03-15
2583 ** Updates to SuccessorML support:
2584 *** Add an `allowSuccessorML {false|true}` MLB annotation to enable all
2585 Successor ML features with a single annotation.
2586 *** Fix parsing of numeric labels to only accept an INT token that does not
2587 begin with 0, is not an extended literal, is not negative, and is decimal.
2588 *** Drop the alternate word prefixes (`0xw` and `0bw`).
2589 *** Unconditionally allow line comments in MLB files.
2590 *** Allow UTF-8 byte sequences in text constants.
2591 *** Refactor `ml.lex` and `mlb.lex` to be more maintainable.
2592 *** Rename `allowRecPunning` annotation to `allowRecordPunExps`.
2593
2594 * 2017-02-27
2595 ** Update ML-Yacc examples (`calc`, `fol`, `pascal`) to comply with MLton
2596 build process. Thanks to Hai Nguyen Van for the pull request.
2597
2598 * 2017-01-25
2599 ** Update PortingMLton documentation and `./bin/add-cross` script. Thanks to
2600 Daniel Moerner for the pull request.
2601
2602 * 2016-09-29
2603 ** Constant fold `CPointer_equal(NULL, NULL)` to `true`.
2604
2605 * 2016-09-29
2606 ** Introduce `NEEDS_SIGALTSTACK_EXEC` config in runtime system.
2607
2608 * 2016-09-27
2609 ** Construct a devel build version string from last commit time and last
2610 commit hash.
2611 ** Omit build date and build node from version banner; makes self-compiles
2612 deterministic.
2613 ** Remove `upgrade-basis.sml` from build. The generated `upgrade-basis.sml`
2614 was introduced to handle incompatibilities in the Basis Library provided by an
2615 old version of MLton and the Basis Library assumed by the current sources.
2616 However, there are no incompatibilities with MLton 20130715, MLton 20100608,
2617 or MLton 20070826. Nonetheless, the feature testing performed by
2618 `./bin/upgrade-basis` to generate `upgrade-basis.sml` is time consuming,
2619 especially when trying to simply type check the compiler sources.
2620
2621 * 2016-06-20
2622 ** Do not `gzip` man pages on OpenBSD. Thanks to Alexander Abushkevich for
2623 the pull request.
2624
2625 * 2016-06-20
2626 ** Generate position independent code for OpenBSD. Thanks to Alexander
2627 Abushkevich for the pull request.
2628
2629 * 2016-06-20
2630 ** Fix profiling for amd64-openbsd and x86-openbsd. Thanks to Alexander
2631 Abushkevich for the pull request.
2632
2633 * 2016-04-06
2634 ** Update SML/NJ librarys to SML/NJ 110.79.
2635
2636 * 2016-03-22
2637 ** Update LLVM codegen to support (and require) &gt;= llvm-3.7. Thanks to Eugene
2638 Akentyev for the pull request.
2639
2640 * 2016-02-26
2641 ** Configure GMP location via `Makefile`.
2642
2643 * 2016-01-10
2644 ** Fix typo in `mlb-formal.tex`. Thanks to Jon Sterling for the pull request.
2645
2646 * 2015-11-10
2647 ** Update SML/NJ librarys to SML/NJ 110.78. Use `allowOrPats` and
2648 `allowSigWithtype` to minimize diffs.
2649
2650 * 2015-10-20
2651 ** Fix elaboration of `withtype` in signature.
2652
2653 * 2015-10-06
2654 ** Add support for setting CM anchor bindings in `cm2mlb` tool.
2655
2656 * 2015-10-06
2657 ** Fix non-exhaustive match warnings with or-patterns. Thanks to Rob Simmons
2658 for the bug report.
2659 ** Distinguish between partial and fully redundant matches.
2660 ** Report partial redundancy in `val` declarations.
2661 ** Lower precedence of or-patterns in parser.
2662 ** Make a variety of cosmetic improvements to non-exhaustive and redundant
2663 error/warning messages, primarily to be consistent in formatting between
2664 quoted AST and generated messages.
2665
2666 * 2015-07-10
2667 ** Extend support for arm64 (aarch64). Thanks to Edmund Evans for the patch.
2668
2669 * 2015-06-22
2670 ** Introduce `valrecConstr {warn|error|ignore}` MLB annotation to report when
2671 a `val rec` (or `fun`) declaration redefines an identifier that previously had
2672 constructor status.
2673
2674 * 2015-06-19
2675 ** Add support for selected SuccessorML features (undertaken by Kevin Bradley
2676 as an RIT CS MS Capstone Project).
2677 *** `do`-declarations (`allowDoDecls`)
2678 *** extended literals (`allowExtendedLiterals`)
2679 *** line comments (`allowLineComments`)
2680 *** optional leading bar in matches, fun decls, and datatype decls
2681 (`allowOptBar`)
2682 *** optional trailing semicolon in sequence expressions (`allowOptSemicolon`)
2683 *** or patterns (`allowOrPats`)
2684 *** record expression punning (`allowRecPunning`)
2685 *** withtype in signatures (`allowSigWithtype`)
2686
2687 * 2015-06-10
2688 ** Hide equality status of poly (and mono) vector and array slices.
2689 ** Hide type equality of mono and poly `Word8.word` arrays and vectors.
2690
2691 * 2015-06-08
2692 ** Added `reentrant` attribute to `_import`. An `_import`-ed C function that
2693 (directly or indirectly) calls an `_export`-ed SML function should be
2694 attributed `reentrant`.
2695
2696 * 2015-06-08
2697 ** Make compilation deterministic:
2698 *** Eliminate output executable name from compile-time specified `@MLton`
2699 arguments.
2700 *** Deterministically generate magic constant for executable.
2701
2702 * 2015-06-08
2703 ** Add `-keep ast` compile option. Undertaken by Ross Bayer at RIT supported
2704 by NSF CISE Research Infrastructure (CRI) award.
2705
2706 * 2015-06-02
2707 ** Updates to Debian packaging. Thanks to Christopher Cramer for the pull
2708 request.
2709
2710 * 2015-03-30
2711 ** Use `LANG=en_us` when computing version and build date. Thanks to Eugene
2712 Akentyev for the pull request.
2713
2714 * 2015-02-17
2715 ** Update `mlnlffigen` to warn and skip functions with `struct`/`union`
2716 arguments. Thanks to Armando Doval for the pull request.
2717
2718 * 2014-12-22
2719 ** Move pervasive constructs from `./mlton/ast` to `./mlton/atoms`, so that
2720 `./mlton/ast/sources.mlb` depends on `./mlton/atoms/sources.mlb` (and not the
2721 other way around). Undertaken by Vedant Raiththa at RIT supported by NSF CISE
2722 Research Infrastructure (CRI) award.
2723
2724 * 2014-12-17
2725 ** Cache a worker thread to service calls of `_export`-ed functions. Thanks
2726 to Bernard Berthomieu for the bug report.
2727
2728 * 2014-12-02
2729 ** Post-process generated front-end files for compatibility with SML/NJ's
2730 recent `ml-lex` and `ml-yacc` tools that generate log identifiers rather than
2731 unqualified (top-level environment) identifiers.
2732 ** Corrected documentation for SML/NJ `Makefile` target and fixed
2733 `bootstrap-nj` target. Thanks to Daniel Rosenwasser for the pull request.
2734
2735 * 2014-11-21
2736 ** Reorganized runtime support for `IntInf` operations so that programs that
2737 do not use `IntInf` compile to executables with no residual dependency on GMP.
2738 ** Fixed bug in `MLton.IntInf.fromRep` that could yield values that violate
2739 the `IntInf` representation invariants. Thanks to Rob Simmons for the bug
2740 report.
2741
2742 * 2014-10-24
2743 ** Added `pure` and `impure` attributes to `_import`. An unattributed
2744 `_import` is treated as `impure`. A `pure` `_import` may be subject to more
2745 aggressive optimizations (common subexpression elimination, dead-code
2746 elimination). Undertaken by Vedant Raiththa at RIT supported by NSF CISE
2747 Research Infrastructure (CRI) award.
2748
2749 * 2014-10-22
2750 ** Various updates to treatment of `IntInf` constants in the compiler.
2751 *** Recognize both `Big` and `Small` representations of `IntInf`-s.
2752 *** Translate `IntInf` consts to `Big` and `Small` representations in
2753 conversion from SSA to RSSA. This is consistent with the treatment of other
2754 `IntInf` operations in the conversion. After the conversion, `IntInf` is no
2755 longer treated as a primitive.
2756 *** Remove `initIntInfs` from program initialization.
2757 *** Constant fold `IntInf_toVector` and `WordVector_toIntInf` primitives.
2758
2759 * 2014-10-20
2760 ** Various updates to `structure WordXVector` in compiler proper.
2761 *** Update the `WordXVector.layout` function. If the `elementSize` is
2762 `WordX.word8` and more than 90% of the characters satisfy `Char.isGraph
2763 orelse Char.isSpace`, then display as an SML string constant (with
2764 non-printable characters SML-escaped). Otherwise, display as an SML/NJ-style
2765 `#[0x0, 0xF]` vector literal.
2766 *** Update initialization of `static struct GC_vectorInit vectorInits[]`
2767 constants in runtime. If the `WordXVector`'s (primitive) `elementSize` is
2768 `WordSize.W8`, then emit a C-escaped string constant. Otherwise, emit a
2769 C-array initialization.
2770
2771 * 2014-08-15
2772 ** More updates to benchmark infrastructure.
2773 *** Make `update-counts.sh` script more robust.
2774 *** Update `hamlet.sml` benchmark program to close input file after each
2775 loop.
2776 *** Update `fft.sml` benchmark program to only invoke `test` function with
2777 power-of-2 arguments.
2778 *** Update `model-elimination.sml` benchmark program to iterate `main ()`
2779 according to `doit` size parameter.
2780
2781 * 2014-08-11
2782 ** Include `winsock2.h` before `windows.h` in MinGW port. Thanks to Shu-Hung
2783 You for the pull request.
2784
2785 * 2014-07-31
2786 ** Refactor array and vector implementation in Basis Library into a primitive
2787 implementation (using `SeqInt.int` for indexing) and a wrapper implementation
2788 (using the default `Int.int` for indexing). Thanks to Rob Simmons for the
2789 pull request.
2790 ** Correct description of `MLton.{Vector,Array}.unfoldi` on website. Thanks
2791 to Rob Simmons for the pull request.
2792
2793 * 2014-07-14
2794 ** Updates to benchmark infrastructure.
2795 *** Add `even-odd.sml` benchmark that exercises mutual tail recursion.
2796 *** Add `update-counts.sh` script to calculate appropriate benchmark
2797 iteration counts and update benchmark iteration counts so that all
2798 benchmarks run for at least 30 seconds.
2799 *** Updates to benchmark driver program.
2800
2801 * 2014-07-07
2802 ** Change `./basis-library/integer/int-inf.sml` to reduce dependency on
2803 GMP-specific details of `./basis-library/integer/int-inf0.sml`. Thanks to Rob
2804 Simmons for the pull request.
2805 ** Correct type and description of `MLton.IntInf.fromRep` on website. Thanks
2806 to Rob Simmons for the pull request.
2807
2808 * 2014-07-01
2809 ** Add experimental LLVM codegen (undertaken by Brian Leibig as an RIT CS MS
2810 Project).
2811
2812 * 2014-06-09
2813 ** Update `CallingFromSMLToC` page on website. Thanks to Bikal Gurung for the
2814 pull request.
2815
2816 * 2014-03-18
2817 ** Updates for MinGW port.
2818
2819 * 2014-02-07
2820 ** Update AsciiDoc sources for website.
2821
2822 * 2013-10-31
2823 ** Various updates to website. Thanks to Mauricio C Antunes for the pull
2824 request.
2825 *** Add Tofte's tutorial and Rossberg's grammar.
2826 *** Fix links to implementations.
2827
2828 * 2013-10-10
2829 ** Update links from `References` page on website. Thanks to Mauricio C
2830 Antunes for the pull request.
2831
2832 * 2013-09-02
2833 ** Fix example for `Lazy` page on website. Thanks to Daniel Rosenwasser for
2834 the pull request.
2835
2836 == Version 20130715
2837
2838 Here are the changes from version 20100608 to version 20130715.
2839
2840 === Summary
2841
2842 * Compiler.
2843 ** Cosmetic improvements to type-error messages.
2844 ** Removed features:
2845 *** Bytecode codegen: The bytecode codegen had not seen significant use and
2846 it was not well understood by any of the active developers.
2847 *** Support for `.cm` files as input: The ML Basis system provides much
2848 better infrastructure for "programming in the very large" than the (very)
2849 limited support for CM. The `cm2mlb` tool (available in the source
2850 distribution) can be used to convert CM projects to MLB projects, preserving
2851 the CM scoping of module identifiers.
2852 ** Bug fixes: see changelog
2853 * Runtime.
2854 ** Bug fixes: see changelog
2855 * Language.
2856 ** Interpret `(*#line line:col "file" *)` directives as relative
2857 file names.
2858 ** ML Basis annotations.
2859 *** Added: `resolveScope`
2860 * Libraries.
2861 ** Basis Library.
2862 *** Improved performance of `String.concatWith`.
2863 *** Use bit operations for `REAL.class` and other low-level operations.
2864 *** Support additional variables with `Posix.ProcEnv.sysconf`.
2865 *** Bug fixes: see changelog
2866 ** `MLton` structure.
2867 *** Removed: `MLton.Socket`
2868 ** Other libraries.
2869 *** Updated: ckit library, MLRISC library, SML/NJ library
2870 *** Added: MLLPT library
2871 * Tools.
2872 ** mllex
2873 *** Generate `(*#line line:col "file.lex" *)` directives with simple
2874 (relative) file names, rather than absolute paths.
2875 ** mlyacc
2876 *** Generate `(*#line line:col "file.grm" *)` directives with simple
2877 (relative) file names, rather than absolute paths.
2878 *** Fixed bug in comment-handling in lexer.
2879
2880 === Details
2881
2882 * 2013-07-06
2883 ** Update SML/NJ libraries to SML/NJ 110.76.
2884
2885 * 2013-06-19
2886 ** Upgrade `gdtoa.tgz`; fixed bug in `Real32.{fmt,toDecimal,toString}`, which
2887 in some cases produced too many digits
2888
2889 * 2013-06-18
2890 ** Removed `MLton.Socket` structure (deprecated in last release).
2891
2892 * 2013-06-10
2893 ** Improved performance of `String.concatWith`.
2894
2895 * 2013-05-22
2896 ** Update SML/NJ libraries to SML/NJ 110.75.
2897
2898 * 2013-04-30
2899 ** Detect PowerPC 64 architecture.
2900
2901 * 2012-10-09
2902 ** Fixed bug in elaboration that erroneously accepted the following:
2903
2904 signature S = sig structure A : sig type t end
2905 and B : sig type t end where type t = A.t end
2906
2907 * 2012-09-04
2908 ** Introduce an MLB annotation to control overload and flex record resolution
2909 scope: `resolveScope {strdec|dec|topdec|program}`.
2910
2911 * 2012-07-04
2912 ** Simplify use of `getsockopt` and `setsockopt` in Basis Library.
2913 ** Direct implementation of `Socket.Ctl.{getATMARK,getNREAD}` in runtime
2914 system, rather than indirect implementation in Basis Library via `ioctl`.
2915 ** Replace use of casting through a union with `memcpy` in runtime.
2916
2917 * 2012-06-11
2918 ** Use bit operations for `REAL.class` and other low-level operations.
2919 ** Fixed bugs in `REAL.copySign`, `REAL.signBit`, and `REAL.{to,from}Decimal`.
2920
2921 * 2012-06-01
2922 ** Cosmetic improvements to type-error messages.
2923 ** Fixed bug in elaboration that erroneously rejected the following:
2924
2925 datatype ('a, ''a) t = T
2926 type ('a, ''a) u = unit
2927
2928 and erroneously accepted the following:
2929
2930 fun f (x: 'a) : ''a = x
2931 fun g (x: 'a) : ''a = if x = x then x else x
2932
2933 * 2012-02-24
2934 ** Fixed bug in redundant SSA optimization.
2935
2936 * 2011-06-20
2937 ** Support additional variables with `Posix.ProcEnv.sysconf`.
2938
2939 * 2011-06-17
2940 ** Change `mllex` and `mlyacc` to generate `#line` directives with simple file
2941 names, rather than absolute paths.
2942 ** Interpret `#line` directives as relative file names.
2943
2944 * 2011-06-14
2945 ** Fixed bug in SSA/SSA2 shrinker that could erroneously turn a non-tail
2946 function call with a `Bug` transfer as its continuation into a tail function
2947 call.
2948
2949 * 2011-06-11
2950 ** Update SML/NJ libraries to SML/NJ 110.73 and add ML-LPT library.
2951
2952 * 2011-06-10
2953 ** Fixed bug in translation from SSA2 to RSSA with case expressions over
2954 non-primitive-sized words.
2955 ** Fixed bug in SSA/SSA2 type checking of case expressions over words.
2956
2957 * 2011-06-04
2958 ** Upgrade `gdtoa.tgz`.
2959 ** Remove bytecode codegen.
2960 ** Remove support for `.cm` files as input.
2961
2962 * 2011-05-03
2963 ** Fixed a bug with the treatment of `as`-patterns, which should not allow the
2964 redefinition of constructor status.
2965
2966 * 2011-02-18
2967 ** Fixed bug with treatment of nan in common subexpression elimination SSA
2968 optimization.
2969
2970 * 2011-02-18
2971 ** Fixed bug in translation from SSA2 to RSSA with weak pointers.
2972
2973 * 2011-02-05
2974 ** Fixed bug in amd64 codegen calling convention for varargs C calls.
2975
2976 * 2011-01-17
2977 ** Fixed bug in comment-handling in lexer for `mlyacc`'s input language.
2978
2979 * 2010-06-22
2980 ** Fixed bug in elaboration of function clauses with different numbers of
2981 arguments that would raise an uncaught `Subscript` exception.
2982
2983
2984 == Version 20100608
2985
2986 Here are the changes from version 20070826 to version 20100608.
2987
2988 === Summary
2989
2990 * New platforms.
2991 ** ia64-hpux
2992 ** powerpc64-aix
2993 * Compiler.
2994 ** Command-line switches.
2995 *** Added: `-mlb-path-var '&lt;name&gt; &lt;value&gt;'`
2996 *** Removed: `-keep sml`, `-stop sml`
2997 ** Improved constant folding of floating-point operations.
2998 ** Experimental: Support for compiling to a C library; see wiki documentation.
2999 ** Extended `-show-def-use` output to include types of variable definitions.
3000 ** Deprecated features (to be removed in a future release)
3001 *** Bytecode codegen: The bytecode codegen has not seen significant use and
3002 it is not well understood by any of the active developers.
3003 *** Support for `.cm` files as input: The ML Basis system provides much
3004 better infrastructure for "programming in the very large" than the (very)
3005 limited support for CM. The `cm2mlb` tool (available in the source
3006 distribution) can be used to convert CM projects to MLB projects, preserving
3007 the CM scoping of module identifiers.
3008 ** Bug fixes: see changelog
3009 * Runtime.
3010 ** `@MLton` switches.
3011 *** Added: `may-page-heap {false|true}`
3012 ** `may-page-heap`: By default, MLton will not page the heap to disk when
3013 unable to grow the heap to accomodate an allocation. (Previously, this
3014 behavior was the default, with no means to disable, with security an
3015 least-surprise issues.)
3016 ** Bug fixes: see changelog
3017 * Language.
3018 ** Allow numeric characters in ML Basis path variables.
3019 * Libraries.
3020 ** Basis Library.
3021 *** Bug fixes: see changelog.
3022 ** `MLton` structure.
3023 *** Added: `MLton.equal`, `MLton.hash`, `MLton.Cont.isolate`,
3024 `MLton.GC.Statistics, `MLton.Pointer.sizeofPointer`,
3025 `MLton.Socket.Address.toVector`
3026 *** Changed:
3027 *** Deprecated: `MLton.Socket`
3028 ** `Unsafe` structure.
3029 *** Added versions of all of the monomorphic array and vector structures.
3030 ** Other libraries.
3031 *** Updated: ckit library, MLRISC library, SML/NJ library.
3032 * Tools.
3033 ** `mllex`
3034 *** Eliminated top-level `type int = Int.int` in output.
3035 *** Include `(*#line line:col "file.lex" *)` directives in output.
3036 *** Added `%posint` command, to set the `yypos` type and allow the lexing of
3037 multi-gigabyte files.
3038 ** `mlnlffigen`
3039 *** Added command-line switches `-linkage archive` and `-linkage shared`.
3040 *** Deprecated command-line switch `-linkage static`.
3041 *** Added support for ia64 and hppa targets.
3042 ** `mlyacc`
3043 *** Eliminated top-level `type int = Int.int` in output.
3044 *** Include `(*#line line:col "file.grm" *)` directives in output.
3045
3046 === Details
3047
3048 * 2010-05-12
3049 ** Fixed bug in the mark-compact garbage collector where the C library's
3050 `memcpy` was used to move objects during the compaction phase; this could lead
3051 to heap corruption and segmentation faults with newer versions of `gcc` and/or
3052 `glibc`, which assume that src and dst in a `memcpy` do not overlap.
3053
3054 * 2010-03-12
3055 ** Fixed bug in elaboration of `datatype` declarations with `withtype`
3056 bindings.
3057
3058 * 2009-12-11
3059 ** Fixed performance bug in RefFlatten SSA2 optimization.
3060
3061 * 2009-12-09
3062 ** Fixed performance bug in SimplifyTypes SSA optimization.
3063
3064 * 2009-12-02
3065 ** Fixed bug in amd64 codegen register allocation of indirect C calls.
3066
3067 * 2009-09-17
3068 ** Fixed bug in `IntInf.scan` and `IntInf.fromString` where leading spaces
3069 were only accepted if the stream had an explicit sign character.
3070
3071 * 2009-07-10
3072 ** Added CombineConversions SSA optimization.
3073
3074 * 2009-06-09
3075 ** Removed deprecated command line switch `-show-anns {false, true}`.
3076
3077 * 2009-04-18
3078 ** Removed command line switches `-keep sml` and `-stop sml`. Their meaning
3079 was unclear with `.mlb` files; their effect with `.cm` files can be achieved
3080 with `-stop f`.
3081
3082 * 2009-04-16
3083 ** Fixed bug in `IntInf.~&gt;&gt;` that could cause a `glibc` assertion failure.
3084
3085 * 2009-04-01
3086 ** Fixed exported type of `MLton.Process.reap`.
3087
3088 * 2009-01-27
3089 ** Added `MLton.Socket.Address.toVector` to get the network-byte-order
3090 representation of an IP address.
3091
3092 * 2008-11-10
3093 ** Fixed bug in `MLton.size` and `MLton.share` when tracing the current stack.
3094
3095 * 2008-10-27
3096 ** Fixed phantom typing of sockets by hiding the representation of socket
3097 types. Previously the representation of sockets was revealed rendering the
3098 phantom types useless.
3099
3100 * 2008-10-10
3101 ** Fixed bug in nested `_export`/`_import` functions.
3102
3103 * 2008-09-12
3104 ** Improved constant folding of floating point operations.
3105
3106 * 2008-08-20
3107 ** Store the card/cross map at the end of the allocated ML heap; avoids
3108 possible out of memory errors when resizing the ML heap cannot be followed by
3109 a card/cross map allocation.
3110
3111 * 2008-07-24
3112 ** Added support for compiling to a C library. The relevant new compiler
3113 options are `-ar` and `-format`. Libraries are named based on the name of the
3114 `-export-header` file. Libraries have two extra methods:
3115 *** `NAME_open(argc, argv)` initializes the library and runs the SML code
3116 until it reaches the end of the program. If the SML code exits or raises an
3117 uncaught exception, the entire program will terminate.
3118 *** `NAME_close()` will execute any registered atExit functions, any
3119 outstanding finalizers, and frees the ML heap.
3120
3121 * 2008-07-16
3122 ** Fixed bug in the name mangling of `_import`-ed functions with the `stdcall`
3123 convention.
3124
3125 * 2008-06-12
3126 ** Added `MLton.Pointer.sizeofPointer`.
3127
3128 * 2008-06-06
3129 ** Added expert command line switch `-emit-main {true|false}`.
3130
3131 * 2008-05-17
3132 ** Fixed bug in Windows code to page the heap to disk when unable to grow the
3133 heap to a desired size. Thanks to Sami Evangelista for the bug report.
3134
3135 * 2008-05-10
3136 ** Implemented `MLton.Cont.isolate`.
3137
3138 * 2008-04-20
3139 ** Fixed bug in *NIX code to page the heap to disk when unable to grow the
3140 heap to a desired size. Thanks to Nicolas Bertolotti for the bug report and
3141 patch.
3142
3143 * 2008-04-07
3144 ** More flexible active/paused stack resizing policy. +
3145 Removed `thread-shrink-ratio` runtime option. + Added
3146 `stack-current-grow-ratio`, `stack-current-max-reserved-ratio`,
3147 `stack-current-permit-ratio`, `stack-current-shrink-ratio`,
3148 `stack-max-reserved-ratio`, and `stack-shrink-ratio` runtime options.
3149
3150 * 2008-04-07
3151 ** Fixed bugs in Basis Library where the representations of `OS.IO.iodesc`,
3152 `Posix.IO.file_desc`, `Posix.Signal.signal`, `Socket.sock`,
3153 `Socket.SOGK.sock_type` as integers were exposed.
3154
3155 * 2008-03-14
3156 ** Added unsafe versions of all of the monomorphic array and vector
3157 structures.
3158
3159 * 2008-03-02
3160 ** Fixed bug in Basis Library where the representation of `OS.Process.status`
3161 as an integer was exposed.
3162
3163 * 2008-02-13
3164 ** Fixed space-safety bug in RefFlatten optimization (to flatten refs into
3165 containing data structure). Thanks to Daniel Spoonhower for the bug report and
3166 initial diagnosis and patch.
3167
3168 * 2008-01-25
3169 ** Various updates to GC statistics gathering. Some basic GC statistics can
3170 be accessed from SML by `MLton.GC.Statistics.*` functions.
3171
3172 * 2008-01-24
3173 ** Added primitive (structural) polymorphic hash.
3174
3175 * 2008-01-21
3176 ** Fixed frontend to accept `op _longvid_` patterns and expressions. Thanks to
3177 Florian Weimer for the bug report.
3178
3179 * 2008-01-17
3180 ** Extended `-show-def-use` output to include types of variable definitions.
3181
3182 * 2008-01-09
3183 ** Extended `MLton_equal` to be a structural equality on all types, including
3184 `real` and `-&gt;` types.
3185
3186 * 2007-12-18
3187 ** Changed ML-Yacc and ML-Lex to output line directives so that MLton's
3188 def-use information points to the source files (`.grm` and `.lex`) instead of
3189 the generated implementations (`.grm.sml` and `.lex.sml`).
3190
3191 * 2007-12-14
3192 ** Added runtime option `may-page-heap {false|true}`. By default, MLton will
3193 not page the heap to disk when unable to grow the heap to a desired size.
3194 (Previously, this behavior was the default, with no means to disable, with
3195 security and least-surprise concerns.) Thanks to Wesley Terpstra for the
3196 patch.
3197 ** Fixed bug the FFI visible representation of `Int16.int ref` (and references
3198 of other primitive types smaller than 32-bits) on big-endian platforms. Thanks
3199 to Dave Herman for the bug report.
3200
3201 * 2007-12-13
3202 ** Fixed bug in `ImperativeIOExtra.canInput` (`TextIO.canInput`). Thanks to
3203 Ville Laurikari for the bug report.
3204
3205 * 2007-12-09
3206 ** Better constant folding of `IntInf` operations.
3207
3208 * 2007-12-07
3209 ** Fixed bug in algebraic simplification of `RealX` primitives. `Real.&lt;= (x,
3210 x)` is `false` when `x` is `NaN`.
3211
3212 * 2007-11-29
3213 ** Fixed bug in type inference of flexible records. This would later cause
3214 the compiler to raise the `TypeError` exception. Thanks to Wesley Terpstra for
3215 the bug report.
3216
3217 * 2007-11-28
3218 ** Fixed bug in cross-compilation of `gdtoa` library. Thanks to Wesley
3219 Terpstra for the bug report and patch.
3220
3221 * 2007-11-20
3222 ** Fixed bug in RefFlatten optimization (pass to flatten refs into containing
3223 data structure). Thanks to Ruy LeyWild for the bug report.
3224
3225 * 2007-11-19
3226 ** Fixed bug in the handling of weak pointers by the mark-compact garbage
3227 collector. Thanks to Sean McLaughlin for the bug report and Florian Weimer for
3228 the initial diagnosis.
3229
3230 * 2007-11-07
3231 ** Added `%posint` command to `ml-lex`, to set the `yypos` type and allow the
3232 lexing of multi-gigabyte input files. Thanks to Florian Weimer for the feature
3233 concept and original patch.
3234
3235 * 2007-11-07
3236 ** Added command-line switch `-mlb-path-var '&lt;name&gt; &lt;value&gt;'` for specifying
3237 MLB path variables.
3238
3239 * 2007-11-06
3240 ** Allow numeric characters in MLB path variables.
3241
3242 * 2007-09-20
3243 ** Fixed bug in elaboration of structures with signature constraints. This
3244 would later cause the compiler to raise the `TypeError` exception. Thanks to
3245 Vesa Karvonen for the bug report.
3246
3247 * 2007-09-11
3248 ** Fixed bug in interaction of `_export`-ed functions and signal
3249 handlers. Thanks to Sean McLaughlin for the bug report.
3250
3251 * 2007-09-03
3252 ** Fixed bug in implementation of `_export`-ed functions using `char`
3253 type. Thanks to Katsuhiro Ueno for the bug report.
3254
3255
3256 == Version 20070826
3257
3258 Here are the changes from version 20051202 to version 20070826.
3259
3260 === Summary
3261
3262 * New platforms:
3263 ** amd64-linux, amd64-freebsd
3264 ** hppa-hpux
3265 ** powerpc-aix
3266 ** x86-darwin (Mac OS X)
3267 * Compiler.
3268 ** Support for 64-bit platforms.
3269 *** Native amd64 codegen.
3270 ** Command-line switches.
3271 *** Added: `-codegen amd64`, `-codegen x86`, `-default-type &lt;type&gt;`,
3272 `-profile-val {false|true}`.
3273 *** Changed: `-stop f` (file listing now includes `.mlb` files)
3274 ** Bytecode codegen.
3275 *** Support for profiling.
3276 *** Support for exception history.
3277 * Language.
3278 ** ML Basis annotations.
3279 *** Removed: `allowExport`, `allowImport`, `sequenceUnit`, `warnMatch`.
3280 * Libraries.
3281 ** Basis Library.
3282 *** Added: `PackWord16Big, `PackWord16Little`, `PackWord64Big`,
3283 `PackWord64Little`.
3284 *** Bug Fixes: see changelog.
3285 ** `MLton` structure.
3286 *** Added: `MLTON_MONO_ARRAY`, `MLTON_MONO_VECTOR`, `MLTON_REAL`,
3287 `MLton.BinIO.tempPrefix`, `MLton.CharArray`, `MLton.CharVector`,
3288 `MLton.IntInf.BigWord`, `MLton.IntInf.SmallInt`,
3289 `MLton.Exn.defaultTopLevelHandler`, `MLton.Exn.getTopLevelHandler`,
3290 `MLton.Exn.setTopLevelHandler`, `MLton.LargeReal`, `MLton.LargeWord`,
3291 `MLton.Real`, `MLton.Real32`, `MLton.Real64`, `MLton.Rlimit.Rlim`,
3292 `MLton.TextIO.tempPrefix`, `MLton.Vector.create`, `MLton.Word.bswap`,
3293 `MLton.Word8.bswap`, `MLton.Word16`, `MLton.Word32`, `MLton.Word64`,
3294 `MLton.Word8Array`, `MLton.Word8Vector`.
3295 *** Changed: `MLton.Array.unfoldi`, `MLton.IntInf.rep`, `MLton.Rlimit`,
3296 `MLton.Vector.unfoldi`.
3297 *** Deprecated: `MLton.Socket`
3298 ** Other libraries.
3299 *** Added: MLRISC libary.
3300 *** Updated: ckit library, SML/NJ library.
3301 * Tools.
3302
3303 === Details
3304
3305 * 2007-08-12
3306 ** Removed deprecated ML Basis annotations.
3307
3308 * 2007-08-06
3309 ** Fixed bug in treatment of `Real&lt;N&gt;.{scan,fromString}` operations.
3310 `Real&lt;N&gt;.{scan,fromString}` were using `TO_NEAREST` semantics, but should obey
3311 current rounding mode. (Only `Real&lt;N&gt;.fromDecimal` is specified to always
3312 have `TO_NEAREST` semantics.) Thanks to Sean McLaughlin for the bug report.
3313
3314 * 2007-07-27
3315 ** Fixed bugs in constant-folding of floating-point operations with C codegen.
3316
3317 * 2007-07-26
3318 ** Fixed bug in treatment of floating-point operations. Floating-point
3319 operations depend on the current rounding mode, but were being treated as
3320 pure. Thanks to Sean McLaughlin for the bug report.
3321
3322 * 2007-07-13
3323 ** Added `MLton.Exn.{default,get,set}TopLevelHandler`.
3324
3325 * 2007-07-12
3326 ** Restored `native` option to `-codegen` flag.
3327
3328 * 2007-07-11
3329 ** Fixed bug in `Real32.toInt`: conversion of real values close to
3330 `Int.maxInt` could be incorrect.
3331
3332 * 2007-07-07
3333 ** Updates to bytecode code generator: support for amd64-* targets, support
3334 for profiling (including exception history).
3335 ** Fixed bug in `Socket` module of Basis Library; unmarshalling of socket
3336 options (for `get*` functions) used `andb` rather than `orb`. Thanks to Anders
3337 Petersson for the bug report (and patch).
3338
3339 * 2007-07-06
3340 ** Fixed bug in `Date` module of Basis Library; some functions would
3341 erroneously raise `Date` when given a year &lt;= 1900. Thanks to Joe Hurd for the
3342 bug report.
3343 ** Fixed a long-standing bug in monomorphisation pass. Thanks to Vesa Karvonen
3344 for the bug report.
3345
3346 * 2007-05-18
3347 ** Native amd64 code generator for amd64-* targets.
3348 ** Eliminate `native` option from `-codegen` flag.
3349 ** Add `x86` and `amd64` options to `-codegen` flag.
3350
3351 * 2007-04-29
3352 ** Improved type checking of RSSA and Machine ILs.
3353
3354 * 2007-04-14
3355 ** Fixed aliasing issues with `basis/Real/*.c` files.
3356 ** Added real/word casts in `MLton` structure.
3357
3358 * 2007-04-12
3359 ** Added primitives for bit cast of word to/from real.
3360 ** Implement `PackReal&lt;N&gt;{Big,Little}` using `PackWord&lt;N&gt;{Big,Little}` and bit
3361 casts.
3362
3363 * 2007-04-11
3364 ** Move all system header `#include`-s to `platform/` os headers.
3365 ** Use C99 `&lt;assert.h&gt;`, rather than custom `"assert.{h,c}"`.
3366
3367 * 2007-03-13
3368 ** Implement `PackWord&lt;N&gt;{Big,Little}` entirely in ML, using an ML byte swap
3369 function.
3370
3371 * 2007-02-25
3372 ** Change amd64-* target platforms from 32-bit compatibility mode (i.e.,
3373 `-m32`) to 64-bit mode (i.e., `-m64`). Currently, only the C codegen is able
3374 to generate 64-bit executables.
3375
3376 * 2007-02-23
3377 ** Removed expert command line switch `-coalesce &lt;n&gt;`.
3378 ** Added expert command line switch `-chunkify {coalesce&lt;n&gt;|func|one}`.
3379
3380 * 2007-02-20
3381 ** Fixed bug in `PackReal&lt;N&gt;.toBytes`. Thanks to Eric McCorkle for the bug
3382 report (and patch).
3383
3384 * 2007-02-18
3385 ** Added command line switch `-profile-val`, to profile the evaluation of
3386 `val` bindings; this is particularly useful with exception history for
3387 debugging uncaught exceptions at the top-level.
3388
3389 * 2006-12-29
3390 ** Added command line switch `-show {anns|path-map}` and deprecated command
3391 line switch `-show-anns {false|true}`. Use `-show path-map` to see the
3392 complete MLB path map as seen by the compiler.
3393
3394 * 2006-12-20
3395 ** Changed the output of command line switch `-stop f` to include `.mlb`
3396 files. This is useful for generating Makefile dependencies. The old output
3397 is easy to recover if necessary (e.g. `grep -v '\.mlb$'`).
3398
3399 * 2006-12-08
3400 ** Added command line switches `-{,target}-{as,cc,link}-opt-quote`, which pass
3401 their argument as a single argument to `gcc` (i.e., without tokenization at
3402 spaces). These options support using headers and libraries (including the
3403 MLton runtime headers and libraries) from a path with spaces.
3404
3405 * 2006-12-02
3406 ** Extensive reorganization of garbage collector, runtime system, and Basis
3407 Library implementation. (This is in preparation for future 64bit support.)
3408 They should be more C standards compliant and easier to port to new systems.
3409 ** FFI revisions
3410 *** Disallow nested indirect types (e.g., `int array array`).
3411
3412 * 2006-11-30
3413 ** Fixed a bug in elaboration of FFI forms; unary FFI types (e.g., `array`,
3414 `ref`, `vector`) could be used in places where `MLton.Pointer.t` was required.
3415 This would later cause the compiler to raise the `TypeError` exception, along
3416 with a lot of XML IL.
3417
3418 * 2006-11-19
3419 ** On *-darwin, work with GnuMP installed via Fink or MacPorts.
3420
3421 * 2006-10-30
3422 ** Ported to x86-darwin.
3423
3424 * 2006-09-23
3425 ** Added missing specification of `find` to the `MONO_VECTOR` signature.
3426
3427 * 2006-08-03
3428 ** Fixed a bug in Useless SSA optimization, caused by calling an imported C
3429 function and then ignoring the result.
3430
3431 * 2006-06-24
3432 ** Fixed a bug in pass to flatten data structures. Thanks to Joe Hurd for the
3433 bug report.
3434
3435 * 2006-06-08
3436 ** Fixed a bug in the native codegen's implementation of the C-calling
3437 convention.
3438
3439 * 2006-05-11
3440 ** Ported to PowerPC-AIX.
3441 ** Fixed a bug in the runtime for the cases where nonblocking IO with sockets
3442 was implemented using `MSG_DONTWAIT`. This flag does not exist on AIX,
3443 Cygwin, HPUX, and MinGW and was previously just ignored. Now the runtime
3444 simulates the flag for these platforms (except MinGW, yet, where it's still
3445 ignored).
3446
3447 * 2006-05-06
3448 ** Added `-default-type '&lt;ty&gt;&lt;N&gt;'` for specifying the binding of default types
3449 in the Basis Library (e.g., `Int.int`).
3450
3451 * 2006-04-25
3452 ** Ported to HPPA-HPUX.
3453 ** Fixed `PackReal{,32,64}{Big,Little}` to follow the Basis Library
3454 specification.
3455
3456 * 2006-04-19
3457 ** Fixed a bug in `MLton.share` that could cause a segfault.
3458
3459 * 2006-03-30
3460 ** Changed `MLton.Vector.unfoldi` to return the state in addition to the
3461 result vector.
3462
3463 * 2006-03-30
3464 ** Added `MLton.Vector.create`, a more powerful vector-creation function than
3465 is available in the basis library.
3466
3467 * 2006-03-04
3468 ** Added MLRISC from SML/NJ 110.57 to standard distribution.
3469
3470 * 2006-03-03
3471 ** Fixed bug in SSA simplifier that could eliminate an irredundant test.
3472
3473 * 2006-03-02
3474 ** Ported a bugfix from SML/NJ for a bug with the combination of `withNack`
3475 and `never` in CML.
3476
3477 * 2006-02-09
3478 ** Support compiler specific annotations in ML Basis files. If an annotation
3479 contains `:`, then the text preceding the `:` is meant to denote a compiler.
3480 For MLton, if the text preceding the `:` is equal to `mlton`, then the
3481 remaining annotation is scanned as a normal annotation. If the text preceding
3482 the `:` is not-equal to `mlton`, then the annotation is ignored, and no
3483 warning is issued.
3484
3485 * 2006-02-04
3486 ** Fixed bug in elaboration of functors; a program with a very large number of
3487 functors could exhibit the error `ElaborateEnv.functorClosure: firstTycons`.
3488
3489
3490 == Version 20051202
3491
3492 Here are the changes from version 20041109 to version 20051202.
3493
3494 === Summary
3495
3496 * New license: BSD-style instead of GPL.
3497 * New platforms:
3498 ** hppa: Debian Linux.
3499 ** x86: MinGW.
3500 * Compiler.
3501 ** improved exception history.
3502 ** Command-line switches.
3503 *** Added: `-as-opt`, `-mlb-path-map`, `-target-as-opt`, `-target-cc-opt`.
3504 *** Deprecated: none.
3505 *** Removed: `-native`, `-sequence-unit`, `-warn-match`, `-warn-unused`.
3506 * Language.
3507 ** FFI syntax changes and extensions.
3508 *** Added: `_symbol`.
3509 *** Changed: `_export`, `_import`.
3510 *** Removed: `_ffi`.
3511 ** ML Basis annotations.
3512 *** Added: `allowFFI`, `nonexhaustiveExnMatch`, `nonexhaustiveMatch`,
3513 `redundantMatch`, `sequenceNonUnit`.
3514 *** Deprecated: `allowExport`, `allowImport`, `sequenceUnit`, `warnMatch`.
3515 * Libraries.
3516 ** Basis Library.
3517 *** Added: `Int1`, `Word1`.
3518 ** `MLton` structure.
3519 *** Added: `Process.create`, `ProcEnv.setgroups`, `Rusage.measureGC`,
3520 `Socket.fdToSock`, `Socket.Ctl.getError`.
3521 *** Changed: `MLton.Platform.Arch`.
3522 ** Other libraries.
3523 *** Added: ckit library, ML-NLFFI library, SML/NJ library.
3524 * Tools.
3525 ** updates of `mllex` and `mlyacc` from SML/NJ.
3526 ** added `mlnlffigen`.
3527 ** profiling supports better inclusion/exclusion of code.
3528
3529 === Details
3530
3531 * 2005-11-19
3532 ** Updated SML/NJ Library and CKit Library from SML/NJ 110.57.
3533
3534 * 2005-11-15
3535 ** Fixed a bug in `MLton.ProcEnv.setgroups`.
3536
3537 * 2005-11-11
3538 ** Fixed a bug in the interleaving of lexing/parsing and elaborating of ML
3539 Basis files, which would raise an unhandled `Force` exception on cyclic basis
3540 references. Thanks to John Dias for the bug report.
3541
3542 * 2005-11-10
3543 ** Fixed two bugs in `Time.scan`. One would raise `Time` on a string with a
3544 large fractional component. Thanks to Carsten Varming for the bug report.
3545 The other failed to scan strings with an explicit sign followed by a decimal
3546 point.
3547
3548 * 2005-11-03
3549 ** Removed `MLton.GC.setRusage`.
3550 ** Added `MLton.Rusage.measureGC`.
3551
3552 * 2005-09-11
3553 ** Fixed bug in display of types with large numbers of type variables, which
3554 could cause unhandled exception `Chr`.
3555
3556 * 2005-09-08
3557 ** Fixed bug in type inference of flexible records that would show up as
3558 `"Type error: variable applied to wrong number of type args"`.
3559
3560 * 2005-09-06
3561 ** Fixed bug in `Real.signBit`, which had assumed that the underlying C
3562 signbit returned 0 or 1, when in fact any nonzero value is allowed to indicate
3563 the signbit is set.
3564
3565 * 2005-09-05
3566 ** Added `-mlb-path-map` switch.
3567
3568 * 2005-08-25
3569 ** Fixed bug in `MLton.Finalizable.touch`, which was not keeping alive
3570 finalizable values in all cases.
3571
3572 * 2005-08-18
3573 ** Added SML/NJ Library and CKit Library from SML/NJ 110.55 to standard
3574 distribution.
3575 ** Fixed bug in `Socket.Ctl.*`, which got the endianness wrong on big-endian
3576 machines. Thanks to Wesley Terpstra for the bug report and fix.
3577 ** Added `MLton.GC.setRusage`.
3578 ** Fixed bug in `mllex`, which had file positions starting at 2. They now
3579 start at zero.
3580
3581 * 2005-08-15
3582 ** Fixed bug in `LargeInt.scan`, which should skip leading `"0x"` and `"0X"`.
3583 Thanks to Wesley Terpstra for the bug report and fix.
3584
3585 * 2005-08-06
3586 ** Additional revisions of FFI:
3587 *** Deprecated `_export` with incomplete annotation.
3588 *** Added `_address` for address of C objects.
3589 *** Eliminated address component of `_symbol`.
3590 *** Changed the type of the `_symbol*` expression.
3591 *** See documentation for more detail.
3592
3593 * 2005-08-06
3594 ** Annotation changes:
3595 *** Deprecated: `sequenceUnit`
3596 *** Added: `sequenceNonUnit`
3597
3598 * 2005-08-03
3599 ** Annotation changes:
3600 *** Deprecated: `allowExport`, `allowImport`, `warnMatch`
3601 *** Added: `allowFFI`, `nonexhaustiveExnMatch`, `nonexhaustiveMatch`,
3602 `redundantMatch`
3603
3604 * 2005-08-01
3605 ** Update `mllex` and `mlyacc` with SML/NJ 110.55+ versions. This
3606 incorporates a small number of minor bug fixes.
3607
3608 * 2005-07-23
3609 ** Fixed bug in pass to flatten refs into containing data structure.
3610
3611 * 2005-07-23
3612 ** Overhaul of FFI:
3613 *** Deprecated `_import` of C base types.
3614 *** Added `_symbol` for address, getter, and setter of C base types.
3615 *** See documentation for more detail.
3616
3617 * 2005-07-21
3618 ** Update `mllex` and `mlyacc` with SML/NJ 110.55 versions. This incorporates
3619 a small number of minor bug fixes.
3620
3621 * 2005-07-20
3622 ** Fixed bug in front end that allowed unary constructors to be used without
3623 an argument in patterns.
3624
3625 * 2005-07-19
3626 ** Eliminated `_ffi`, which has been deprecated for some time.
3627
3628 * 2005-07-14
3629 ** Fixed bug in runtime that caused getrusage to be called on every GC, even
3630 if timing info isn't needed.
3631
3632 * 2005-07-13
3633 ** Fixed bug in closure conversion tickled by making a weak pointer to a
3634 closure.
3635
3636 * 2005-07-12
3637 ** Changed `{OS,Posix}.Process.sleep` to call `nanosleep()` instead of
3638 `sleep()`.
3639 ** Added `MLton.ProcEnv.setgroups`.
3640
3641 * 2005-07-11
3642 ** `InetSock.{any,toAddr}` raise `SysErr` if port is not in [0, 2^16^).
3643
3644 * 2005-07-02
3645 ** Fixed bug in `Socket.recvVecFrom{,',NB,NB'}`. The type was too polymorphic
3646 and allowed the creation of a bogus `sock_addr`.
3647
3648 * 2005-06-28
3649 ** The front end now reports errors on encountering undefined or cyclicly
3650 defined MLB path variables.
3651
3652 * 2005-05-22
3653 ** Fixed bug in `Posix.IO.{getlk,setlk,setlkw}` that caused a link-time error:
3654 undefined reference to `Posix_IO_FLock_typ`.
3655 ** Improved exception history so that the first entry in the history is the
3656 source position of the raise, and the rest is the call stack.
3657
3658 * 2005-05-19
3659 ** Improved exception history for `Overflow` exceptions.
3660
3661 * 2005-04-20
3662 ** Fixed a bug in pass to flatten refs into containing data structure.
3663
3664 * 2005-04-14
3665 ** Fixed a front-end bug that could cause an internal bug message of the form
3666 `"missing flexInst"`.
3667
3668 * 2005-04-13
3669 ** Fixed a bug in the representation of flat arrays/vectors that caused
3670 incorrect behavior when the element size was 2 or 4 bytes and there were
3671 multiple components to the element (e.g. `(char * char) vector`).
3672
3673 * 2005-04-01
3674 ** Fixed a bug in `GC_arrayAllocate` that could cause a segfault.
3675
3676 * 2005-03-22
3677 ** Added structures `Int1`, `Word1`.
3678
3679 * 2005-03-19
3680 ** Fixed a bug that caused `Socket.Ctl.{get,set}LINGER` to raise `Subscript`.
3681 The problem was in the use of `PackWord32Little.update`, which scales the
3682 supplied index by `bytesPerElem`.
3683
3684 * 2005-03-13
3685 ** Fixed a bug in CML mailboxes.
3686
3687 * 2005-02-26
3688 ** Fixed an off-by-one error in `mkstemp` defined in `mingw.c`.
3689
3690 * 2005-02-13
3691 ** Added `mlnlffigen` tool (heavily adapted from SML/NJ).
3692
3693 * 2005-02-12
3694 ** Added MLNLFFI Library (heavily adapted from SML/NJ) to standard
3695 distribution.
3696
3697 * 2005-02-04
3698 ** Fixed a bug in `OS.path.toString`, which did not raise `InvalidArc` when
3699 needed.
3700
3701 * 2005-02-03
3702 ** Fixed a bug in `OS.Path.joinDirFile`, which did not raise `InvalidArc` when
3703 passed a file that was not an arc.
3704
3705 * 2005-01-26
3706 ** Fixed a front end bug that incorrectly rejected expansive __valbind__s with
3707 useless bound type variables.
3708
3709 * 2005-01-22
3710 ** Fixed x86 codegen bug which failed to account for the possibility that a
3711 64-bit move could interfere with itself (as simulated by 32-bit moves).
3712
3713 * 2004-12-22
3714 ** Fixed `Real32.fmt StringCvt.EXACT`, which had been producing too many
3715 digits of precision because it was converting to a `Real64.real`.
3716
3717 * 2004-12-15
3718 ** Replaced MLB path variable `MLTON_ROOT` with `SML_LIB`, to use a more
3719 compiler-independent name. We will keep `MLTON_ROOT` aliased to `SML_LIB`
3720 until after the next release.
3721
3722 * 2004-12-02
3723 ** `Unix.create` now works on all platforms (including Cygwin and MinGW).
3724
3725 * 2004-11-24
3726 ** Added support for `MLton.Process.create`, which works on all platforms
3727 (including Windows-based ones like Cygwin and MinGW) and allows better control
3728 over `std{in,out,err}` for child process.
3729
3730
3731 == Version 20041109
3732
3733 Here are the changes from version 20040227 to 20041109.
3734
3735 === Summary
3736
3737 * New platforms:
3738 ** x86: FreeBSD 5.x, OpenBSD
3739 ** PowerPC: Darwin (MacOSX)
3740 * Support for MLBasis files.
3741 * Support for dynamic libraries.
3742 * Support for Concurrent ML (CML).
3743 * New structures: `Int2`, `Int3`, ..., `Int31` and `Word2`, `Word3`, ..., `Word31`.
3744 * A new form of profiling: `-profile count`.
3745 * A bytecode generator.
3746 * Data representation improvements.
3747 * `MLton` structure changes.
3748 ** Added: `share`, `shareAll`
3749 ** Changed: `Exn`, `IntInf`, `Signal`, `Thread`.
3750 * Command-line switch changes.
3751 ** Deprecated:
3752 *** `-native` (use `-codegen`)
3753 *** `-sequence-unit` (use `-default-ann`)
3754 *** `-warn-match` (use `-default-ann`)
3755 *** `-warn-unused` (use `-default-ann`)
3756 ** Removed:
3757 *** `-detect-overflow`
3758 *** `-exn-history` (use `-const`)
3759 *** `-safe`
3760 *** `-show-basis-used`
3761 ** Added:
3762 *** `-codegen`
3763 *** `-const`
3764 *** `-default-ann`
3765 *** `-disable-ann`
3766 *** `-profile-branch`
3767 *** `-target-link-opt`
3768
3769 === Details
3770
3771 * 2004-09-22
3772 ** Extended `_import` to support indirect function calls.
3773
3774 * 2004-09-13
3775 ** Made `Date.{fromString,scan}` accept a space (treated as zero) in the first
3776 character of the day of the month.
3777
3778 * 2004-09-12
3779 ** Fixed bug in `IntInf` that could cause a segfault.
3780 ** Remove `MLton.IntInf.size`.
3781
3782 * 2004-09-05
3783 ** Made `-detect-overflow` and `-safe` expert options.
3784
3785 * 2004-08-30
3786 ** Added `val MLton.share: 'a -&gt; unit`, which maximizes sharing in a heap
3787 object.
3788
3789 * 2004-08-27
3790 ** Fixed bug in `Real.toLargeInt`. It would incorrectly raise `Option`
3791 instead of `Overflow` in the case when the real was not an `INF`, but rounding
3792 produced an `INF`.
3793 ** Fixed bugs in `Date.{fmt,fromString,scan,toString}`. They incorrectly
3794 allowed a space for the first character in the day of the month.
3795
3796 * 2004-08-18
3797 ** Changed `MLton.{Thread,Signal,World}` to distinguish between implicitly and
3798 explicitly paused threads.
3799
3800 * 2004-07-28
3801 ** Added support for programming in the large using the ML Basis system.
3802
3803 * 2004-07-11
3804 ** Fixed bugs in `ListPair.*Eq` functions, which incorrectly raised the
3805 `UnequalLengths` exception.
3806
3807 * 2004-07-01
3808 ** Added `val MLton.Exn.addExnMessager: (exn -&gt; string option) -&gt; unit`.
3809
3810 * 2004-06-23
3811 ** Runtime system options that take memory sizes now accept a "`g`" suffix
3812 indicating gigabytes. They also now take a real instead of an integer,
3813 e.g. `fixed-heap 0.5g`. They also now accept uppercase, e.g. `150M`.
3814
3815 * 2004-06-12
3816 ** Added support for OpenBSD.
3817
3818 * 2004-06-10
3819 ** Added support for FreeBSD 5.x.
3820
3821 * 2004-05-28
3822 ** Deprecated the `-native` flag. Instead, use the new flag `-codegen
3823 {native|bytecode|C}`. This is in anticipation of adding a bytecode compiler.
3824
3825 * 2004-05-26
3826 ** Fixed a front-end bug that could cause cascading error to print a very
3827 large and unreadable internal bug message of the form `"datatype ... realized
3828 with scheme Unknown"`.
3829
3830 * 2004-05-17
3831 ** Automatically restart functions in the Basis Library that correspond
3832 directly to interruptable system calls.
3833
3834 * 2004-05-13
3835 ** Added `-profile count`, for dynamic counts of function calls and branches.
3836 ** Equate the types `Posix.Signal.signal` and `Unix.signal`.
3837
3838 * 2004-05-11
3839 ** Fixed a bug with `-basis 1997` that would cause type errors due to
3840 differences between types in the MLton structure and types in the rest of the
3841 basis library.
3842
3843 * 2004-05-01
3844 ** Fixed a bug with sharing constraints in signatures that would sometimes
3845 mistakenly treat two structures as identical when they shouldn't have been.
3846 This would cause some programs to be mistakenly rejected.
3847
3848 * 2004-04-30
3849 ** Added `MLton.Signal.{handled,restart}`.
3850
3851 * 2004-04-23
3852 ** Added `Timer.checkCPUTimes`, and updated the `Timer` structure to match the
3853 latest basis spec. Also fixed `totalCPUTimer` and `totalRealTimer`, which
3854 were wrong.
3855
3856 * 2004-04-13
3857 ** Added `MLton.Signal.Mask.{getBlocked,isMember}`.
3858
3859 * 2004-04-12
3860 ** Fix bug that mistakenly generalized variable types containing unknown types
3861 when matching against a signature.
3862 ** Reasonable front-end error message when unification causes recursive
3863 (circular) type.
3864
3865 * 2004-04-03
3866 ** Fixed bug in sharing constraints so that `sharing A = B = C` means that all
3867 pairs `A = B`, `A = C`, `B = C` are shared, not just `A = B` and `B = C`.
3868 This matters in some situations.
3869
3870 * 2004-03-20
3871 ** Fixed `Time.now` which was treating microseconds as nanoseconds.
3872
3873 * 2004-03-14
3874 ** Fixed SSA optimizer bug that could cause the error `"&lt;type&gt; has no
3875 tyconInfo property"`.
3876
3877 * 2004-03-11
3878 ** Fixed `Time.fromReal` to raise `Time`, not `Overflow`, on unrepresentable
3879 times.
3880
3881 * 2004-03-04
3882 ** Added structures `Word2`, `Word3`, ..., `Word31`.
3883
3884 * 2004-03-03
3885 ** Added structures `Int2`, `Int3`, ..., `Int31`.
3886 ** Fixed bug in elaboration of `and` with signatures, structures, and functors
3887 so that it now evaluates all right-hand sides before binding any left-hand
3888 sides.
3889
3890
3891 == Version 20040227
3892
3893 Here are the changes from version 20030716 to 20040227.
3894
3895 === Summary
3896
3897 * The front end now follows the Definition of SML and produces readable error
3898 messages.
3899 * Added support for NetBSD.
3900 * Basis library changes tracking revisions to the specification.
3901 * Added structures: `Int64`, `Real32`, `Word64`.
3902 * File positions use `Int64`.
3903 * Major improvements to `-show-basis`, which now displays the basis in a very
3904 readable way with full type information.
3905 * Command-line switch changes.
3906 ** Deprecated: `-basis`.
3907 ** Removed: `-lib-search`, `-link`, `-may-load-world`, `-static`.
3908 ** Added: `-link-opt`, `-runtime`, `-sequence-unit`, `-show-def-use`,
3909 `-stop tc`, `-warn-match`, `-warn-unused`.
3910 ** Changed: `-export-header`, `-show-basis`, `-show-basis-used`.
3911 ** Renamed: `-host` to `-target`.
3912 * FFI changes.
3913 ** Renamed `_ffi` as `_import`.
3914 ** Added `cdecl` and `stdcall` attributes to `_import` and `_export`
3915 expressions.
3916 * MLton structure changes.
3917 ** Added: Pointer.
3918 ** Removed: Ptrace.
3919 ** Changed: `Finalizable`, `IntInf`, `Platform`, `Random`, `Signal`, `Word`.
3920
3921 === Details
3922
3923 * 2004-02-16
3924 ** Changed `-export-header`, `-show-basis`, `-show-basis-used` to take a file
3925 name argument, and they no longer force compilation to halt.
3926 ** Added `-show-def-use` and `-warn-unused`, which deal with def-use
3927 information.
3928
3929 * 2004-02-13
3930 ** Added flag `-sequence-unit`, which imposes the constraint that in the
3931 sequence expression `(e1; e2)`, `e1` must be of type `unit`.
3932
3933 * 2004-02-10
3934 ** Lots of changes to `MLton.Signal`: name changes, removal of superfluous
3935 functions, additional functions.
3936
3937 * 2004-02-09
3938 ** Extended `-show-basis` so that when used with an input program, it shows
3939 the basis defined by the input program.
3940 ** Added `stop` runtime argument.
3941 ** Made `-call-graph {false|true}` an option to `mlprof` that determines
3942 whether or not a call graph file is written.
3943
3944 * 2004-01-20
3945 ** Fixed a bug in `IEEEReal.{fromString,scan}`, which would improperly return
3946 `INF` instead of `ZERO` for things like `"0.0000e123456789012345"`.
3947 ** Fixed a bug in `Real.{fromDecimal,fromString,scan}`, which didn't return an
3948 appropriately signed zero for `~0.0`.
3949 ** Fixed a bug in `Real.{toDecimal,fmt}`, which didn't correctly handle
3950 `~0.0`.
3951 ** Report a compile-time error on unrepresentable real constants.
3952
3953 * 2004-01-05
3954 ** Removed option `-may-load-world`. You can now use `-runtime no-load-world`
3955 instead.
3956 ** Removed option `-static`. You can now use `-link-opt -static` instead.
3957 ** Changed `MLton.IntInf.size` to return 0 instead of 1 on small ints.
3958
3959 * 2003-12-28
3960 ** Fixed horrible bug in `MLton.Random.alphaNumString` that caused it to
3961 return 0 for all characters beyond position 11.
3962
3963 * 2003-12-17
3964 ** Removed `-basis` as a normal flag. It is still available as an expert
3965 flag, but its use is deprecated. It will almost certainly disappear after the
3966 next release.
3967
3968 * 2003-12-10
3969 ** Allow multiple `@MLton --` runtime args in sequnce. This makes it easier
3970 for scripts to prefix `@MLton` args without having to splice them with other
3971 ones.
3972
3973 * 2003-12-04
3974 ** Added support for files larger than 2G. This included changing
3975 `Position` from `Int32` to `Int64`.
3976
3977 * 2003-12-01
3978 ** Added `structure MLton.Pointer`, which includes a `type t` for pointers
3979 (memory addresses, not SML heap pointers) and operations for loading from and
3980 storing to memory.
3981
3982 * 2003-11-03
3983 ** Fixed `Timer.checkGCTime` so that only the GC user time is included, not GC
3984 system time.
3985
3986 * 2003-10-13
3987 ** Added `-warn-match` to control display nonexhaustive and redundant
3988 match warnings.
3989 ** Fixed space leak in `StreamIO` causing the entire stream to be retained.
3990 Thanks to Jared Showalter for the bug report and fix.
3991
3992 * 2003-10-10
3993 ** Added `-stop tc` switch to stop after type checking.
3994
3995 * 2003-09-25
3996 ** Fixed `Posix.IO.getfl`, which had mistakenly called `fcntl` with `F_GETFD`
3997 instead of `F_GETFL`.
3998 ** Tracking basis library changes:
3999 *** `Socket` module datagram functions no longer return amount written,
4000 since they always write the entire amount or fail. So,
4001 `send{Arr,Vec}To{,'}` now return `unit` instead of `int`.
4002 *** Added nonblocking versions of all the send and recv functions, as well
4003 as accept and connect. So, we now have: `acceptNB`, `connectNB`,
4004 `recv{Arr,Vec}{,From}NB{,'}`, `send{Arr,Vec}{,To}NB{,'}`.
4005
4006 * 2003-09-24
4007 ** Tracking basis library changes:
4008 *** `TextIO.inputLine` now returns a `string option`.
4009 *** Slices used in `Byte`, `PRIM_IO`, `PrimIO`, `Posix.IO`, `StreamIO`.
4010 *** `Posix.IO.readVec` raises `Size`, not `Subscript`, with negative
4011 argument.
4012
4013 * 2003-09-22
4014 ** Fixed `Real.toManExp` so that the mantissa is in [0.5, 1), not [1, 2). The
4015 spec says that 1.0 &lt;= man * radix &lt; radix, which since radix is 2, implies
4016 that the mantissa is in [0.5, 1).
4017 ** Added `Time.{from,to}Nanoseconds`.
4018
4019 * 2003-09-11
4020 ** Added `Real.realRound`.
4021 ** Added `Char{Array,Vector}Slice` to `Text`.
4022
4023 * 2003-09-11
4024 ** `OS.IO.poll` and `Socket.select` now raise errors on negative timeouts.
4025 ** `Time.time` is now implemented using `IntInf` instead of `Int`, which means
4026 that a much larger range of time values is representable.
4027
4028 * 2003-09-10
4029 ** `Word64` is now there.
4030
4031 * 2003-09-09
4032 ** Replaced `Pack32{Big,Little}` with `PackWord32{Big,Little}`.
4033 ** Fixed bug in `OS.FileSys.fullPath`, which mistakenly stopped as soon as it
4034 hit a symbolic link.
4035
4036 * 2003-09-08
4037 ** Fixed `@MLton max-heap`, which was mistakenly ignored. Cleaned up `@MLton
4038 fixed-heap`. Both `fixed-heap` and `max-heap` can use copying or mark-compact
4039 collection.
4040
4041 * 2003-09-06
4042 ** `Int64` is completely there.
4043 ** Fixed `OS.FileSys.tmpName` so that it creates the file, and doesn't use
4044 `tmpnam`. This eliminates an annoying linker warning message.
4045
4046 * 2003-09-05
4047 ** Added structures `{LargeInt,LargeReal,LargeWord,Word}{Array,Array2,ArraySlice,Vector,VectorSlice}`
4048 ** Fixed bug in `Real.toDecimal`, which return class `NORMAL` for subnormals.
4049 ** Fixed bug in `Real.toLargeInt`, which didn't return as precise an integer
4050 as possible.
4051
4052 * 2003-09-03
4053 ** Lots of fixes to `REAL` functions.
4054 *** `Real32` is now completely in place, except for `Real32.nextAfter` on
4055 SunOS.
4056 *** Fixed `Real.Math.exp` on x86 to return the right value when applied to
4057 `posInf` and `negInf`.
4058 *** Changed `Real.Math.{cos,sin,tan}` on x86 to always use a call to the C
4059 math library instead of using the x86 instruction. This eliminates some
4060 anomalies between compiling `-native false` and `-native true`.
4061 *** Change `Real.Math.pow` to handle exceptional cases in the SML code.
4062 *** Fixed `Real.signBit` on Sparcs.
4063
4064 * 2003-08-28
4065 ** Fixed `PackReal{,64}Little` to work correctly on Sparc.
4066 ** Added `PackReal{,64}Big`, `PackReal32{Big,Little}`.
4067 ** Added `-runtime` switch, which passes arguments to the runtime via
4068 `@MLton`. These arguments are processed before command line switches.
4069 ** Eliminated MLton switch `-may-load-world`. Can use `-runtime` combined
4070 with new runtime switch `-no-load-world` to disable load world in an
4071 executable.
4072
4073 * 2003-08-26
4074 ** Changed `-host` to `-target`.
4075 ** Split `MLton.Platform.{arch,os}` into `MLton.Platform.{Arch,OS}.t`.
4076
4077 * 2003-08-21
4078 ** Fixed bug in C codegen that would cause undefined references to
4079 `Real_{fetch,move,store}` when compiling on Sparcs with `-align 4`.
4080
4081 * 2003-08-17
4082 ** Eliminated `-link` and `-lib-search`, which are no longer needed.
4083 Eliminated support for passing `-l*`, `-L*`, and `*.a` on the command line.
4084 Use `-link-opt` instead.
4085
4086 * 2003-08-16
4087 ** Added `-link-opt`, for passing options to `gcc` when linking.
4088
4089 * 2003-07-19
4090 ** Renamed `_ffi` as `_import`. The old `_ffi` will remain for a while, but
4091 is deprecated and should be replaced with `_import`.
4092 ** Added attributes to `_export` and `_import`. For now, the only attributes
4093 are `cdecl` and `stdcall`.
4094
4095
4096 == Version 20030716
4097
4098 Here are the changes from version 20030711 to 20030716.
4099
4100 == Summary
4101
4102 * Fixed several serious bugs with the 20030711 release.
4103
4104 == Details
4105
4106 * 2003-07-15
4107 ** Fixed bug that caused a segfault when attempting to create an
4108 array that was too large, e.g
4109
4110 1 + Array.sub (Array.tabulate (valOf Int.maxInt, fn i =&gt; i), 0)
4111
4112 ** mlton now checks the command line arguments following the file to compile
4113 that are passed to the linker to make sure they are reasonable.
4114
4115 * 2003-07-14
4116 ** Fixed packaging for Cygwin and Sparc to include `libgmp.a`.
4117 ** Eliminated bootstrap target. The `Makefile` automatically determines
4118 whether to bootstrap or not.
4119 ** Fixed XML type checker bug that could cause error: `"empty tyvars in
4120 PolyVal dec"`.
4121
4122 * 2003-07-12
4123 ** Turned off `FORCE_GENERATIONAL` in gc. It had been set, which caused the
4124 gc to always use generational collection. This could seriously slow apps down
4125 that don't need it.
4126
4127
4128 == Version 20030711
4129
4130 Here are the changes from version 20030312 to 20030711.
4131
4132 === Summary
4133
4134 * Added support for Sparc/SunOS using the C code generator.
4135 * Completed the basis library implementation. At this point, the only missing
4136 basis library function is `use`.
4137 * Added `_export`, which allows one to call SML functions from C.
4138 * Added weak pointers (via `MLton.Weak`) and finalization (via
4139 `MLton.Finalizable`).
4140 * Added new integer modules: `Int8`, `Int16`.
4141 * Better profiling call graphs
4142 * Fixed conversions between reals and their decimal representations to be
4143 correct using the gdtoa library.
4144
4145 === Details
4146
4147 * 2003-07-07
4148 ** Profiling improvements:
4149 *** Eliminated `mlton -profile-split`. Added `mlprof -split`. Now the
4150 profiling infrastructure keeps track of the splits and allows one to decide
4151 which splits to make (if any) when `mlprof` is run, which is much better
4152 than having to decide at compile time.
4153 *** Changed `mlprof -graph` to `mlprof -keep`, and changed the behavior so
4154 that `-keep` also controls which functions are displayed in the table.
4155 *** Eliminated `mlprof -ignore`: it's behavior is now subsumed by `-keep`,
4156 whose meaning has changed to be more like -ignore on nodes that are not
4157 kept.
4158 ** When calling `gcc` for linking, put `-link` args in same order as they
4159 appeared on the MLton command line (they used to be reversed).
4160
4161 * 2003-07-03
4162 ** Making `OS.Process.{atExit,exit}` conform to the basis library spec in that
4163 exceptions raised during cleaners are caught and ignored. Also, calls to
4164 `exit` from cleaners cause the rest of cleaners to run.
4165
4166 * 2003-07-02
4167 ** Fixed bug with negative `IntInf` constants that could cause compile time
4168 error message: `"x86Translate.translateChunk ... strange Offset: base: ..."`
4169 ** Changed argument type of `MLton.IntInf.Small` from `word` to `int`.
4170 ** Added fix to profiling so that the `mlmon.out` file is written even when
4171 the program terminates due to running out of memory.
4172
4173 * 2003-06-25
4174 ** Added `{Int{8,16},Word8}{,Array,ArraySlice,Vector,VectorSlice,Array2}`
4175 structures.
4176
4177 * 2003-06-25
4178 ** Fixed bug in `IntInf.sign`, which returned the wrong value for zero.
4179
4180 * 2003-06-24
4181 ** Added `_export`, for calling from C to SML.
4182
4183 * 2003-06-18
4184 ** Regularization of options:
4185 *** `-diag` --&gt; `-diag-pass`
4186 *** `-drop-pass` takes a regexp
4187
4188 * 2003-06-06
4189 ** Fixed bug in `OS.IO.poll` that caused it to return the input event types
4190 polled for instead of what was actually available.
4191
4192 * 2003-06-04
4193 ** Fixed bug in KnownCase SSA optimization that could case incorrect results
4194 in compiled programs.
4195
4196 * 2003-06-03
4197 ** Fixed bug in SSA optimizer that could cause the error message:
4198
4199 Type error: Type.equals
4200 {from = char vector, to = unit vector}
4201 Type error: analyze raised exception loopStatement: ...
4202 unhandled exception: TypeError
4203
4204 * 2003-06-02
4205 ** Fixed `Real.rem` to work correctly on `inf`-s and `nan`-s.
4206 ** Fixed bug in profiling that caused the function name to be omitted on
4207 functions defined by `val rec`.
4208
4209 * 2003-05-31
4210 ** `Fixed Real.{fmt,fromString,scan,toString}` to match the basis library
4211 spec.
4212 ** Added `IEEEReal.{fromString,scan}`.
4213 ** Added `Real.{from,to}Decimal`.
4214
4215 * 2003-05-25
4216 ** Added `Real.nextAfter`.
4217 ** Added `OS.Path.{from,to}UnixPath`, which are the identity function on Unix.
4218
4219 * 2003-05-20
4220 ** Added type `MLton.pointer`, the type of C pointers, for use with the FFI.
4221
4222 * 2003-05-18
4223 ** Fixed two bugs in type inference that could cause the compiler to raise the
4224 `TypeError` exception, along with a lot of XML IL. The `type-check.sml`
4225 regression contains simple examples of what failed.
4226 ** Fixed a bug in the simplifier that could cause the message: `"shrinker
4227 raised Prim.apply raised assertion failure: SmallIntInf.fromWord"`.
4228
4229 * 2003-05-15
4230 ** Fixed bug in `Real.class` introduced on 04-28 that cause many regression
4231 failures with reals when using newer `gcc`-s.
4232 ** Replaced `MLton.Finalize` with `MLton.Finalizable`, which has a more robust
4233 approach to finalization.
4234
4235 * 2003-05-13
4236 ** Fixed bug in `MLton.FFI` on Cygwin that caused `Thread_returnToC` to be
4237 undefined.
4238
4239 * 2003-05-12
4240 ** Added support for finalization with `MLton.Finalize`.
4241
4242 * 2003-05-09
4243 ** Fixed a runtime system bug that could cause a segfault. This bug would
4244 happen after a GC during heap resizing when copying a heap, if the heap was
4245 allocated at a very low (&lt;10M) address. The bug actually showed up on a
4246 Cygwin system.
4247
4248 * 2003-05-08
4249 ** Fixed bug in `HashType` that raised `"Vector.forall2"` when the arity of a
4250 type constructor is changed by `SimplifyTypes`, but a newly constructed type
4251 has the same hash value.
4252
4253 * 2003-05-02
4254 ** Switched over to new layered IO implementation, which completes the
4255 implementation of the `BinIO` and `TextIO` modules.
4256
4257 * 2003-04-28
4258 ** Fixed bug that caused an assertion failure when generating a jump table for
4259 a case dispatch on a non-word sized index with non-zero lower bound on the
4260 range.
4261
4262 * 2003-04-24
4263 ** Added `-align {4|8}`, which controls alignment of objects. With `-align
4264 8`, memory accesses to doubles are guaranteed to be aligned mod 8, and so
4265 don't need special routines to load or store.
4266
4267 * 2003-04-22
4268 ** Fixed bug that caused a total failure of time profiling with `-native
4269 false`. The bug was introduced with the C codegen improvements that split the
4270 C into multiple files. Now, the C codegen declares all profile labels used in
4271 each file so that they are global symbols.
4272
4273 * 2003-04-18
4274 ** Added `MLton.Weak`, which supports weak pointers.
4275
4276 * 2003-04-10
4277 ** Replaced the basis library's `MLton.hostType` with `MLton.Platform.arch`
4278 and `MLton.Platform.os`.
4279
4280 * 2003-04
4281 ** Added support for SPARC/SunOS using the C codegen.
4282
4283 * 2003-03-25
4284 ** Added `MLton.FFI`, which allows callbacks to SML from C.
4285
4286 * 2003-03-21
4287 ** Fixed `mlprof` so that the default `-graph arg` for data from
4288 `-profile-stack true` is `(thresh-stack x)`, not `(thresh x)`.
4289
4290
4291 == Version 20030312
4292
4293 Here are the changes from version 20020923 to 20030312.
4294
4295 === Summary
4296
4297 * Added source-level profiling of both time and allocation.
4298 * Updated basis library to 2002 specification. To obtain the old
4299 library, compile with `-basis 1997`.
4300 * Added many modules to basis library:
4301 ** `BinPrimIO`, `GenericSock`, `ImperativeIO`, `INetSock`, `NetHostDB`,
4302 `NetProtDB`, `NetServDB`, `Socket`, `StreamIO`, `TextPrimIO`, `UnixSock`.
4303 * Completed implementation of `IntInf` and `OS.IO`.
4304
4305 === Details
4306
4307 * 2003-02-23
4308 ** Replaced `-profile-combine` wih `-profile-split`.
4309
4310 * 2003-02-11
4311 ** Regularization of options:
4312 *** `-l` --&gt; `-link`
4313 *** `-L` --&gt; `-lib-search`
4314 *** `-o` --&gt; `-output`
4315 *** `-v` --&gt; `-verbose`
4316
4317 * 2003-02-10
4318 ** Added option to `mlton`: `-profile-combine {false|true}`
4319
4320 * 2003-02-09
4321 ** Added options to `mlprof`: `-graph-title`, `-gray`, `-ignore`, `-mlmon`,
4322 `-tolerant`.
4323
4324 * 2002-11 - 2003-01
4325 ** Added source-level allocation and time profiling. This includes the new
4326 options to mlton: `-profile` and `-profile-stack`.
4327
4328 * 2002-12-28
4329 ** Added `NetHostDB`, `NetProtDB`, `NetServDB` structures.
4330 ** Added `Socket`, `GenericSock`, `INetSock`, `UnixSock` structures.
4331
4332 * 2002-12-19
4333 ** Fixed bug in signal check insertion that could cause some signals to be
4334 missed. The fix was to add a signal check on entry to each function in
4335 addition to at each loop header.
4336
4337 * 2002-12-10
4338 ** Fixed bug in runtime that might cause the message `"Unable to set
4339 cardMapForMutator"`.
4340
4341 * 2002-11-23
4342 ** Added support for the latest Basis Library specification.
4343 ** Added option `-basis` to choose Basis Library version. Currently available
4344 basis libraries are `2002`, `2002-strict`, `1997`, and `none`.
4345 ** Added `IntInf.{orb,xorb,andb,notb,&lt;&lt;,~&gt;&gt;}` values.
4346 ** Added `OS.IO.{poll_desc,poll_info}` types.
4347 ** Added `OS.IO.{pollDesc,pollToIODesc,infoToPollDesc,Poll}` values.
4348 ** Added `OS.IO.{pollIn,pollOut,pollPri,poll,isIn,isOut,isPri}` values.
4349 ** Added `BinPrimIO`, `TextPrimIO` structures.
4350 ** Added `StreamIO`, `ImperativeIO` functors.
4351
4352 * 2002-11-22
4353 ** Fixed bug that caused time profiling to fail (with a segfault) when
4354 resuming a saved world.
4355
4356 * 2002-11-07
4357 ** Fixed bug in `MLton.eq` that could arise when using `eq` on functions.
4358
4359 * 2002-11-05
4360 ** Improvements to polymorphic equality. Equality on IntInfs, vectors, and
4361 dataypes all do an `eq` test first before a more expensive comparison.
4362
4363 * 2002-11-01
4364 ** Added allocation profiling. Now, can compile with either `-profile alloc`
4365 or `-profile time`. Renamed `MLton.Profile` as `MLton.ProfileTime`. Added
4366 `MLton.ProfileAlloc`. Cleaned up and changed most `mlprof` option names.
4367
4368 * 2002-10-31
4369 ** Eliminated `MLton.debug`.
4370 ** Fixed bug in the optimizer that affected `IntInf.fmt`. The optimizer had
4371 been always using base 10, instead of the passed in radix.
4372
4373 * 2002-10-22
4374 ** Fixed `Real.toManExp` so that the mantissa is in [1, 2), not [0.5, 1).
4375 ** Added `Real.fromLargeInt`, `Real.toLargeInt`.
4376 ** Fixed `Real.split`, which would return an incorrect whole part due to the
4377 underlying primitive, `Real_modf`, being treated as functional instead of
4378 side-effecting.
4379
4380 * 2002-09-30
4381 ** Fixed `rpath` problem with packaging. All executables in packages
4382 previously made had included a setting for `RPATH`.
4383
4384
4385 == Version 20020923
4386
4387 Here are the changes from version 20020410 to 20020923.
4388
4389 === Summary
4390
4391 * MLton now runs on FreeBSD.
4392 * Major runtime system improvements. The runtime now implements mark-compact
4393 and generational collection, in addition to the copying collection that was
4394 there before. It automatically switches between the the collection strategies
4395 to improve performance and to try to avoid paging.
4396 * Performance when compiling `-exn-history true` has been improved.
4397 * Added `IntInf.log2`, `MLton.GC.pack`, `MLton.GC.unpack`.
4398 * Fixed bug in load world that could cause "sread failed" on Cygwin.
4399 * Fixed optimizer bug that could cause `"no analyze var value property"`
4400 message.
4401
4402 === Details
4403
4404 * 2002-09
4405 ** Integrated Sam Rushing's changes to port MLton to FreeBSD.
4406
4407 * 2002-08-25
4408 ** Changed the implementation of exception history to be completely
4409 functional. Now, the extra field in exceptions (when compiling `-exn-history
4410 true`) is a `string list` instead of a `string list ref`, and `raise` conses a
4411 new exception with a new element in the list instead of assigning to the list.
4412 This changes the semantics of exception history (for the better) on some
4413 programs. See `regression/exnHistory3.sml` for an example. It also
4414 significantly improves performance when compiling `-exn-history true`.
4415
4416 * 2002-07 and 2002-08
4417 ** Added generational GC, and code to the runtime that automatically turns it
4418 on and off.
4419
4420 * 2002-08-20
4421 ** Fixed SSA optimizer bug that could cause the following error message: `"x_0
4422 has no analyze var value property"`
4423
4424 * 2002-07-28
4425 ** Added `MLton.GC.{pack,unpack}`. `pack` shrinks the heap so that other
4426 processes can use the RAM, and its dual, `unpack`, resizes the heap to the
4427 desired size.
4428
4429 * 2002-06 and 2002-07
4430 ** Added mark compact GC.
4431 ** Changed array layout so that arrays have three, not two header words. The
4432 new word is a counter word that preceeds the array length and header.
4433 ** Changed all header words to be indices into an array of object descriptors.
4434
4435 * 2002-06-27
4436 ** Added patches from Michael Neumann to port runtime to FreeBSD 4.5.
4437
4438 * 2002-06-05
4439 ** Output file and intermediate file are now saved in the current directory
4440 instead of in the directory containing the input file.
4441
4442 * 2002-05-31
4443 ** Fixed bug in overloading of `/` so that the following now type checks:
4444
4445 fun f (x, y) = x + y / y
4446
4447 * 2002-04-26
4448 ** Added back `max-heap` runtime option.
4449
4450 * 2002-04-25
4451 ** Fixed load/save world so that they use binary mode. This should fix the
4452 `sread failed` problem that Byron Hale saw on Cygwin that caused `mlton` to
4453 fail to start.
4454 ** Added `IntInf.log2`.
4455 ** Changed call to linker to use `libgmp.a` (if it exists) instead of
4456 `libgmp.so`. This is because the linker adds a dependency to a shared library
4457 even if there are no references to it
4458
4459 * 2002-04-23
4460 ** Rewrote heap resizing code. This fixed bug that was triggered with large
4461 heaps and could cause a spurious out of memory error.
4462 ** Removed GnuMP from MLton sources (again :-).
4463
4464
4465 == Version 20020410
4466
4467 Here are the changes from version 20011006 to version 20020410.
4468
4469 === Details
4470
4471 * 2002-03-28
4472 ** Added BinIO.
4473
4474 * 2002-03-27
4475 ** Regularization of options
4476 *** `-g` --&gt; `-degug {false|true}`
4477 *** `-h n` --&gt; `-fixed-heap n`
4478 *** `-p` --&gt; `-profile {false|true}`
4479
4480 * 2002-03-22
4481 ** Set up the stubs so that MLton can be compiled in the standard basis
4482 library, with no `MLton` structure. Thus it is now easy to compile MLton with
4483 an older (or newer) version of itself that has a different `MLton` structure.
4484
4485 * 2002-03-17
4486 ** Added `MLton.Process.{spawn,spawne,spawnp}`, which use primitives when
4487 running on Cygwin and fork/exec when running on Linux.
4488
4489 * 2002-02 - 2002-03
4490 ** Added the ability to cross-compile to Cygwin/Windows.
4491
4492 * 2002-02-24
4493 ** Added GnuMP back for use with Cygwin.
4494
4495 * 2002-02-10
4496 ** Reworked object header words so that `Array.maxLen = valOf Int.maxInt`.
4497 Also fixed a long-standing minor bug in MLton, where `Array.array
4498 (Array.maxLen, ...)` would raise `Size` instead of attempting to allocate the
4499 array. It was an off-by-one error in the meaning of `Array.maxLen`.
4500
4501 * 2002-02-08
4502 ** Modifications to runtime to behave better in situations where the amount of
4503 live data is a signifant fraction of the amount of RAM, based on code from
4504 PolySpace. MLton executables by default can now use more than the available
4505 amount of RAM. Executables will still respect the `max-heap` runtime arg if
4506 it is set.
4507
4508 * 2002-02-04
4509 ** Improvements to runtime so that it fails to get space, it attempts to get
4510 less space instead of failing. Based on PolySpace's modifications.
4511 ** Added `MLton.eq`.
4512
4513 * 2002-02-03
4514 ** Added `MLton.IntInf.gcd`.
4515 ** Removed GnuMP from MLton sources. We now link with `/usr/lib/libgmp.a`.
4516 ** Added `TextIO.getPosOut`.
4517 ** Renamed type `MLton.Itimer.which` to `MLton.Itimer.t` and
4518 `MLton.Itimer.whichSignal` to `MLton.Itimer.signal`.
4519 ** Added `-coalesce` flag, for use with the C backend.
4520
4521 * 2002-01-26
4522 ** Added `-show-basis-used`, which prints out the parts of the basis library
4523 that the input program uses.
4524 ** Changed several other flags (`-print-at-fun-entry`, `-show-basis`,
4525 `-static`) to follow the `{false|true}` convention.
4526
4527 * 2002-01-22
4528 ** Improved `MLton.profile` so that multiple profile arrays can exist
4529 simultaneously and so that the current one being used can be set from the SML
4530 side.
4531
4532 * 2002-01-18
4533 ** The Machine IL has been replaced with an RSSA (representation explicit SSA)
4534 IL and an improved Machine IL.
4535
4536 * 2002-01-16
4537 ** Added KnownCase SSA optimization
4538
4539 * 2002-01-14
4540 ** Added rudimentary profiling control from with a MLton compile program via
4541 the `MLton.Profile` structure.
4542
4543 * 2002-01-09
4544 ** Fixed bug in match compiler that caused case expressions on datatypes with
4545 redundant cases to be compiled incorrectly.
4546
4547 * 2002-01-08
4548 ** Added redundant tuple construction elimination to SSA shrinker.
4549 ** Improved Flatten SSA optimization.
4550
4551 * 2001-12-06
4552 ** Changed the interface for `MLton.Signal`. There is no longer a separate
4553 `Handler` substructure. This was done so that programs that just use
4554 `default` and `ignore` signal handlers don't bring in the entire thread
4555 mechanism.
4556
4557 * 2001-12-05
4558 ** Added LocalRef elimination SSA optimization.
4559
4560 * 2001-11-19
4561 ** The CPS IL has been replaced with an SSA (static-single assignment) IL.
4562 All of the optimizations have been ported from CPS to SSA.
4563
4564 * 2001-10-24
4565 ** Fixed bug in `Thread_atomicEnd` -- `limit` was mistakenly set to `base`
4566 instead of to 0. This caused assertion failures when for executables compiled
4567 `-g` because `GC_enter` didn't reset `limit`.
4568 ** Fixed bug in register allocation of byte registers.
4569
4570 * 2001-10-23
4571 ** Added `-D` option to `cmcat` for preprocessor defines. Thanks to Anoq for
4572 sending the code.
4573 ** Changed limit check insertion so that limit checks are only coalesced
4574 within a single basic block -- not across blocks. This slows many benchmarks
4575 down, but is needed to fix a bug in the way that limit checks were coalesced
4576 across blocks. Hopefully we will figure out a better fix soon.
4577
4578 * 2001-10-18
4579 ** Fixed type inference of flexrecord so that it now follows the Definition.
4580 Many programs containing flexrecords were incorrectly rejected. Added many
4581 new tests to regression/flexrecord.sml.
4582 ** Changed the behavior of `-keep dot` combined with `-keep pass` for SSA
4583 passes. Dot files are now saved for the program before and after, instead of
4584 just after.
4585
4586 * 2001-10-11
4587 ** Fixed a bug in the type inference that caused type variables to be
4588 mistakenly generalized. The bug was exposed in Norman Ramsey's `sled.sml`.
4589 Added a test to `regression/flexrecord.sml` to catch the problem.
4590
4591
4592 == Version 20011006
4593
4594 Here are the changes from version 20010806 to version 20011006.
4595
4596 === Summary
4597
4598 * Added `MLton.Exn.history`, which is similar to `SMLofNJ.exnHistory`.
4599 * Support for `#line` directives of the form `(*#line line.col "file"*)`.
4600 * Performance improvements in native codegenerator.
4601 * Bug fixes in front-end, optimizer, register allocator,
4602 `Real.{maxFinite,minPos,toManExp}`, and in heap save and restore.
4603
4604 === Details
4605
4606 * 2001-10-05
4607 ** Fixed a bug in polymorphic layered patterns, like
4608
4609 val 'a a as b = []
4610
4611 These would always fail due to the variable `a` not being handled correctly.
4612 ** Fixed the syntax of `val rec` so that a pattern is allowed on the left-hand
4613 side of the `=`. Thus, we used to reject, but now accept, the following.
4614
4615 val rec a as b as c = fn _ =&gt; ()
4616 val rec a : unit -&gt; unit : unit -&gt; unit = fn () =&gt; ()
4617
4618 Thanks again to Andreas Rossberg's test files. This is now tested for in
4619 `valrec.sml`.
4620 ** Fixed dynamic semantics of `val rec` so that if `val rec` is used to
4621 override constructor status, then at run time, the `Bind` exception is raised
4622 as per rule 126 of the Definition. So, for example, the following program
4623 type checks and compiles, but raises `Bind` at run time.
4624
4625 val rec NONE = fn () =&gt; ()
4626 val _ = NONE ()
4627
4628 Again, this is checked in `valrec.sml`.
4629 ** Added `\r\n` to ml.lex so that Windows style newlines are acceptable in
4630 input files.
4631
4632 * 2001-10-04
4633 ** Fixed bug in the implementation of `open` declarations, which in the case
4634 of `open A B` had opened `A` and then looked up `B` in the resulting
4635 environment. The correct behaviour (see rule 22 of the Definition) is to
4636 lookup each _longstrid_ in the current environment, and then open them all in
4637 sequence. This is now checked for in the `open.sml` regression test. Thanks
4638 to Andreas Rossberg for pointing this bug out.
4639 ** Fixed bug that caused tyvars of length 1 (i.e. `'`) to be rejected. This
4640 is now checked in the `id.sml` regression test. Again, thanks to Andreas
4641 Rossberg for the test.
4642
4643 * 2001-10-02
4644 ** Fixed bugs in `Real.toManExp` (which always returned the wrong result
4645 because the call to `frexp` was not treated as side-effecting by the
4646 optimizer) and in `Real.minPos`, which was zero because of a mistake with
4647 extra precision bits.
4648
4649 * 2001-10-01
4650 ** Added `MLton.Exn.history`.
4651 ** Fixed register allocation bug with `fucom` instruction. Was allowing
4652 `fucomp` when the first source was not removable.
4653 ** Changed `Real.isFinite` to use the C `math.h` `finite` function. This
4654 fixed the nontermination bug which occurred in any program that used
4655 `Real.maxFinite`.
4656
4657 * 2001-09-22
4658 ** Bug fixes found from Ramsey's `lrtl` in `contify.fun` and
4659 `unused-args.fun`, both of which caused compile-time exceptions to be raised.
4660
4661 * 2001-09-21
4662 ** Fixed `MLton.World.{load,save}` so that the saved world does not store the
4663 max heap size. Instead, the max heap size is computed upon load world in
4664 exactly the same way as at program startup. This fixes a long-standing (but
4665 only recently noticed) problem in which `mlton` (which uses a saved world)
4666 would attempt to use as much memory as was on the machine used to build
4667 `world.mlton`.
4668
4669 * 2001-08-29
4670 ** Overlow checking is now on by default in the C backend. This is a huge
4671 performance hit, but who cares, since we never use the C backend except for
4672 testing anyways.
4673
4674 * 2001-08-22
4675 ** Added support for #line directives of the form
4676
4677 (*#line line.col "file"*)
4678
4679 These directives only affect error messages produced by the parser and
4680 elaborator.
4681
4682 * 2001-08-17
4683 ** Fixed bug in RemoveUnused optimzation that caused the following program to
4684 fail to compile.
4685
4686 fun f l = case l of [] =&gt; f l | _ :: l =&gt; f l
4687 val _ = f [13]
4688
4689 * 2001-08-14
4690 ** New x86-codegen infrastructure.
4691 *** support for tracking liveness of stack slots and carrying them in
4692 registers across basic blocks
4693 *** more specific `Entry` and `Transfer` datatypes to make calling convention
4694 distinctions more explicit
4695 *** new heuristic for carrying values in registers across basic blocks (look
4696 Ma, no Overflows!)
4697 *** new "predict" model for generating register allocation hints
4698 *** additional bug fixes
4699
4700 * 2001-08-07
4701 ** `MLton.Socket.shutdownWrite` flushes the outstream.
4702
4703
4704 == Version 20010806
4705
4706 Here are the changes from version 20010706 to version 20010806.
4707
4708 === Summary
4709
4710 * `Word.andb (w, 0xFF)` now works correctly
4711 * `MLton.Rusage.rusage` has a patch to work around a linux kernel bug
4712 * Programs of the form `_exp_ ; _program_` are now accepted
4713 * Added the `MLton.Rlimit` structure
4714 * Added the `-keep dot` flag, which produces call graphs, intraprocedural
4715 control-flow graphs, and dominator trees
4716
4717 === Details
4718
4719 * 2001-08-06
4720 ** Added simple CommonBlock elimination CPS optimization.
4721
4722 * 2001-08-02
4723 ** Took out `-keep il`.
4724
4725 * 2001-07-31
4726 ** Performance improvements to `TextIO.{input, output, output1}`.
4727
4728 * 2001-07-25
4729 ** Added RedundantTest elimination CPS optimization.
4730
4731 * 2001-07-21
4732 ** Added CommonSubexp elimination CPS optimization.
4733
4734 * 2001-07-20
4735 ** Bug fix to x86 codegen. The `commuteBinALMD` peephole optimization would
4736 rewrite `mov 2,Y; add Y,Y` as `mov Y,Y; add 2,Y`. Now the appropriate
4737 interference checks are made.
4738 ** Added intraprocedural unused argument removal.
4739 ** Added intraprocedural flattener. This avoids some stupid tuple allocations
4740 in loops. Decent speedup on a few benchmarks (`count-graphs`, `psdes-random`,
4741 `wc-scanStream`) and no noticeable slowdowns.
4742 ** Added `-keep dot` flag.
4743
4744 * 2001-07-17
4745 ** Modified grammar to properly handle `val rec`. There were several problems.
4746 *** MLton had accepted `val rec 'a ...` instead of `val 'a rec ...`
4747 *** MLton had not accepted `val x = 13 and rec f = fn () =&gt; ()`
4748 *** MLton had not accepted `val rec rec f = fn () =&gt; ()`
4749 *** MLton had not accepted `val rec f = fn () =&gt; () and rec g = fn () =&gt; ()`
4750
4751 * 2001-07-16
4752 ** Workaround for Linux kernel bug that can cause `getrusage` to return a wrong
4753 system time value (low by one second). See `fixedGetrusage` in `gc.c`.
4754 ** Bug fix to x86 codegen. The register allocator could get confused when
4755 doing comparisons of floating point numbers and use the wrong operand. The
4756 bug seems to have never been detected because it only happens when both of the
4757 operands are already on the floating point stack, which is rare, since one is
4758 almost always in memory since we don't carry floating point values in the
4759 stack across basic blocks.
4760 ** Added production to the grammar on page 58 of the Definition that had been
4761 missing from MLton since day one.
4762
4763 program ::= exp ; &lt;program&gt;
4764
4765 Also updated docs to reflect change.
4766 ** Modified grammar to accept the empty program.
4767 ** Added `-type-check` expert flag to turn on type checking in ILs.
4768
4769 * 2001-07-15
4770 ** Bug fix to the algebraic simplifier. It had been rewriting
4771 `Word32.andb (w, 0wxFF)` to `w` instead of
4772 `Word32.andb (w, 0wxFFFFFFFF)` to `w`.
4773
4774 * 2001-07-13
4775 ** Improved CPS shrinker so that `if`-tests where the `then` and `else` branch
4776 jump to the same label is turned into a direct jump.
4777 ** Improved CPS shrinker (`Prim.apply`) to handle constructors
4778 *** `A = A` --&gt; `true`
4779 *** `A = B` --&gt; `false`
4780 *** `A x` = `B y` --&gt; `false`
4781 ** Rewrote a lot of loops in the basis library to use inequalities instead of
4782 equality for the loop termination test so that the (forthcoming) overflow
4783 detection elimination will work on the loop index variable.
4784
4785 * 2001-07-11
4786 ** Fixed minor bugs in `Array2.{array,tabulate}`, `Substring.{slice}` that
4787 caused the `Overflow` exception to be raised instead of `Size` or `Subscript`
4788 ** Fixed bug in `Pack32Big.update` that caused the wrong location to be updated.
4789 ** Fixed several bugs in `Pack32{Big,Little}.{subArr,subVec,update}` that
4790 caused `Overflow` to be raised instead of `Subscript`. Also, improved the
4791 implementation so that bounds checking only occurs once per call (instead of
4792 four times, which was sometimes happening.
4793 ** Fixed bugs in `Time.{toMilliseconds,toMicroseconds}` that could cause a
4794 spurious `Overflow` exception.
4795 ** Fixed bugs in `Time.{fromMilliseconds,fromMicroseconds}` that could cause a
4796 spurious `Time` exception.
4797 ** Improved `Pack32.sub*` by reordering the `orb`-s.
4798 ** Improved `{Int,IntInf}.mod` to increase chances of constant folding.
4799 ** Switched many uses of `+`, `-`, `*` in basis library to the non-overflow
4800 checked versions. Modules changed were: `Array`, `Array2`, `Byte`, `Char`,
4801 `Int`, `IntInf`, `List`, `Pack32{Big,Little}`, `Util`, `String`, `StringCvt`,
4802 `Substring`, `TextIO`, `Time`, `Vector`.
4803 ** Added regression tests for `Array2`, `Int` (overflow checking), `Pack32`,
4804 `Substring`, `Time`.
4805 ** Changed CPS output so that it includes a dot graph for each CPS function.
4806
4807 * 2001-07-09
4808 ** Change `OS.Process.exit` so that it raises an exception if the exit status
4809 is not in [0, 256).
4810 ** Added `MLton.Rlimit` to provide access to `getrlimit` and `setrlimit`.
4811
4812
4813 == Version 20010706
4814
4815 Here are the changes from the 20000906 version to the 20010706 version.
4816
4817 === Summary
4818
4819 * Native X86 code generator (instead of using `gcc`)
4820 * Significantly improved compile times
4821 * Significantly improved run times for generated executables
4822 * Many bug fixes
4823 * Correct raising of the `Overflow` exception for integer arithmetic
4824 * New modules in the `MLton` structure
4825
4826 === Details
4827
4828 * 2001-07-06
4829 ** GC mods from Henry. Mostly adding `inline` declarations.
4830
4831 * 2001-07-05
4832 ** Fixed several runtime bugs involving threads, critical sections, and
4833 signals.
4834
4835 * 2001-06-29
4836 ** Fixed performance bug in `cps/two-point-lattice.fun` that caused quadratic
4837 behavior. This affects the raise-to-jump and useless analayses. In
4838 particular, the useless analysis was blowing up when compiling `fxp`.
4839
4840 * 2001-06-27
4841 ** Henry improved `wordAlign` -- this sped up GC by 27% (during a self
4842 compile).
4843
4844 * 2001-06-20
4845 ** Moved `MLton.random` to `MLton.Random.rand` and added other stuff to
4846 `MLton.Random`
4847 ** Added `MLton.TextIO.mkstemp`.
4848 ** Made `Int.{div,quot}` respect the `-detect-overflow` switch.
4849
4850 * 2001-06-20
4851 ** Added `MLton.Syslog`.
4852
4853 * 2001-06-07
4854 ** Fixed bug in `MLton.Socket.accept` that was in the runtime implementation
4855 `Socket_accept`. It did a `setsockopt SO_REUSEADDR` after the `accept`. It
4856 should have been after the call to `socket` in `Socket_listen`. Thanks to
4857 Doug Bagley for the fix.
4858
4859 * 2001-05-30
4860 ** Fixed bug in remove-unused that caused polymorphic equality to return
4861 `true` sometimes when constructors were never used in a pattern match. For
4862 example, the following (in which `A` and `B` are not used as patterns):
4863
4864 datatype t = A | B
4865 datatype u = C of t
4866 val _ = if C A = C B then raise Fail "bug" else ()
4867
4868 * 2001-03-27
4869 ** Fixed bug that caused all of the following to fail:
4870 `{LargeWord,Word,SysWord}.{toLargeInt,toLargeIntX,fromLargeInt}` The problem
4871 was the basis library file `integer/patch.sml` which fixed `Word32` but not
4872 the other structures that are the same.
4873
4874 * 2001-02-12
4875 ** Fixed bug in match compiler that caused it to spend a lot of extra time in
4876 deep patterns. It still could be exponential however. Hopefully this will
4877 get fixed in the release after next. This bug could cause very slow compile
4878 times in some cases. Anyways, this fix cut the `finish infer` time of a self
4879 compile down from 22 to under 4 seconds. I.E. most of the time used to be
4880 spent due to this bug.
4881
4882 * 2001-02-06
4883 ** Fixed bug in frontend that caused the wrong file and line number to be
4884 reported with errors in functor bodys.
4885
4886 * 2001-01-03 - 2000-02-05
4887 ** Changes to CoreML, XML, SXML, and CPS ILs to replace lists by vectors in
4888 order to decrease space usage.
4889
4890 * 2001-01-16
4891 ** Fixed a bug in constant propagation where the length of vectors was not
4892 propagated properly.
4893
4894 * 2000-12-11 - 2001-01-03
4895 ** Major rewrite of elaborator to use a single hash table for each namespace
4896 instead of a hash table for every environment.
4897
4898 * 2000-12-20
4899 ** Fixed some bugs in the SML/NJ compatibility library,
4900 `src/lib/mlton-subs-in-smlnj`.
4901
4902 * 2000-12-08
4903 ** More careful removal of tracing code when compiling `MLton_debug=0`. This
4904 cut down self compile data size by 100k and compile time by a few seconds.
4905 ** Added built in character and word cases propagated throughout all ILs.
4906
4907 * 2000-12-06
4908 ** Added max stack size information to `gc-summary`.
4909
4910 * 2000-12-05
4911 ** Added `src/benchmark`, which contains an SML program that benchmarks all of
4912 the SML compilers I have my hands on. The script has lots of hardwired paths
4913 for now.
4914
4915 * 2000-12-04
4916 ** Fixed bug in `Posix.ProcEnv.environ,` which did not work correctly in a
4917 saved world (the original `environ` was saved). In fact, it did not work at
4918 all because the ML primitive expected a constant and the C was a nullary
4919 function. This caused a segfault with any program using
4920 `Posix.ProcEnv.environ`.
4921 ** `Added MLton.ProcEnv.setenv`, since there doesn't seem to be any `setenv`
4922 in the basis library.
4923
4924 * 2000-11-29
4925 ** Changed backend so that it should no longer generate machine programs with
4926 `void` operands.
4927 ** Added `-detect-overflow` and `-safe` flags.
4928
4929 * 2000-11-27 - 2000-11-28
4930 ** Changes in many places to use `List.revMap` instead of `List.map` to cut
4931 down on allocation.
4932
4933 * 2000-11-21
4934 ** Added `MLton.Word.~` and `MLton.Word8.~` to the `MLton` structure.
4935
4936 * 2000-11-20
4937 ** Fixed a bug in the CPS shrinker that could cause a compile-time failure.
4938 It was maintaining occurrence counts incorrectly.
4939
4940 * 2000-11-15
4941 ** Fixed a (performance) bug in constant propagation that caused the hashing
4942 to be bad.
4943 ** Improved translation to XML so that the match compiler isn't called on
4944 tuple or if expressions. This should speed up the translation and make the
4945 output smaller.
4946 ** Fixed a bug in the match compiler that caused it to not generate integer
4947 case statements. This should speed up the mlyacc benchmark and the MLton
4948 front end.
4949
4950 * 2000-11-09
4951 ** Added `IntInf_equal` and `IntInf_compare` primitives.
4952 ** Took out the automatic `-keep c` when compiling `-g`.
4953
4954 * 2000-11-08
4955 ** Added a whole bunch of algebraic laws to the CPS shrinker, including some
4956 specifically targeted to `IntInf` primitives.
4957
4958 * 2000-11-03
4959 ** Improved implementation of properties so that sets don't allocate.
4960 ** Improved implementation of type homomorphism in type inference. What was
4961 there before appears to have been a bug -- it didn't use the property on
4962 types.
4963
4964 * 2000-11-02
4965 ** Fixed timers used with `-v` option to use user + sys time.
4966
4967 * 2000-10-27
4968 ** Split the runtime basis library C files into many separate files so that
4969 only the needed code would be included by the linker.
4970 ** Fixed several bugs in the front end grammar and elaborator that caused type
4971 specifications to be handled incorrectly. The following three programs used
4972 to be handled incorrectly, but are now handled correctly.
4973
4974 signature S = sig type t and u = int end (* reject *)
4975 signature S = sig type t = int and u = t end (* accept *)
4976 signature S = sig eqtype t and u = int end (* reject *)
4977
4978 * 2000-10-25
4979 ** Changes to `main.sml` to run complete compiles with `-native` switch.
4980
4981 * 2000-10-24
4982 ** Removed defunctorizer.
4983
4984 * 2000-10-20
4985 ** Fixed bug in `cps-tree.fun` with `PrimExp.maySideEffect`. This bug could
4986 cause `"no operand"` failures in the backend.
4987 ** Fixed bug in the runtime implementation of `MLton.size`. The size for
4988 stack objects was using the `used` instead of `reserved`, and so was too low.
4989
4990 * 2000-10-19
4991 ** Replaced automatically generated dependencies in `src/runtime/Makefile`
4992 with hand generated ones. Took out `make depend` from `src/Makefile`. `make
4993 depend` was behaving really badly on RHAT 7.0.
4994 ** Tweaked compiler to shorten width of C output lines to work around bug in
4995 RHAT 7.0 `cpp` which silently truncates (very) long lines.
4996 ** Fixed bug in grammar that didn't allow `op` to occur in datatype and
4997 exception bindings, causing the following to fail
4998
4999 datatype t = op T
5000 exception op E = op Fail
5001
5002 ** Improved error messages in CM processor. Fixed bug in CM Alias handling.
5003
5004 * 2000-10-18
5005 ** Fixed two bugs in the gc that did comparisons with `(s-&gt;limit -
5006 s-&gt;frontier)`, which of course doesn't work if `frontier` is beyond `limit`,
5007 since these are unsigned. This could have caused segfaults, except that the
5008 mutator checks the `frontier` upon return from the GC.
5009
5010 * 2000-10-17
5011 ** Fixed bug in backend in the calculation of `maxFrameSize`. It could be
5012 wrong (low) in some situations.
5013 ** Improved CPS inliner's estimate of function sizes. The size of a function
5014 now takes into account other inlined functions that the function calls. This
5015 also changed the meaning of the size argument to the `-inline` switch. It now
5016 corresponds (roughly) to the product of the size of the function and the
5017 number of calls. In general, it should be larger than before.
5018
5019 * 2000-10-13
5020 ** Made some calls to `Array.sub` unsafe in the implementation of `Array2`.
5021 ** Integrated Matthew's new x86 backend with floating point support.
5022
5023 * 2000-10-09
5024 ** Fixed CM file processor so that MLton works if it is run from a different
5025 directory than the main CM file.
5026
5027 * 2000-10-04
5028 ** Changed LimitCheck so it loops on the `frontier &gt; limit` check. This fixed
5029 a potential bug in threads caused when there is enough space available for a
5030 thread, `t`, before switching to another thread but not enough space when it
5031 resumes. This could have caused a segfault.
5032
5033 * 2000-10-03
5034 ** More rewrites of `TextIO.StreamIO` to improve speed.
5035 ** Changed `TextIO` so that only `TextIO.stdErr` is unbuffered.
5036 ** Changed `TextIO` so that FIFOs and sockets are buffered.
5037
5038 * 2000-10-02
5039 ** Combined remove-unused-constructors, remove-unused-functions, and
5040 remove-unused-globals into a single pass that runs to fixed-point and produces
5041 results at least as good as running the previous three in (any) sequence.
5042
5043 * 2000-09-29
5044 ** Added `GC_FIRST_CHECK`, which does a gc at each limit check the first time
5045 it reached.
5046 ** Reimplemented `TextIO.StreamIO` (from 2000-09-12) to use lists of strings
5047 instead of lists of characters so that the per char space overhead is small.
5048
5049 * 2000-09-21
5050 ** Fixed bug in profiling labels in C code. The label was always the basic
5051 block label instead of the cps function label.
5052 ** Added `-b` switch to `mlprof` to gather data at the basic block level.
5053 ** Improved performance of `TextIO.input1` by about 3X.
5054
5055 * 2000-09-15 - 2000-09-19
5056 ** Added overflow exceptions to CPS and Machine ILs.
5057
5058 * 2000-09-12
5059 ** Fixed `TextIO.scanStream`. It was very broken.
5060 ** Added `TextIO.{getInstream,mkInstream,setInstream}` and
5061 `TextIO.StreamIO.{canInput,closeIn,endOfStream,input1,input,inputAll,inputLine,inputN}`.
5062
5063 * 2000-09-11
5064 ** Fixed `Real_qequal` in `mlton-lib.h`. It was missing a paren that caused
5065 code using it to not even compile. It was also semantically incorrect.
5066 ** Noted that `Real_{equal,lt,le,gt,ge}` may not follow basis library spec,
5067 since ANSI does not require IEEE compliance, and hence these could return
5068 wrong results when nans are involved.
5069
5070
5071 == Version 20000906
5072
5073 Here are the changes from the 20000712 version to the 20000906 version.
5074
5075 === Summary
5076
5077 * Version 20000906 is mostly a bugfix release over 20000712. The other major
5078 changes are that `mllex` and `mlyacc` are now included and that `mlton` can now
5079 process a limited subset of CM files as input.
5080
5081 === Details
5082
5083 * 2000-09-06
5084 ** Fixed `Socket_listen` in `mlton-lib.c` so that it closes the socket if the
5085 `bind`, `listen`, or `getsockname` fails. This could have caused a file
5086 descriptor leak.
5087
5088 * 2000-09-05
5089 ** Added `-static` commandline switch.
5090 ** Changed default max heap size to .85 RAM from .95 RAM.
5091 ** Added `PackRealLittle` structure to basis library.
5092
5093 * 2000-08-25
5094 ** Added cases on integers to ILs (instead of using sequences of tests) so
5095 that backend can emit more efficient test (jump table, binary tree, ...).
5096
5097 * 2000-08-24
5098 ** Fixed bug in `gc.c`. `dfsInitializeStack` would `smummap` a `NULL` pointer
5099 whenver `toSpace` was `NULL`. This could cause `MLton.size` to segfault.
5100 ** Fixed bug in `Popt` that caused `-k` to fail with no keeps.
5101
5102 * 2000-08-22 - 2000-08-23
5103 ** Ported `mllex` and `mlyacc` from SML/NJ
5104
5105 * 2000-08-20 - 2000-08-21
5106 ** Added ability to use a `.cm` file as input to MLton.
5107
5108 * 2000-08-16
5109 ** Ported `mlprof` to SML.
5110 ** Fixed bug in `library/basic/assert.sml` that caused asserts to be run even
5111 when `MLton.debug = false`.
5112
5113 * 2000-08-15
5114 ** Fixed bug in backend -- computation of `maxFrameSize` was wrong. It didn't
5115 count slots in frames that didn't make nontail calls. This could lead to the
5116 stack being overwritten because a stack limit check didn't guarantee enough
5117 space, and lead to a segfault.
5118 ** Fixed bug in `gc.c` `newThreadOfSize`. If the thread allocation caused a
5119 gc, then the stack wasn't forwarded, leading to a segfault. The solution was
5120 to ensure enough memory all at once, and then fill in both objects.
5121
5122 * 2000-08-14
5123 ** Changed limit checks so that checks &lt; 512 bytes are replaced by a check for
5124 0 bytes. The runtime also moves the limit down by 512. This is done so that
5125 the common case, a small limit check, has less code and is faster.
5126 ** Fixed bug in `cps/cps-tree.fun`. `Program.hasPrim` returned `true` for any
5127 program that had *any* primapp, not just programs satisfying the predicate.
5128 This caused `cps/once.fun` to be overly conservative, since it thought that
5129 every program used continuations.
5130
5131 * 2000-08-10
5132 ** Fixed bug in CPS typechecker. It didn't enforce that handlers should be
5133 defined before any reference to them -- including implicit references in
5134 `HandlerPops`. This caused an evil bug in the liveness analysis where a
5135 variable that was only live in the handler was missed in a continuation
5136 because the liveness for the handler wasn't computed yet.
5137 ** Limited the size for moving up limit checks for arrays whose size is known
5138 at compile time to avoid huge limit checks getting moved into loops.
5139 ** added `-indent`, `-kp`, `-show-types` switches.
5140 ** Put optimization in CPS IL suggested by Neal Glew. It determines for each
5141 toplevel function if it can raise an exception to its caller. Also, it
5142 removes `HanderPush` and `HandlerPop` for handlers that are not on top of the
5143 stack for any nontail call.
5144
5145 * 2000-08-08
5146 ** Changed register allocator so that continuation formals can be allocated in
5147 pseudo registers -- they aren't necessarily forced to the stack.
5148
5149 * 2000-08-03
5150 ** Fixed bug in constant folding. `Word8.&gt;&gt;` had been used to implement
5151 `Word8.~&gt;&gt;`.
5152 ** Fixed bug in allocate registers that was not forcing the size argument to
5153 `Primitive.Array.array` to be a stack slot. This could cause problems if
5154 there was a thread switch in the limit check, since upon return the size
5155 pseudo register would have a bogus value.
5156
5157 * 2000-08-01
5158 ** Turned back on XML simplification after monomorphisation.
5159
5160 * 2000-07-31
5161 ** Fixed bug in `MLton.Itimer.set` that caused the time to be doubled.
5162 ** Fixed bug in `MLton.Thread` that made it look like asynchronous exceptions
5163 were allowed by `throw`-ing an exception raising thunk to an interrupted
5164 thread obtained via a signal handler. Attempting asynchronous exceptions will
5165 now cause process death, with a helpful error message.
5166
5167 * 2000-07-27
5168 ** Updated docs to include `structure World: MLTON_WORLD` in `MLton`
5169 structure.
5170 ** Added toplevel signatures `MLTON_{CONT, ..., WORLD}` to basis library.
5171 ** Fixed broken link in docs to CM in `cmcat` section.
5172
5173 * 2000-07-26
5174 ** Eliminated `GC_switchToThread` and `Thread_switchTo1`, since the inlined
5175 version `Thread_switchTo` is all that's needed, and Matt's X86 backend now
5176 handles it.
5177 ** Added `MLton.Signal.vtalrm`, needed for `Itimer.Set{which =
5178 Itimer.Virtual, ...}`.
5179
5180 * 2000-07-25
5181 ** Added `MLton.Socket.shutdownWrite`.
5182
5183 * 2000-07-21
5184 ** Updated `mlton-lib.c` `MLton_bug` with new email (MLton@sourcelight.com).
5185
5186 * 2000-07-19
5187 ** Fixed `Posix.Process.kill` to check for errors.
5188
5189 * 2000-07-18
5190 ** Fixed the following `Posix.ProcEnv` functions to check for errors:
5191 `setgid`, `setpgid`, `setsid`, `setuid`.
5192 ** Fixed `doc/examples/callcc.sml`.
5193
5194
5195 == Version 20000712
5196
5197 Here are the changes from the 1999-07-12 to the 20000712 version.
5198
5199 === Details
5200
5201 * 2000-06-10 - 2000-07-12
5202 ** Too many changes to count: bug fixes, new basis library modules, optimizer
5203 improvements.
5204
5205 * 2000-06-30
5206 ** Fixed bug in monomorphiser that caused programs with non-value carrying
5207 exception declarations in polymorphic functions to have a compile-time error
5208 because of a duplicate label. The problem was that the exception constructor
5209 wasn't duplicated.
5210
5211 * 2000-05-22 - 2000-06-10
5212 ** Finished the changes for the new CPS IL.
5213
5214 * 2000-01-01
5215 ** Fixed some errors in the basis library:
5216 *** `Real.copySign`
5217 *** `Posix.FileSys.fpathconf`
5218 *** `Posix.IO.{lseek, getlk, setlk, setlkw}`
5219 *** `Posix.ProcEnv.setpgid`
5220 *** `Posix.TTY.getattr`
5221 *** `System.FileSys.realPath`
5222
5223 * 1999-12-22
5224 ** Fixed bug in `src/closure-convert/abstract-value.fun` that caused a
5225 compiler failure whenever a program had a vector where the element type
5226 contained an `-&gt;`.
5227
5228 * 1999-12-10
5229 ** Changed dead code elimination in `core-ml/dead-code.fun` so that wildcard
5230 declarations (`val _ = ...`) in the basis are kept. Changed places in the
5231 basis library to take advantage of this.
5232 ** Added `setTopLevelHander` primitive so that the basis library code can
5233 define the toplevel handler.
5234 ** Changed `basis-library/misc/suffix.sml` to call `OS.Process.exit`. Took
5235 out `Halt` transfer from CPS, since the program never should reach it.
5236 ** Cleaned up `basis-library/system/{process.sml, unix.sml}` to use the new
5237 signal handling stuff.
5238
5239 * 1999-11-28 - 1999-12-20
5240 ** Added support for threads and cleaned up signal handling. This involved a
5241 number of changes:
5242 *** The stack is now allocated as just another kind of heap object.
5243 *** Limit checks are inserted at all loop headers, whether or not there is
5244 any allocation. This is to ensure that the signal handler always has a
5245 chance to get called.
5246 *** The register allocator puts more variables in stack slots. The new rule
5247 is that a variable goes in a stack slot if it is ever live across a nontail
5248 call, in a handler, or (this is the new part) across a limit check.
5249 *** Arguments are passed on the stack, with the convention determined by
5250 argument types.
5251 *** The "locals" array of pointers that was copied to/from for GC is now
5252 gone, because no registers (in particular no pointer valued registers) can
5253 be live at a limit check point.
5254
5255 * 1999-11-21
5256 ** Runtime system
5257 *** Fixed a bug introduced by the signal code (presumably on 1999-08-09)
5258 that caused a gc to *not* be performed when doing a save world. This caused
5259 the heaps created by save world to be the same size as the heap -- not the
5260 live data. This was quite bad.
5261 *** Cleaned up the `Makefile`. Add make depend.
5262 *** Added max gc pause to `gc-summary` info.
5263 *** Move heap translation variables that had been file statics into the
5264 `GC_state`.
5265 ** Made `structure Position` available at toplevel.
5266 ** Basis Library
5267 *** Added `MLton.loadWorld`
5268 ** Added `Primitive.usesCallcc`
5269 ** Added `Primitive.safe`
5270 ** Removed special size functions from `cps/save-world` -- they are no longer
5271 necessary since size doesn't do a gc.
5272 ** Fixed another (sigh) bug in `cps/simplify-types.fun` that could cause it to
5273 not terminate.
5274
5275 * 1999-11-16
5276 ** Cleaned up `backend/machine.fun` a bit so that it spits out macros for
5277 allocation of objects and bumping of frontier. Added macros `MLTON_object`
5278 and `MLTON_incFrontier` to `include/mlton-lib.h`.
5279 ** Fixed a bug in `backend/limit-check.fun` that caused loops to not be
5280 detected if they were only reached by a case branch. This could cause there
5281 to be loop that allocates with no limit check. Needless to say, this could
5282 cause a segfault if the loop ran for long enough.
5283
5284 * 1999-10-18
5285 ** Added basis library function `Array2.copy`.
5286
5287 * 1999-08-15
5288 ** Turned off globalization of ref cells (`closure-convert/globalize.fun`)
5289 because it interacts badly with serialization.
5290
5291 * 1999-08-13
5292 ** Fixed bug in `mlton-lib.h` in `MLTON_allocArrayNoPointers` that was
5293 triggered when `bytesPerElt == 0`. The problem was that it wasn't reserving
5294 space for the forwarding pointer. This could cause a segfault.
5295
5296 * 1999-08-08 and 1999-08-09
5297 ** Added support for signal handling.
5298
5299 * 1999-08-07
5300 ** Fixed bugs in `Array.tabulate` (and other `tabulate` variants) caused if
5301 the function argument used `callcc`.
5302
5303 * 1999-08-01
5304 ** Added serialization, which was mostly code in `src/runtime/gc.c`. +
5305 `GC_serialize` converts an object to a `Word8Vector.vector`. +
5306 `GC_deserialize` undoes the conversion. + (de)Serialization should work for
5307 all objects except for functions, because I haven't yet added the support in
5308 the flow analysis.
5309
5310 * 1999-07-31
5311 ** Cleaned up the GC. Changed headers, by stealing a bit from the number of
5312 non pointers and making it a mark bit (used in `GC_size`).
5313 ** Rewrote `GC_size` so that it runs in time proportional to the number of
5314 pointers in the object. It does a depth-first-search now, using toSpace to
5315 hold the stack.
5316
5317 * 1999-07-30
5318 ** Fixed bug in `SUBSTRING`. `getc` had the wrong type. This bug wasn't
5319 noticed because MLton doesn't do enough type checking.
5320 ** Fixed bug (segfault) caused when a GC immediately followed a throw.
5321
5322 * 1999-07-29
5323 ** Fixed bug in `Date.fmt` (`basis-library/system/date.sml`). It was not
5324 setting `Tm.buf`, and hence the time was always 0 unless there had been a
5325 previous call to `setTmBuf`.
5326
5327 * 1999-07-28
5328 ** Fixed bugs in `Posix.IO.FLock.{getlk,setlk,setlkw}`, which would cause
5329 compilation to fail because `FLock.toInt` was defined as the C `castInt`,
5330 which no longer exists. Instead, expand `FLock.toInt` to
5331 `MLTON_pointerToInt`, which was added to `include/mlton-lib.h`.
5332 ** Changed `Posix.Primitive.Flock` to `Posix.Primitive.FLock`.
5333 ** Added `MLTON_chown`, `MLTON_ftruncate` to `include/mlton-posix.h`. They
5334 were missing. This would cause compilation of any program using
5335 `Posix.FileSys.{chown,ftruncate}` to fail. Also made it so all of the
5336 primitives in `basis-library/posix/primitive.sml` use `MLTON_` versions of
5337 functions, even if a wrapper is unnecessary.
5338
5339 * 1999-07-25
5340 ** Added some other missing signature definitions to toplevel.
5341
5342 * 1999-07-24
5343 ** Added missing `OS_*` signature definitions to
5344 `basis-library/top-level/top-level.sml`.
5345
5346 * 1999-07-19
5347 ** Fixed bug in `basis-library/arrays-and-vectors/mono-array.sml`. Used `:&gt;`
5348 instead of `:` so that the monomorphic array types are abstract.
5349
5350
5351 == Version 19990712
5352
5353 Here are the changes from the 1999-03-19 version to the 1999-07-12 version.
5354
5355 === Details
5356
5357 * 1999-07-12
5358 ** Changed `src/backend/machine.fun` so that the 'pointer locals' array is
5359 only as large as neccessary in order to copy all pointer-valued locals, not as
5360 large as the number of pointer-valued locals.
5361
5362 * 1999-07-11
5363 ** Rewrote `src/backend/allocate-registers.fun` so that it does a better job
5364 of sharing "registers" (i.e. C local variables) and stack slots. This should
5365 cut down on the amount of copying that has to happen before and after a gc.
5366 It should also cut down on the size of stack slots.
5367
5368 * 1999-07-10
5369 ** Fixed a bug in `src/backend/parallel-move.fun` that should have been
5370 triggered on most any parallel move. I guess parallel moves almost never
5371 happened due to the old register allocation strategy -- but, with the new one
5372 (see note for 1999-07-12) parallel moves will be frequent.
5373
5374 * 1999-06-27
5375 ** Fixed `src/main.sml` so that when compiling `-p`, the `.c` file is compiled
5376 `-g` and the `.o` is linked `-p`.
5377 ** In `bakend/machine.fun`, added profiling comments before chunkswitches and
5378 put in an optimization to avoid printing repeated profiling comments. Also,
5379 profiling comments are only output when compiling `-p`.
5380
5381 * 1999-06-17
5382 ** Changed `-i` to `-inline`, `-f` to `-flatten`, `-np` to `-no-polyvariance`,
5383 `-u` to `-unsafe`.
5384 ** Added `-i`, `-I`, `-l`, `-L` flags for includes and libraries.
5385 ** Updated documentation for these options and for ffi.
5386
5387 * 1999-06-16
5388 ** Hardwired version number in `src/control/control.sml`. As it stood, the
5389 version number was computed when MLton was built after someone downloaded it,
5390 which was clearly wrong.
5391
5392 * 1999-06-16
5393 ** Fixed undefined variable `time` in `GC_done` in `src/runtime/gc.c`.
5394
5395 * 19990-06-08
5396 ** in `include/mlton-lib.h`:
5397 *** removed `#include &lt;huge_val.h&gt;`
5398 *** added `#include &lt;math.h&gt;`
5399 *** and deleted all of the function signatures I had copied from `math.h`
5400 ** Changed `Real.{minNormalPos, minPos, maxFinite}` so that they are computed
5401 in `real.sml` instead of appearing as constants in the C.
5402
5403 * 1999-06-07
5404 `IntInf.pow` added to basis library.
5405
5406 * 1999-06-04
5407 ** `bin/mlton` changed to use `.arch-n-opsys` if it exists.
5408
5409 * 1999-06-03
5410 ** `src/Makefile` changed to use `sml-cm` instead of `sml`
5411
5412 * 1999-05-10
5413 ** Patch to `src/atoms/small-int-inf.fun` to work around a bug in the SML/NJ
5414 implementation of bignums. This bug was causing some hex bignum constants to
5415 be lexed incorrectly.
5416
5417 * 1999-04-15
5418 ** Comments emitted in C code for profiling. The comments identify the CPS
5419 function responsible for each C statement.
5420
5421 * 1999-04-15
5422 ** `callcc` and `throw` added.
5423
5424 * 1999-04-15
5425 ** Bug in `src/cps/simplify-types` fixed. The bug caused nontermination
5426 whenever there was a circular datatype with a vector on the rhs.
5427 E.g. `datatype t = T of t vector`
5428
5429
5430 == Version 19990319
5431
5432 Here are the changes from the 1998-08-26 version to the 1999-03-19 version.
5433
5434 === Summary
5435
5436 * Compile time and code size have decreased.
5437 * Runtime performance of executables has improved.
5438 * Large programs can now be compiled.
5439 * MLton is self hosting.
5440 * The basis library is mostly complete and many bugs have been fixed.
5441 * The monomorphiser (`-m`) is no longer available.
5442 * The heap and stack are automatically resized.
5443 * There are now facilities for heap checkpointing (`MLton.saveWorld`) and object
5444 size computation (`MLton.size`).
5445 * MLton uses the GNU multiprecision (GnuMP) library to provide a fast
5446 implementation of `IntInf`.</screen>
5447 <simpara><?asciidoc-pagebreak?></simpara>
5448 </section>
5449 <section id="ChrisClearwater">
5450 <title>ChrisClearwater</title>
5451 <simpara></simpara>
5452 <simpara><?asciidoc-pagebreak?></simpara>
5453 </section>
5454 <section id="Chunkify">
5455 <title>Chunkify</title>
5456 <simpara><link linkend="Chunkify">Chunkify</link> is an analysis pass for the <link linkend="RSSA">RSSA</link>
5457 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="ToMachine">ToMachine</link>.</simpara>
5458 <section id="_description_3">
5459 <title>Description</title>
5460 <simpara>It partitions all the labels (function and block) in an <link linkend="RSSA">RSSA</link>
5461 program into disjoint sets, referred to as chunks.</simpara>
5462 </section>
5463 <section id="_implementation_4">
5464 <title>Implementation</title>
5465 <itemizedlist>
5466 <listitem>
5467 <simpara>
5468 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/chunkify.sig"><literal>chunkify.sig</literal></ulink>
5469 </simpara>
5470 </listitem>
5471 <listitem>
5472 <simpara>
5473 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/chunkify.fun"><literal>chunkify.fun</literal></ulink>
5474 </simpara>
5475 </listitem>
5476 </itemizedlist>
5477 </section>
5478 <section id="_details_and_notes_4">
5479 <title>Details and Notes</title>
5480 <simpara>Breaking large <link linkend="RSSA">RSSA</link> functions into chunks is necessary for
5481 reasonable compile times with the <link linkend="CCodegen">CCodegen</link> and the <link linkend="LLVMCodegen">LLVMCodegen</link>.</simpara>
5482 <simpara><?asciidoc-pagebreak?></simpara>
5483 </section>
5484 </section>
5485 <section id="CKitLibrary">
5486 <title>CKitLibrary</title>
5487 <simpara>The <ulink url="http://www.smlnj.org/doc/ckit">ckit Library</ulink> is a C front end
5488 written in SML that translates C source code (after preprocessing)
5489 into abstract syntax represented as a set of SML datatypes. The ckit
5490 Library is distributed with SML/NJ. Due to differences between SML/NJ
5491 and MLton, this library will not work out-of-the box with MLton.</simpara>
5492 <simpara>As of 20180119, MLton includes a port of the ckit Library synchronized
5493 with SML/NJ version 110.82.</simpara>
5494 <section id="_usage">
5495 <title>Usage</title>
5496 <itemizedlist>
5497 <listitem>
5498 <simpara>
5499 You can import the ckit Library into an MLB file with:
5500 </simpara>
5501 <informaltable
5502 frame="all"
5503 rowsep="1" colsep="1"
5504 >
5505 <tgroup cols="2">
5506 <colspec colname="col_1" colwidth="50*"/>
5507 <colspec colname="col_2" colwidth="50*"/>
5508 <thead>
5509 <row>
5510 <entry align="left" valign="top">MLB file</entry>
5511 <entry align="left" valign="top">Description</entry>
5512 </row>
5513 </thead>
5514 <tbody>
5515 <row>
5516 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/ckit-lib/ckit-lib.mlb</literal></simpara></entry>
5517 <entry align="left" valign="top"><simpara></simpara></entry>
5518 </row>
5519 </tbody>
5520 </tgroup>
5521 </informaltable>
5522 </listitem>
5523 <listitem>
5524 <simpara>
5525 If you are porting a project from SML/NJ&#8217;s <link linkend="CompilationManager">CompilationManager</link> to
5526 MLton&#8217;s <link linkend="MLBasis">ML Basis system</link> using <literal>cm2mlb</literal>, note that the
5527 following map is included by default:
5528 </simpara>
5529 <screen># ckit Library
5530 $ckit-lib.cm $(SML_LIB)/ckit-lib
5531 $ckit-lib.cm/ckit-lib.cm $(SML_LIB)/ckit-lib/ckit-lib.mlb</screen>
5532 <simpara>This will automatically convert a <literal>$/ckit-lib.cm</literal> import in an input
5533 <literal>.cm</literal> file into a <literal>$(SML_LIB)/ckit-lib/ckit-lib.mlb</literal> import in the
5534 output <literal>.mlb</literal> file.</simpara>
5535 </listitem>
5536 </itemizedlist>
5537 </section>
5538 <section id="_details">
5539 <title>Details</title>
5540 <simpara>The following changes were made to the ckit Library, in addition to
5541 deriving the <literal>.mlb</literal> file from the <literal>.cm</literal> file:</simpara>
5542 <itemizedlist>
5543 <listitem>
5544 <simpara>
5545 <literal>ast/pp/pp-ast-adornment-sig.sml</literal> (modified): Rewrote use of <literal>signature</literal> in <literal>local</literal>.
5546 </simpara>
5547 </listitem>
5548 <listitem>
5549 <simpara>
5550 <literal>ast/pp/pp-ast-ext-sig.sml</literal> (modified): Rewrote use of <literal>signature</literal> in <literal>local</literal>.
5551 </simpara>
5552 </listitem>
5553 <listitem>
5554 <simpara>
5555 <literal>ast/type-util-sig.sml</literal> (modified): Rewrote use of <literal>signature</literal> in <literal>local</literal>.
5556 </simpara>
5557 </listitem>
5558 <listitem>
5559 <simpara>
5560 <literal>parser/parse-tree-sig.sml</literal> (modified): Rewrote use of (sequential) <literal>withtype</literal> in signature.
5561 </simpara>
5562 </listitem>
5563 <listitem>
5564 <simpara>
5565 <literal>parser/parse-tree.sml</literal> (modified): Rewrote use of (sequential) <literal>withtype</literal>.
5566 </simpara>
5567 </listitem>
5568 </itemizedlist>
5569 </section>
5570 <section id="_patch">
5571 <title>Patch</title>
5572 <itemizedlist>
5573 <listitem>
5574 <simpara>
5575 <ulink url="https://github.com/MLton/mlton/blob/master/lib/ckit-lib/ckit.patch"><literal>ckit.patch</literal></ulink>
5576 </simpara>
5577 </listitem>
5578 </itemizedlist>
5579 <simpara><?asciidoc-pagebreak?></simpara>
5580 </section>
5581 </section>
5582 <section id="Closure">
5583 <title>Closure</title>
5584 <simpara>A closure is a data structure that is the run-time representation of a
5585 function.</simpara>
5586 <section id="_typical_implementation">
5587 <title>Typical Implementation</title>
5588 <simpara>In a typical implementation, a closure consists of a <emphasis>code pointer</emphasis>
5589 (indicating what the function does) and an <emphasis>environment</emphasis> containing
5590 the values of the free variables of the function. For example, in the
5591 expression</simpara>
5592 <programlisting language="sml" linenumbering="unnumbered">let
5593 val x = 5
5594 in
5595 fn y =&gt; x + y
5596 end</programlisting>
5597 <simpara>the closure for <literal>fn y =&gt; x + y</literal> contains a pointer to a piece of code
5598 that knows to take its argument and add the value of <literal>x</literal> to it, plus
5599 the environment recording the value of <literal>x</literal> as <literal>5</literal>.</simpara>
5600 <simpara>To call a function, the code pointer is extracted and jumped to,
5601 passing in some agreed upon location the environment and the argument.</simpara>
5602 </section>
5603 <section id="_mlton_8217_s_implementation">
5604 <title>MLton&#8217;s Implementation</title>
5605 <simpara>MLton does not implement closures traditionally. Instead, based on
5606 whole-program higher-order control-flow analysis, MLton represents a
5607 function as an element of a sum type, where the variant indicates
5608 which function it is and carries the free variables as arguments. See
5609 <link linkend="ClosureConvert">ClosureConvert</link> and <link linkend="References_CejtinEtAl00">CejtinEtAl00</link> for details.</simpara>
5610 <simpara><?asciidoc-pagebreak?></simpara>
5611 </section>
5612 </section>
5613 <section id="ClosureConvert">
5614 <title>ClosureConvert</title>
5615 <simpara><link linkend="ClosureConvert">ClosureConvert</link> is a translation pass from the <link linkend="SXML">SXML</link>
5616 <link linkend="IntermediateLanguage">IntermediateLanguage</link> to the <link linkend="SSA">SSA</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>.</simpara>
5617 <section id="_description_4">
5618 <title>Description</title>
5619 <simpara>It converts an <link linkend="SXML">SXML</link> program into an <link linkend="SSA">SSA</link> program.</simpara>
5620 <simpara><link linkend="Defunctionalization">Defunctionalization</link> is the technique used to eliminate
5621 <link linkend="Closure">Closure</link>s (see <link linkend="References_CejtinEtAl00">CejtinEtAl00</link>).</simpara>
5622 <simpara>Uses <link linkend="Globalize">Globalize</link> and <link linkend="LambdaFree">LambdaFree</link> analyses.</simpara>
5623 </section>
5624 <section id="_implementation_5">
5625 <title>Implementation</title>
5626 <itemizedlist>
5627 <listitem>
5628 <simpara>
5629 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/closure-convert.sig"><literal>closure-convert.sig</literal></ulink>
5630 </simpara>
5631 </listitem>
5632 <listitem>
5633 <simpara>
5634 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/closure-convert.fun"><literal>closure-convert.fun</literal></ulink>
5635 </simpara>
5636 </listitem>
5637 </itemizedlist>
5638 </section>
5639 <section id="_details_and_notes_5">
5640 <title>Details and Notes</title>
5641 <simpara></simpara>
5642 <simpara><?asciidoc-pagebreak?></simpara>
5643 </section>
5644 </section>
5645 <section id="CMinusMinus">
5646 <title>CMinusMinus</title>
5647 <simpara><ulink url="http://cminusminus.org">C--</ulink> is a portable assembly language intended
5648 to make it easy for compilers for different high-level languages to
5649 share the same backend. An experimental version of MLton has been
5650 made to generate C--.</simpara>
5651 <itemizedlist>
5652 <listitem>
5653 <simpara>
5654 <ulink url="http://www.mlton.org/pipermail/mlton/2005-March/026850.html">http://www.mlton.org/pipermail/mlton/2005-March/026850.html</ulink>
5655 </simpara>
5656 </listitem>
5657 </itemizedlist>
5658 <section id="_also_see">
5659 <title>Also see</title>
5660 <itemizedlist>
5661 <listitem>
5662 <simpara>
5663 <link linkend="LLVM">LLVM</link>
5664 </simpara>
5665 </listitem>
5666 </itemizedlist>
5667 <simpara><?asciidoc-pagebreak?></simpara>
5668 </section>
5669 </section>
5670 <section id="Codegen">
5671 <title>Codegen</title>
5672 <simpara><link linkend="Codegen">Codegen</link> is a translation pass from the <link linkend="Machine">Machine</link>
5673 <link linkend="IntermediateLanguage">IntermediateLanguage</link> to one or more compilation units that can be
5674 compiled to native object code by an external tool.</simpara>
5675 <section id="_implementation_6">
5676 <title>Implementation</title>
5677 <itemizedlist>
5678 <listitem>
5679 <simpara>
5680 <ulink url="https://github.com/MLton/mlton/tree/master/mlton/codegen"><literal>codegen</literal></ulink>
5681 </simpara>
5682 </listitem>
5683 </itemizedlist>
5684 </section>
5685 <section id="_details_and_notes_6">
5686 <title>Details and Notes</title>
5687 <simpara>The following <link linkend="Codegen">codegens</link> are implemented:</simpara>
5688 <itemizedlist>
5689 <listitem>
5690 <simpara>
5691 <link linkend="AMD64Codegen">AMD64Codegen</link>
5692 </simpara>
5693 </listitem>
5694 <listitem>
5695 <simpara>
5696 <link linkend="CCodegen">CCodegen</link>
5697 </simpara>
5698 </listitem>
5699 <listitem>
5700 <simpara>
5701 <link linkend="LLVMCodegen">LLVMCodegen</link>
5702 </simpara>
5703 </listitem>
5704 <listitem>
5705 <simpara>
5706 <link linkend="X86Codegen">X86Codegen</link>
5707 </simpara>
5708 </listitem>
5709 </itemizedlist>
5710 <simpara><?asciidoc-pagebreak?></simpara>
5711 </section>
5712 </section>
5713 <section id="CombineConversions">
5714 <title>CombineConversions</title>
5715 <simpara><link linkend="CombineConversions">CombineConversions</link> is an optimization pass for the <link linkend="SSA">SSA</link>
5716 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
5717 <section id="_description_5">
5718 <title>Description</title>
5719 <simpara>This pass looks for and simplifies nested calls to (signed)
5720 extension/truncation.</simpara>
5721 </section>
5722 <section id="_implementation_7">
5723 <title>Implementation</title>
5724 <itemizedlist>
5725 <listitem>
5726 <simpara>
5727 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/combine-conversions.fun"><literal>combine-conversions.fun</literal></ulink>
5728 </simpara>
5729 </listitem>
5730 </itemizedlist>
5731 </section>
5732 <section id="_details_and_notes_7">
5733 <title>Details and Notes</title>
5734 <simpara>It processes each block in dfs order (visiting definitions before uses):</simpara>
5735 <itemizedlist>
5736 <listitem>
5737 <simpara>
5738 If the statement is not a <literal>PrimApp</literal> with <literal>Word_extdToWord</literal>, skip it.
5739 </simpara>
5740 </listitem>
5741 <listitem>
5742 <simpara>
5743 After processing a conversion, it tags the <literal>Var</literal> for subsequent use.
5744 </simpara>
5745 </listitem>
5746 <listitem>
5747 <simpara>
5748 When inspecting a conversion, check if the <literal>Var</literal> operand is also the
5749 result of a conversion. If it is, try to combine the two operations.
5750 Repeatedly simplify until hitting either a non-conversion <literal>Var</literal> or a
5751 case where the conversion cannot be simplified.
5752 </simpara>
5753 </listitem>
5754 </itemizedlist>
5755 <simpara>The optimization rules are very simple:</simpara>
5756 <screen>x1 = ...
5757 x2 = Word_extdToWord (W1, W2, {signed=s1}) x1
5758 x3 = Word_extdToWord (W2, W3, {signed=s2}) x2</screen>
5759 <itemizedlist>
5760 <listitem>
5761 <simpara>
5762 If <literal>W1 = W2</literal>, then there is no conversions before <literal>x_1</literal>.
5763 </simpara>
5764 <simpara>This is guaranteed because <literal>W2 = W3</literal> will always trigger optimization.</simpara>
5765 </listitem>
5766 <listitem>
5767 <simpara>
5768 Case <literal>W1 &lt;= W3 &lt;= W2</literal>:
5769 </simpara>
5770 <screen>x3 = Word_extdToWord (W1, W3, {signed=s1}) x1</screen>
5771 </listitem>
5772 <listitem>
5773 <simpara>
5774 Case <literal>W1 &lt; W2 &lt; W3 AND ((NOT s1) OR s2)</literal>:
5775 </simpara>
5776 <screen>x3 = Word_extdToWord (W1, W3, {signed=s1}) x1</screen>
5777 </listitem>
5778 <listitem>
5779 <simpara>
5780 Case <literal>W1 = W2 &lt; W3</literal>:
5781 </simpara>
5782 <simpara>unoptimized, because there are no conversions past <literal>W1</literal> and <literal>x2 = x1</literal></simpara>
5783 </listitem>
5784 <listitem>
5785 <simpara>
5786 Case <literal>W3 &lt;= W2 &lt;= W1 OR W3 &lt;= W1 &lt;= W2</literal>:
5787 </simpara>
5788 <screen>x_3 = Word_extdToWord (W1, W3, {signed=_}) x1</screen>
5789 <simpara>because <literal>W3 &lt;= W1 &amp;&amp; W3 &lt;= W2</literal>, just clip <literal>x1</literal></simpara>
5790 </listitem>
5791 <listitem>
5792 <simpara>
5793 Case <literal>W2 &lt; W1 &lt;= W3 OR W2 &lt; W3 &lt;= W1</literal>:
5794 </simpara>
5795 <simpara>unoptimized, because <literal>W2 &lt; W1 &amp;&amp; W2 &lt; W3</literal>, has truncation effect</simpara>
5796 </listitem>
5797 <listitem>
5798 <simpara>
5799 Case <literal>W1 &lt; W2 &lt; W3 AND (s1 AND (NOT s2))</literal>:
5800 </simpara>
5801 <simpara>unoptimized, because each conversion affects the result separately</simpara>
5802 </listitem>
5803 </itemizedlist>
5804 <simpara><?asciidoc-pagebreak?></simpara>
5805 </section>
5806 </section>
5807 <section id="CommonArg">
5808 <title>CommonArg</title>
5809 <simpara><link linkend="CommonArg">CommonArg</link> is an optimization pass for the <link linkend="SSA">SSA</link>
5810 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
5811 <section id="_description_6">
5812 <title>Description</title>
5813 <simpara>It optimizes instances of <literal>Goto</literal> transfers that pass the same
5814 arguments to the same label; e.g.</simpara>
5815 <screen>L_1 ()
5816 ...
5817 z1 = ?
5818 ...
5819 L_3 (x, y, z1)
5820 L_2 ()
5821 ...
5822 z2 = ?
5823 ...
5824 L_3 (x, y, z2)
5825 L_3 (a, b, c)
5826 ...</screen>
5827 <simpara>This code can be simplified to:</simpara>
5828 <screen>L_1 ()
5829 ...
5830 z1 = ?
5831 ...
5832 L_3 (z1)
5833 L_2 ()
5834 ...
5835 z2 = ?
5836 ...
5837 L_3 (z2)
5838 L_3 (c)
5839 a = x
5840 b = y</screen>
5841 <simpara>which saves a number of resources: time of setting up the arguments
5842 for the jump to <literal>L_3</literal>, space (either stack or pseudo-registers) for
5843 the arguments of <literal>L_3</literal>, etc. It may also expose some other
5844 optimizations, if more information is known about <literal>x</literal> or <literal>y</literal>.</simpara>
5845 </section>
5846 <section id="_implementation_8">
5847 <title>Implementation</title>
5848 <itemizedlist>
5849 <listitem>
5850 <simpara>
5851 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/common-arg.fun"><literal>common-arg.fun</literal></ulink>
5852 </simpara>
5853 </listitem>
5854 </itemizedlist>
5855 </section>
5856 <section id="_details_and_notes_8">
5857 <title>Details and Notes</title>
5858 <simpara>Three analyses were originally proposed to drive the optimization
5859 transformation. Only the <emphasis>Dominator Analysis</emphasis> is currently
5860 implemented. (Implementations of the other analyses are available in
5861 the <link linkend="Sources">repository history</link>.)</simpara>
5862 <section id="_syntactic_analysis">
5863 <title>Syntactic Analysis</title>
5864 <simpara>The simplest analysis I could think of maintains</simpara>
5865 <screen>varInfo: Var.t -&gt; Var.t option list ref</screen>
5866 <simpara>initialized to <literal>[]</literal>.</simpara>
5867 <itemizedlist>
5868 <listitem>
5869 <simpara>
5870 For each variable <literal>v</literal> bound in a <literal>Statement.t</literal> or in the
5871 <literal>Function.t</literal> args, then <literal>List.push(varInfo v, NONE)</literal>.
5872 </simpara>
5873 </listitem>
5874 <listitem>
5875 <simpara>
5876 For each <literal>L (x1, ..., xn)</literal> transfer where <literal>(a1, ..., an)</literal> are the
5877 formals of <literal>L</literal>, then <literal>List.push(varInfo ai, SOME xi)</literal>.
5878 </simpara>
5879 </listitem>
5880 <listitem>
5881 <simpara>
5882 For each block argument a used in an unknown context (e.g.,
5883 arguments of blocks used as continuations, handlers, arith success,
5884 runtime return, or case switch labels), then
5885 <literal>List.push(varInfo a, NONE)</literal>.
5886 </simpara>
5887 </listitem>
5888 </itemizedlist>
5889 <simpara>Now, any block argument <literal>a</literal> such that <literal>varInfo a = xs</literal>, where all of
5890 the elements of <literal>xs</literal> are equal to <literal>SOME x</literal>, can be optimized by
5891 setting <literal>a = x</literal> at the beginning of the block and dropping the
5892 argument from <literal>Goto</literal> transfers.</simpara>
5893 <simpara>That takes care of the example above. We can clearly do slightly
5894 better, by changing the transformation criteria to the following: any
5895 block argument a such that <literal>varInfo a = xs</literal>, where all of the elements
5896 of <literal>xs</literal> are equal to <literal>SOME x</literal> <emphasis>or</emphasis> are equal to <literal>SOME a</literal>, can be
5897 optimized by setting <literal>a = x</literal> at the beginning of the block and
5898 dropping the argument from <literal>Goto</literal> transfers. This optimizes a case
5899 like:</simpara>
5900 <screen>L_1 ()
5901 ... z1 = ? ...
5902 L_3 (x, y, z1)
5903 L_2 ()
5904 ... z2 = ? ...
5905 L_3(x, y, z2)
5906 L_3 (a, b, c)
5907 ... w = ? ...
5908 case w of
5909 true =&gt; L_4 | false =&gt; L_5
5910 L_4 ()
5911 ...
5912 L_3 (a, b, w)
5913 L_5 ()
5914 ...</screen>
5915 <simpara>where a common argument is passed to a loop (and is invariant through
5916 the loop). Of course, the <link linkend="LoopInvariant">LoopInvariant</link> optimization pass would
5917 normally introduce a local loop and essentially reduce this to the
5918 first example, but I have seen this in practice, which suggests that
5919 some optimizations after <link linkend="LoopInvariant">LoopInvariant</link> do enough simplifications
5920 to introduce (new) loop invariant arguments.</simpara>
5921 </section>
5922 <section id="_fixpoint_analysis">
5923 <title>Fixpoint Analysis</title>
5924 <simpara>However, the above analysis and transformation doesn&#8217;t cover the cases
5925 where eliminating one common argument exposes the opportunity to
5926 eliminate other common arguments. For example:</simpara>
5927 <screen>L_1 ()
5928 ...
5929 L_3 (x)
5930 L_2 ()
5931 ...
5932 L_3 (x)
5933 L_3 (a)
5934 ...
5935 L_5 (a)
5936 L_4 ()
5937 ...
5938 L_5 (x)
5939 L_5 (b)
5940 ...</screen>
5941 <simpara>One pass of analysis and transformation would eliminate the argument
5942 to <literal>L_3</literal> and rewrite the <literal>L_5(a)</literal> transfer to <literal>L_5 (x)</literal>, thereby
5943 exposing the opportunity to eliminate the common argument to <literal>L_5</literal>.</simpara>
5944 <simpara>The interdependency the arguments to <literal>L_3</literal> and <literal>L_5</literal> suggest
5945 performing some sort of fixed-point analysis. This analysis is
5946 relatively simple; maintain</simpara>
5947 <screen>varInfo: Var.t -&gt; VarLattice.t</screen>
5948 <simpara>where</simpara>
5949 <screen>VarLattice.t ~=~ Bot | Point of Var.t | Top</screen>
5950 <simpara>(but is implemented by the <link linkend="FlatLattice">FlatLattice</link> functor with a <literal>lessThan</literal>
5951 list and <literal>value ref</literal> under the hood), initialized to <literal>Bot</literal>.</simpara>
5952 <itemizedlist>
5953 <listitem>
5954 <simpara>
5955 For each variable <literal>v</literal> bound in a <literal>Statement.t</literal> or in the
5956 <literal>Function.t</literal> args, then <literal>VarLattice.&lt;= (Point v, varInfo v)</literal>
5957 </simpara>
5958 </listitem>
5959 <listitem>
5960 <simpara>
5961 For each <literal>L (x1, ..., xn)</literal> transfer where <literal>(a1, ..., an)</literal> are the
5962 formals of <literal>L</literal>}, then <literal>VarLattice.&lt;= (varInfo xi, varInfo ai)</literal>.
5963 </simpara>
5964 </listitem>
5965 <listitem>
5966 <simpara>
5967 For each block argument a used in an unknown context, then
5968 <literal>VarLattice.&lt;= (Point a, varInfo a)</literal>.
5969 </simpara>
5970 </listitem>
5971 </itemizedlist>
5972 <simpara>Now, any block argument a such that <literal>varInfo a = Point x</literal> can be
5973 optimized by setting <literal>a = x</literal> at the beginning of the block and
5974 dropping the argument from <literal>Goto</literal> transfers.</simpara>
5975 <simpara>Now, with the last example, we introduce the ordering constraints:</simpara>
5976 <screen>varInfo x &lt;= varInfo a
5977 varInfo a &lt;= varInfo b
5978 varInfo x &lt;= varInfo b</screen>
5979 <simpara>Assuming that <literal>varInfo x = Point x</literal>, then we get <literal>varInfo a = Point x</literal>
5980 and <literal>varInfo b = Point x</literal>, and we optimize the example as desired.</simpara>
5981 <simpara>But, that is a rather weak assumption. It&#8217;s quite possible for
5982 <literal>varInfo x = Top</literal>. For example, consider:</simpara>
5983 <screen>G_1 ()
5984 ... n = 1 ...
5985 L_0 (n)
5986 G_2 ()
5987 ... m = 2 ...
5988 L_0 (m)
5989 L_0 (x)
5990 ...
5991 L_1 ()
5992 ...
5993 L_3 (x)
5994 L_2 ()
5995 ...
5996 L_3 (x)
5997 L_3 (a)
5998 ...
5999 L_5(a)
6000 L_4 ()
6001 ...
6002 L_5(x)
6003 L_5 (b)
6004 ...</screen>
6005 <simpara>Now <literal>varInfo x = varInfo a = varInfo b = Top</literal>. What went wrong here?
6006 When <literal>varInfo x</literal> went to <literal>Top</literal>, it got propagated all the way through
6007 to <literal>a</literal> and <literal>b</literal>, and prevented the elimination of any common arguments.
6008 What we&#8217;d like to do instead is when <literal>varInfo x</literal> goes to <literal>Top</literal>,
6009 propagate on <literal>Point x</literal>&#8201;&#8212;&#8201;we have no hope of eliminating <literal>x</literal>, but if
6010 we hold <literal>x</literal> constant, then we have a chance of eliminating arguments
6011 for which <literal>x</literal> is passed as an actual.</simpara>
6012 </section>
6013 <section id="_dominator_analysis">
6014 <title>Dominator Analysis</title>
6015 <simpara>Does anyone see where this is going yet? Pausing for a little
6016 thought, <link linkend="MatthewFluet">MatthewFluet</link> realized that he had once before tried
6017 proposing this kind of "fix" to a fixed-point analysis&#8201;&#8212;&#8201;when we were
6018 first investigating the <link linkend="Contify">Contify</link> optimization in light of John
6019 Reppy&#8217;s CWS paper. Of course, that "fix" failed because it defined a
6020 non-monotonic function and one couldn&#8217;t take the fixed point. But,
6021 <link linkend="StephenWeeks">StephenWeeks</link> suggested a dominator based approach, and we were
6022 able to show that, indeed, the dominator analysis subsumed both the
6023 previous call based analysis and the cont based analysis. And, a
6024 moment&#8217;s reflection reveals further parallels: when
6025 <literal>varInfo: Var.t -&gt; Var.t option list ref</literal>, we have something analogous
6026 to the call analysis, and when <literal>varInfo: Var.t -&gt; VarLattice.t</literal>, we
6027 have something analogous to the cont analysis. Maybe there is
6028 something analogous to the dominator approach (and therefore superior
6029 to the previous analyses).</simpara>
6030 <simpara>And this turns out to be the case. Construct the graph <literal>G</literal> as follows:</simpara>
6031 <screen>nodes(G) = {Root} U Var.t
6032 edges(G) = {Root -&gt; v | v bound in a Statement.t or
6033 in the Function.t args} U
6034 {xi -&gt; ai | L(x1, ..., xn) transfer where (a1, ..., an)
6035 are the formals of L} U
6036 {Root -&gt; a | a is a block argument used in an unknown context}</screen>
6037 <simpara>Let <literal>idom(x)</literal> be the immediate dominator of <literal>x</literal> in <literal>G</literal> with root
6038 <literal>Root</literal>. Now, any block argument a such that <literal>idom(a) = x &lt;&gt; Root</literal> can
6039 be optimized by setting <literal>a = x</literal> at the beginning of the block and
6040 dropping the argument from <literal>Goto</literal> transfers.</simpara>
6041 <simpara>Furthermore, experimental evidence suggests (and we are confident that
6042 a formal presentation could prove) that the dominator analysis
6043 subsumes the "syntactic" and "fixpoint" based analyses in this context
6044 as well and that the dominator analysis gets "everything" in one go.</simpara>
6045 </section>
6046 <section id="_final_thoughts">
6047 <title>Final Thoughts</title>
6048 <simpara>I must admit, I was rather surprised at this progression and final
6049 result. At the outset, I never would have thought of a connection
6050 between <link linkend="Contify">Contify</link> and <link linkend="CommonArg">CommonArg</link> optimizations. They would seem
6051 to be two completely different optimizations. Although, this may not
6052 really be the case. As one of the reviewers of the ICFP paper said:</simpara>
6053 <blockquote>
6054 <simpara>I understand that such a form of CPS might be convenient in some
6055 cases, but when we&#8217;re talking about analyzing code to detect that some
6056 continuation is constant, I think it makes a lot more sense to make
6057 all the continuation arguments completely explicit.</simpara>
6058 <simpara>I believe that making all the continuation arguments explicit will
6059 show that the optimization can be generalized to eliminating constant
6060 arguments, whether continuations or not.</simpara>
6061 </blockquote>
6062 <simpara>What I think the common argument optimization shows is that the
6063 dominator analysis does slightly better than the reviewer puts it: we
6064 find more than just constant continuations, we find common
6065 continuations. And I think this is further justified by the fact that
6066 I have observed common argument eliminate some <literal>env_X</literal> arguments which
6067 would appear to correspond to determining that while the closure being
6068 executed isn&#8217;t constant it is at least the same as the closure being
6069 passed elsewhere.</simpara>
6070 <simpara>At first, I was curious whether or not we had missed a bigger picture
6071 with the dominator analysis. When we wrote the contification paper, I
6072 assumed that the dominator analysis was a specialized solution to a
6073 specialized problem; we never suggested that it was a technique suited
6074 to a larger class of analyses. After initially finding a connection
6075 between <link linkend="Contify">Contify</link> and <link linkend="CommonArg">CommonArg</link> (and thinking that the only
6076 connection was the technique), I wondered if the dominator technique
6077 really was applicable to a larger class of analyses. That is still a
6078 question, but after writing up the above, I&#8217;m suspecting that the
6079 "real story" is that the dominator analysis is a solution to the
6080 common argument optimization, and that the <link linkend="Contify">Contify</link> optimization is
6081 specializing <link linkend="CommonArg">CommonArg</link> to the case of continuation arguments (with
6082 a different transformation at the end). (Note, a whole-program,
6083 inter-procedural common argument analysis doesn&#8217;t really make sense
6084 (in our <link linkend="SSA">SSA</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>), because the only way of
6085 passing values between functions is as arguments. (Unless of course
6086 in the case that the common argument is also a constant argument, in
6087 which case <link linkend="ConstantPropagation">ConstantPropagation</link> could lift it to a global.) The
6088 inter-procedural <link linkend="Contify">Contify</link> optimization works out because there we
6089 move the function to the argument.)</simpara>
6090 <simpara>Anyways, it&#8217;s still unclear to me whether or not the dominator based
6091 approach solves other kinds of problems.</simpara>
6092 </section>
6093 <section id="_phase_ordering">
6094 <title>Phase Ordering</title>
6095 <simpara>On the downside, the optimization doesn&#8217;t have a huge impact on
6096 runtime, although it does predictably saved some code size. I stuck
6097 it in the optimization sequence after <link linkend="Flatten">Flatten</link> and (the third round
6098 of) <link linkend="LocalFlatten">LocalFlatten</link>, since it seems to me that we could have cases
6099 where some components of a tuple used as an argument are common, but
6100 the whole tuple isn&#8217;t. I think it makes sense to add it after
6101 <link linkend="IntroduceLoops">IntroduceLoops</link> and <link linkend="LoopInvariant">LoopInvariant</link> (even though <link linkend="CommonArg">CommonArg</link>
6102 get some things that <link linkend="LoopInvariant">LoopInvariant</link> gets, it doesn&#8217;t get all of
6103 them). I also think that it makes sense to add it before
6104 <link linkend="CommonSubexp">CommonSubexp</link>, since identifying variables could expose more common
6105 subexpressions. I would think a similar thought applies to
6106 <link linkend="RedundantTests">RedundantTests</link>.</simpara>
6107 <simpara><?asciidoc-pagebreak?></simpara>
6108 </section>
6109 </section>
6110 </section>
6111 <section id="CommonBlock">
6112 <title>CommonBlock</title>
6113 <simpara><link linkend="CommonBlock">CommonBlock</link> is an optimization pass for the <link linkend="SSA">SSA</link>
6114 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
6115 <section id="_description_7">
6116 <title>Description</title>
6117 <simpara>It eliminates equivalent blocks in a <link linkend="SSA">SSA</link> function. The
6118 equivalence criteria requires blocks to have no arguments or
6119 statements and transfer via <literal>Raise</literal>, <literal>Return</literal>, or <literal>Goto</literal> of a single
6120 global variable.</simpara>
6121 </section>
6122 <section id="_implementation_9">
6123 <title>Implementation</title>
6124 <itemizedlist>
6125 <listitem>
6126 <simpara>
6127 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/common-block.fun"><literal>common-block.fun</literal></ulink>
6128 </simpara>
6129 </listitem>
6130 </itemizedlist>
6131 </section>
6132 <section id="_details_and_notes_9">
6133 <title>Details and Notes</title>
6134 <itemizedlist>
6135 <listitem>
6136 <simpara>
6137 Rewrites
6138 </simpara>
6139 <screen>L_X ()
6140 raise (global_Y)</screen>
6141 <simpara>to</simpara>
6142 <screen>L_X ()
6143 L_Y' ()</screen>
6144 <simpara>and adds</simpara>
6145 <screen>L_Y' ()
6146 raise (global_Y)</screen>
6147 <simpara>to the <link linkend="SSA">SSA</link> function.</simpara>
6148 </listitem>
6149 <listitem>
6150 <simpara>
6151 Rewrites
6152 </simpara>
6153 <screen>L_X ()
6154 return (global_Y)</screen>
6155 <simpara>to</simpara>
6156 <screen>L_X ()
6157 L_Y' ()</screen>
6158 <simpara>and adds</simpara>
6159 <screen>L_Y' ()
6160 return (global_Y)</screen>
6161 <simpara>to the <link linkend="SSA">SSA</link> function.</simpara>
6162 </listitem>
6163 <listitem>
6164 <simpara>
6165 Rewrites
6166 </simpara>
6167 <screen>L_X ()
6168 L_Z (global_Y)</screen>
6169 <simpara>to</simpara>
6170 <screen>L_X ()
6171 L_Y' ()</screen>
6172 <simpara>and adds</simpara>
6173 <screen>L_Y' ()
6174 L_Z (global_Y)</screen>
6175 <simpara>to the <link linkend="SSA">SSA</link> function.</simpara>
6176 </listitem>
6177 </itemizedlist>
6178 <simpara>The <link linkend="Shrink">Shrink</link> pass rewrites all uses of <literal>L_X</literal> to <literal>L_Y'</literal> and drops <literal>L_X</literal>.</simpara>
6179 <simpara>For example, all uncaught <literal>Overflow</literal> exceptions in a <link linkend="SSA">SSA</link> function
6180 share the same raising block.</simpara>
6181 <simpara><?asciidoc-pagebreak?></simpara>
6182 </section>
6183 </section>
6184 <section id="CommonSubexp">
6185 <title>CommonSubexp</title>
6186 <simpara><link linkend="CommonSubexp">CommonSubexp</link> is an optimization pass for the <link linkend="SSA">SSA</link>
6187 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
6188 <section id="_description_8">
6189 <title>Description</title>
6190 <simpara>It eliminates instances of common subexpressions.</simpara>
6191 </section>
6192 <section id="_implementation_10">
6193 <title>Implementation</title>
6194 <itemizedlist>
6195 <listitem>
6196 <simpara>
6197 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/common-subexp.fun"><literal>common-subexp.fun</literal></ulink>
6198 </simpara>
6199 </listitem>
6200 </itemizedlist>
6201 </section>
6202 <section id="_details_and_notes_10">
6203 <title>Details and Notes</title>
6204 <simpara>In addition to getting the usual sorts of things like</simpara>
6205 <itemizedlist>
6206 <listitem>
6207 <simpara>
6208 </simpara>
6209 <screen>(w + 0wx1) + (w + 0wx1)</screen>
6210 <simpara>rewritten to</simpara>
6211 <screen>let val w' = w + 0wx1 in w' + w' end</screen>
6212 </listitem>
6213 </itemizedlist>
6214 <simpara>it also gets things like</simpara>
6215 <itemizedlist>
6216 <listitem>
6217 <simpara>
6218 </simpara>
6219 <screen>val a = Array_uninit n
6220 val b = Array_length a</screen>
6221 <simpara>rewritten to</simpara>
6222 <screen>val a = Array_uninit n
6223 val b = n</screen>
6224 </listitem>
6225 </itemizedlist>
6226 <simpara><literal>Arith</literal> transfers are handled specially. The <emphasis>result</emphasis> of an <literal>Arith</literal>
6227 transfer can be used in <emphasis>common</emphasis> <literal>Arith</literal> transfers that it dominates:</simpara>
6228 <itemizedlist>
6229 <listitem>
6230 <simpara>
6231 </simpara>
6232 <screen>val l = (n + m) + (n + m)
6233
6234 val k = (l + n) + ((l + m) handle Overflow =&gt; ((l + m)
6235 handle Overflow =&gt; l + n))</screen>
6236 <simpara>is rewritten so that <literal>(n + m)</literal> is computed exactly once, as are
6237 <literal>(l + n)</literal> and <literal>(l + m)</literal>.</simpara>
6238 </listitem>
6239 </itemizedlist>
6240 <simpara><?asciidoc-pagebreak?></simpara>
6241 </section>
6242 </section>
6243 <section id="CompilationManager">
6244 <title>CompilationManager</title>
6245 <simpara>The <ulink url="http://www.smlnj.org/doc/CM/index.html">Compilation Manager</ulink> (CM) is SML/NJ&#8217;s mechanism for supporting programming-in-the-very-large.</simpara>
6246 <section id="_porting_sml_nj_cm_files_to_mlton">
6247 <title>Porting SML/NJ CM files to MLton</title>
6248 <simpara>To help in porting CM files to MLton, the MLton source distribution
6249 includes the sources for a utility, <literal>cm2mlb</literal>, that will print an
6250 <link linkend="MLBasis">ML Basis</link> file with essentially the same semantics as the
6251 CM file&#8201;&#8212;&#8201;handling the full syntax of CM supported by your installed
6252 SML/NJ version and correctly handling export filters. When <literal>cm2mlb</literal>
6253 encounters a <literal>.cm</literal> import, it attempts to convert it to a
6254 corresponding <literal>.mlb</literal> import. CM anchored paths are translated to
6255 paths according to a default configuration file
6256 (<ulink url="https://github.com/MLton/mlton/blob/master/util/cm2mlb/cm2mlb-map"><literal>cm2mlb-map</literal></ulink>). For example,
6257 the default configuration includes</simpara>
6258 <screen># Standard ML Basis Library
6259 $SMLNJ-BASIS $(SML_LIB)/basis
6260 $basis.cm $(SML_LIB)/basis
6261 $basis.cm/basis.cm $(SML_LIB)/basis/basis.mlb</screen>
6262 <simpara>to ensure that a <literal>$/basis.cm</literal> import is translated to a
6263 <literal>$(SML_LIB)/basis/basis.mlb</literal> import. See <literal>util/cm2mlb</literal> for details.
6264 Building <literal>cm2mlb</literal> requires that you have already installed a recent
6265 version of SML/NJ.</simpara>
6266 <simpara><?asciidoc-pagebreak?></simpara>
6267 </section>
6268 </section>
6269 <section id="CompilerOverview">
6270 <title>CompilerOverview</title>
6271 <simpara>The following table shows the overall structure of the compiler.
6272 <link linkend="IntermediateLanguage">IntermediateLanguage</link>s are shown in the center column. The names
6273 of compiler passes are listed in the left and right columns.</simpara>
6274 <informaltable
6275 frame="all"
6276 rowsep="1" colsep="1"
6277 >
6278 <tgroup cols="3">
6279 <colspec colname="col_1" colwidth="33*"/>
6280 <colspec colname="col_2" colwidth="33*"/>
6281 <colspec colname="col_3" colwidth="33*"/>
6282 <tbody>
6283 <row>
6284 <entry align="center" valign="top" namest="col_1" nameend="col_3"><simpara><emphasis role="strong">Compiler Overview</emphasis></simpara></entry>
6285 </row>
6286 <row>
6287 <entry align="center" valign="top"><simpara><emphasis>Translation Passes</emphasis></simpara></entry>
6288 <entry align="center" valign="top"><simpara><emphasis><link linkend="IntermediateLanguage">IntermediateLanguage</link></emphasis></simpara></entry>
6289 <entry align="center" valign="top"><simpara><emphasis>Optimization Passes</emphasis></simpara></entry>
6290 </row>
6291 <row>
6292 <entry align="center" valign="top"><simpara></simpara></entry>
6293 <entry align="center" valign="top"><simpara>Source</simpara></entry>
6294 <entry align="center" valign="top"><simpara></simpara></entry>
6295 </row>
6296 <row>
6297 <entry align="center" valign="top"><simpara><link linkend="FrontEnd">FrontEnd</link></simpara></entry>
6298 <entry align="center" valign="top"><simpara></simpara></entry>
6299 <entry align="center" valign="top"><simpara></simpara></entry>
6300 </row>
6301 <row>
6302 <entry align="center" valign="top"><simpara></simpara></entry>
6303 <entry align="center" valign="top"><simpara><link linkend="AST">AST</link></simpara></entry>
6304 <entry align="center" valign="top"><simpara></simpara></entry>
6305 </row>
6306 <row>
6307 <entry align="center" valign="top"><simpara><link linkend="Elaborate">Elaborate</link></simpara></entry>
6308 <entry align="center" valign="top"><simpara></simpara></entry>
6309 <entry align="center" valign="top"><simpara></simpara></entry>
6310 </row>
6311 <row>
6312 <entry align="center" valign="top"><simpara></simpara></entry>
6313 <entry align="center" valign="top"><simpara><link linkend="CoreML">CoreML</link></simpara></entry>
6314 <entry align="center" valign="top"><simpara><link linkend="CoreMLSimplify">CoreMLSimplify</link></simpara></entry>
6315 </row>
6316 <row>
6317 <entry align="center" valign="top"><simpara><link linkend="Defunctorize">Defunctorize</link></simpara></entry>
6318 <entry align="center" valign="top"><simpara></simpara></entry>
6319 <entry align="center" valign="top"><simpara></simpara></entry>
6320 </row>
6321 <row>
6322 <entry align="center" valign="top"><simpara></simpara></entry>
6323 <entry align="center" valign="top"><simpara><link linkend="XML">XML</link></simpara></entry>
6324 <entry align="center" valign="top"><simpara><link linkend="XMLSimplify">XMLSimplify</link></simpara></entry>
6325 </row>
6326 <row>
6327 <entry align="center" valign="top"><simpara><link linkend="Monomorphise">Monomorphise</link></simpara></entry>
6328 <entry align="center" valign="top"><simpara></simpara></entry>
6329 <entry align="center" valign="top"><simpara></simpara></entry>
6330 </row>
6331 <row>
6332 <entry align="center" valign="top"><simpara></simpara></entry>
6333 <entry align="center" valign="top"><simpara><link linkend="SXML">SXML</link></simpara></entry>
6334 <entry align="center" valign="top"><simpara><link linkend="SXMLSimplify">SXMLSimplify</link></simpara></entry>
6335 </row>
6336 <row>
6337 <entry align="center" valign="top"><simpara><link linkend="ClosureConvert">ClosureConvert</link></simpara></entry>
6338 <entry align="center" valign="top"><simpara></simpara></entry>
6339 <entry align="center" valign="top"><simpara></simpara></entry>
6340 </row>
6341 <row>
6342 <entry align="center" valign="top"><simpara></simpara></entry>
6343 <entry align="center" valign="top"><simpara><link linkend="SSA">SSA</link></simpara></entry>
6344 <entry align="center" valign="top"><simpara><link linkend="SSASimplify">SSASimplify</link></simpara></entry>
6345 </row>
6346 <row>
6347 <entry align="center" valign="top"><simpara><link linkend="ToSSA2">ToSSA2</link></simpara></entry>
6348 <entry align="center" valign="top"><simpara></simpara></entry>
6349 <entry align="center" valign="top"><simpara></simpara></entry>
6350 </row>
6351 <row>
6352 <entry align="center" valign="top"><simpara></simpara></entry>
6353 <entry align="center" valign="top"><simpara><link linkend="SSA2">SSA2</link></simpara></entry>
6354 <entry align="center" valign="top"><simpara><link linkend="SSA2Simplify">SSA2Simplify</link></simpara></entry>
6355 </row>
6356 <row>
6357 <entry align="center" valign="top"><simpara><link linkend="ToRSSA">ToRSSA</link></simpara></entry>
6358 <entry align="center" valign="top"><simpara></simpara></entry>
6359 <entry align="center" valign="top"><simpara></simpara></entry>
6360 </row>
6361 <row>
6362 <entry align="center" valign="top"><simpara></simpara></entry>
6363 <entry align="center" valign="top"><simpara><link linkend="RSSA">RSSA</link></simpara></entry>
6364 <entry align="center" valign="top"><simpara><link linkend="RSSASimplify">RSSASimplify</link></simpara></entry>
6365 </row>
6366 <row>
6367 <entry align="center" valign="top"><simpara><link linkend="ToMachine">ToMachine</link></simpara></entry>
6368 <entry align="center" valign="top"><simpara></simpara></entry>
6369 <entry align="center" valign="top"><simpara></simpara></entry>
6370 </row>
6371 <row>
6372 <entry align="center" valign="top"><simpara></simpara></entry>
6373 <entry align="center" valign="top"><simpara><link linkend="Machine">Machine</link></simpara></entry>
6374 <entry align="center" valign="top"><simpara></simpara></entry>
6375 </row>
6376 <row>
6377 <entry align="center" valign="top"><simpara><link linkend="Codegen">Codegen</link></simpara></entry>
6378 <entry align="center" valign="top"><simpara></simpara></entry>
6379 <entry align="center" valign="top"><simpara></simpara></entry>
6380 </row>
6381 </tbody>
6382 </tgroup>
6383 </informaltable>
6384 <simpara>The <literal>Compile</literal> functor (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/main/compile.sig"><literal>compile.sig</literal></ulink>,
6385 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/main/compile.fun"><literal>compile.fun</literal></ulink>), controls the
6386 high-level view of the compiler passes, from <link linkend="FrontEnd">FrontEnd</link> to code
6387 generation.</simpara>
6388 <simpara><?asciidoc-pagebreak?></simpara>
6389 </section>
6390 <section id="CompilerPassTemplate">
6391 <title>CompilerPassTemplate</title>
6392 <simpara>An analysis pass for the <link linkend="ZZZ">ZZZ</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="ZZZOtherPass">ZZZOtherPass</link>.
6393 An implementation pass for the <link linkend="ZZZ">ZZZ</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="ZZZSimplify">ZZZSimplify</link>.
6394 An optimization pass for the <link linkend="ZZZ">ZZZ</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="ZZZSimplify">ZZZSimplify</link>.
6395 A rewrite pass for the <link linkend="ZZZ">ZZZ</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="ZZZOtherPass">ZZZOtherPass</link>.
6396 A translation pass from the <link linkend="ZZA">ZZA</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> to the <link linkend="ZZB">ZZB</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>.</simpara>
6397 <section id="_description_9">
6398 <title>Description</title>
6399 <simpara>A short description of the pass.</simpara>
6400 </section>
6401 <section id="_implementation_11">
6402 <title>Implementation</title>
6403 <itemizedlist>
6404 <listitem>
6405 <simpara>
6406 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ZZZ.fun"><literal>ZZZ.fun</literal></ulink>
6407 </simpara>
6408 </listitem>
6409 </itemizedlist>
6410 </section>
6411 <section id="_details_and_notes_11">
6412 <title>Details and Notes</title>
6413 <simpara>Relevant details and notes.</simpara>
6414 <simpara><?asciidoc-pagebreak?></simpara>
6415 </section>
6416 </section>
6417 <section id="CompileTimeOptions">
6418 <title>CompileTimeOptions</title>
6419 <simpara>MLton&#8217;s compile-time options control the name of the output file, the
6420 verbosity of compile-time messages, and whether or not certain
6421 optimizations are performed. They also can specify which intermediate
6422 files are saved and can stop the compilation process early, at some
6423 intermediate pass, in which case compilation can be resumed by passing
6424 the generated files to MLton. MLton uses the input file suffix to
6425 determine the type of input program. The possibilities are <literal>.c</literal>,
6426 <literal>.mlb</literal>, <literal>.o</literal>, <literal>.s</literal>, and <literal>.sml</literal>.</simpara>
6427 <simpara>With no arguments, MLton prints the version number and exits. For a
6428 usage message, run MLton with an invalid switch, e.g. <literal>mlton -z</literal>. In
6429 the explanation below and in the usage message, for flags that take a
6430 number of choices (e.g. <literal>{true|false}</literal>), the first value listed is the
6431 default.</simpara>
6432 <section id="_options">
6433 <title>Options</title>
6434 <itemizedlist>
6435 <listitem>
6436 <simpara>
6437 <literal>-align <emphasis>n</emphasis></literal>
6438 </simpara>
6439 <simpara>Aligns object in memory by the specified alignment (<literal>4</literal> or <literal>8</literal>).
6440 The default varies depending on architecture.</simpara>
6441 </listitem>
6442 <listitem>
6443 <simpara>
6444 <literal>-as-opt <emphasis>option</emphasis></literal>
6445 </simpara>
6446 <simpara>Pass <emphasis>option</emphasis> to <literal>gcc</literal> when compiling assembler code. If you wish to
6447 pass an option to the assembler, you must use <literal>gcc</literal>'s <literal>-Wa,</literal> syntax.</simpara>
6448 </listitem>
6449 <listitem>
6450 <simpara>
6451 <literal>-cc-opt <emphasis>option</emphasis></literal>
6452 </simpara>
6453 <simpara>Pass <emphasis>option</emphasis> to <literal>gcc</literal> when compiling C code.</simpara>
6454 </listitem>
6455 <listitem>
6456 <simpara>
6457 <literal>-codegen {native|amd64|c|llvm|x86}</literal>
6458 </simpara>
6459 <simpara>Generate native object code via amd64 assembly, C code, LLVM code, or
6460 x86 code or C code. With <literal>-codegen native</literal> (<literal>-codegen amd64</literal> or
6461 <literal>-codegen x86</literal>), MLton typically compiles more quickly and generates
6462 better code.</simpara>
6463 </listitem>
6464 <listitem>
6465 <simpara>
6466 <literal>-const <emphasis>name</emphasis> <emphasis>value</emphasis></literal>
6467 </simpara>
6468 <simpara>Set the value of a compile-time constant. Here is a list of
6469 available constants, their default values, and what they control.</simpara>
6470 <itemizedlist>
6471 <listitem>
6472 <simpara>
6473 <literal>Exn.keepHistory {false|true}</literal>
6474 </simpara>
6475 <simpara>Enable <literal>MLton.Exn.history</literal>. See <link linkend="MLtonExn">MLtonExn</link> for details. There is a
6476 performance cost to setting this to <literal>true</literal>, both in memory usage of
6477 exceptions and in run time, because of additional work that must be
6478 performed at each exception construction, raise, and handle.</simpara>
6479 </listitem>
6480 </itemizedlist>
6481 </listitem>
6482 <listitem>
6483 <simpara>
6484 <literal>-default-ann <emphasis>ann</emphasis></literal>
6485 </simpara>
6486 <simpara>Specify default <link linkend="MLBasisAnnotations">ML Basis annotations</link>. For
6487 example, <literal>-default-ann 'warnUnused true'</literal> causes unused variable
6488 warnings to be enabled by default. A default is overridden by the
6489 corresponding annotation in an ML Basis file.</simpara>
6490 </listitem>
6491 <listitem>
6492 <simpara>
6493 <literal>-default-type <emphasis>type</emphasis></literal>
6494 </simpara>
6495 <simpara>Specify the default binding for a primitive type. For example,
6496 <literal>-default-type word64</literal> causes the top-level type <literal>word</literal> and the
6497 top-level structure <literal>Word</literal> in the <link linkend="BasisLibrary">Basis Library</link> to be
6498 equal to <literal>Word64.word</literal> and <literal>Word64:WORD</literal>, respectively. Similarly,
6499 <literal>-default-type intinf</literal> causes the top-level type <literal>int</literal> and the
6500 top-level structure <literal>Int</literal> in the <link linkend="BasisLibrary">Basis Library</link> to be
6501 equal to <literal>IntInf.int</literal> and <literal>IntInf:INTEGER</literal>, respectively.</simpara>
6502 </listitem>
6503 <listitem>
6504 <simpara>
6505 <literal>-disable-ann <emphasis>ann</emphasis></literal>
6506 </simpara>
6507 <simpara>Ignore the specified <link linkend="MLBasisAnnotations">ML Basis annotation</link> in
6508 every ML Basis file. For example, to see <emphasis>all</emphasis> match and unused
6509 warnings, compile with</simpara>
6510 <screen>-default-ann 'warnUnused true'
6511 -disable-ann forceUsed
6512 -disable-ann nonexhaustiveMatch
6513 -disable-ann redundantMatch
6514 -disable-ann warnUnused</screen>
6515 </listitem>
6516 <listitem>
6517 <simpara>
6518 <literal>-export-header <emphasis>file</emphasis></literal>
6519 </simpara>
6520 <simpara>Write C prototypes to <emphasis>file</emphasis> for all of the functions in the program
6521 <link linkend="CallingFromCToSML">exported from SML to C</link>.</simpara>
6522 </listitem>
6523 <listitem>
6524 <simpara>
6525 <literal>-ieee-fp {false|true}</literal>
6526 </simpara>
6527 <simpara>Cause the x86 native code generator to be pedantic about following the
6528 IEEE floating point standard. By default, it is not, because of the
6529 performance cost. This only has an effect with <literal>-codegen x86</literal>.</simpara>
6530 </listitem>
6531 <listitem>
6532 <simpara>
6533 <literal>-inline <emphasis>n</emphasis></literal>
6534 </simpara>
6535 <simpara>Set the inlining threshold used in the optimizer. The threshold is an
6536 approximate measure of code size of a procedure. The default is
6537 <literal>320</literal>.</simpara>
6538 </listitem>
6539 <listitem>
6540 <simpara>
6541 <literal>-keep {g|o}</literal>
6542 </simpara>
6543 <simpara>Save intermediate files. If no <literal>-keep</literal> argument is given, then only
6544 the output file is saved.</simpara>
6545 <informaltable
6546 frame="all"
6547 rowsep="1" colsep="1"
6548 >
6549 <tgroup cols="2">
6550 <colspec colname="col_1" colwidth="25*"/>
6551 <colspec colname="col_2" colwidth="75*"/>
6552 <tbody>
6553 <row>
6554 <entry align="center" valign="top"><simpara><literal>g</literal></simpara></entry>
6555 <entry align="left" valign="top"><simpara>generated <literal>.c</literal> and <literal>.s</literal> files passed to <literal>gcc</literal> and generated <literal>.ll</literal> files passed to <literal>llvm-as</literal></simpara></entry>
6556 </row>
6557 <row>
6558 <entry align="center" valign="top"><simpara><literal>o</literal></simpara></entry>
6559 <entry align="left" valign="top"><simpara>object (<literal>.o</literal>) files</simpara></entry>
6560 </row>
6561 </tbody>
6562 </tgroup>
6563 </informaltable>
6564 </listitem>
6565 <listitem>
6566 <simpara>
6567 <literal>-link-opt <emphasis>option</emphasis></literal>
6568 </simpara>
6569 <simpara>Pass <emphasis>option</emphasis> to <literal>gcc</literal> when linking. You can use this to specify
6570 library search paths, e.g. <literal>-link-opt -Lpath</literal>, and libraries to link
6571 with, e.g., <literal>-link-opt -lfoo</literal>, or even both at the same time,
6572 e.g. <literal>-link-opt '-Lpath -lfoo'</literal>. If you wish to pass an option to the
6573 linker, you must use <literal>gcc</literal>'s <literal>-Wl,</literal> syntax, e.g.,
6574 <literal>-link-opt '-Wl,--export-dynamic'</literal>.</simpara>
6575 </listitem>
6576 <listitem>
6577 <simpara>
6578 <literal>-llvm-as-opt <emphasis>option</emphasis></literal>
6579 </simpara>
6580 <simpara>Pass <emphasis>option</emphasis> to <literal>llvm-as</literal> when assembling (<literal>.ll</literal> to <literal>.bc</literal>) LLVM code.</simpara>
6581 </listitem>
6582 <listitem>
6583 <simpara>
6584 <literal>-llvm-llc-opt <emphasis>option</emphasis></literal>
6585 </simpara>
6586 <simpara>Pass <emphasis>option</emphasis> to <literal>llc</literal> when compiling (<literal>.bc</literal> to <literal>.o</literal>) LLVM code.</simpara>
6587 </listitem>
6588 <listitem>
6589 <simpara>
6590 <literal>-llvm-opt-opt <emphasis>option</emphasis></literal>
6591 </simpara>
6592 <simpara>Pass <emphasis>option</emphasis> to <literal>opt</literal> when optimizing (<literal>.bc</literal> to <literal>.bc</literal>) LLVM code.</simpara>
6593 </listitem>
6594 <listitem>
6595 <simpara>
6596 <literal>-mlb-path-map <emphasis>file</emphasis></literal>
6597 </simpara>
6598 <simpara>Use <emphasis>file</emphasis> as an <link linkend="MLBasisPathMap">ML Basis path map</link> to define
6599 additional MLB path variables. Multiple uses of <literal>-mlb-path-map</literal> and
6600 <literal>-mlb-path-var</literal> are allowed, with variable definitions in later path
6601 maps taking precedence over earlier ones.</simpara>
6602 </listitem>
6603 <listitem>
6604 <simpara>
6605 <literal>-mlb-path-var <emphasis>name</emphasis> <emphasis>value</emphasis></literal>
6606 </simpara>
6607 <simpara>Define an additional MLB path variable. Multiple uses of
6608 <literal>-mlb-path-map</literal> and <literal>-mlb-path-var</literal> are allowed, with variable
6609 definitions in later path maps taking precedence over earlier ones.</simpara>
6610 </listitem>
6611 <listitem>
6612 <simpara>
6613 <literal>-output <emphasis>file</emphasis></literal>
6614 </simpara>
6615 <simpara>Specify the name of the final output file. The default name is the
6616 input file name with its suffix removed and an appropriate, possibly
6617 empty, suffix added.</simpara>
6618 </listitem>
6619 <listitem>
6620 <simpara>
6621 <literal>-profile {no|alloc|count|time}</literal>
6622 </simpara>
6623 <simpara>Produce an executable that gathers <link linkend="Profiling">profiling</link> data. When
6624 such an executable is run, it produces an <literal>mlmon.out</literal> file.</simpara>
6625 </listitem>
6626 <listitem>
6627 <simpara>
6628 <literal>-profile-branch {false|true}</literal>
6629 </simpara>
6630 <simpara>If true, the profiler will separately gather profiling data for each
6631 branch of a function definition, <literal>case</literal> expression, and <literal>if</literal>
6632 expression.</simpara>
6633 </listitem>
6634 <listitem>
6635 <simpara>
6636 <literal>-profile-stack {false|true}</literal>
6637 </simpara>
6638 <simpara>If <literal>true</literal>, the executable will gather profiling data for all functions
6639 on the stack, not just the currently executing function. See
6640 <link linkend="ProfilingTheStack">ProfilingTheStack</link>.</simpara>
6641 </listitem>
6642 <listitem>
6643 <simpara>
6644 <literal>-profile-val {false|true}</literal>
6645 </simpara>
6646 <simpara>If <literal>true</literal>, the profiler will separately gather profiling data for each
6647 (expansive) <literal>val</literal> declaration.</simpara>
6648 </listitem>
6649 <listitem>
6650 <simpara>
6651 <literal>-runtime <emphasis>arg</emphasis></literal>
6652 </simpara>
6653 <simpara>Pass argument to the runtime system via <literal>@MLton</literal>. See
6654 <link linkend="RunTimeOptions">RunTimeOptions</link>. The argument will be processed before other
6655 <literal>@MLton</literal> command line switches. Multiple uses of <literal>-runtime</literal> are
6656 allowed, and will pass all the arguments in order. If the same
6657 runtime switch occurs more than once, then the last setting will take
6658 effect. There is no need to supply the leading <literal>@MLton</literal> or the
6659 trailing <literal>--</literal>; these will be supplied automatically.</simpara>
6660 <simpara>An argument to <literal>-runtime</literal> may contain spaces, which will cause the
6661 argument to be treated as a sequence of words by the runtime. For
6662 example the command line:</simpara>
6663 <screen>mlton -runtime 'ram-slop 0.4' foo.sml</screen>
6664 <simpara>will cause <literal>foo</literal> to run as if it had been called like:</simpara>
6665 <screen>foo @MLton ram-slop 0.4 --</screen>
6666 <simpara>An executable created with <literal>-runtime stop</literal> doesn&#8217;t process any
6667 <literal>@MLton</literal> arguments. This is useful to create an executable, e.g.,
6668 <literal>echo</literal>, that must treat <literal>@MLton</literal> like any other command-line argument.</simpara>
6669 <screen>% mlton -runtime stop echo.sml
6670 % echo @MLton --
6671 @MLton --</screen>
6672 </listitem>
6673 <listitem>
6674 <simpara>
6675 <literal>-show-basis <emphasis>file</emphasis></literal>
6676 </simpara>
6677 <simpara>Pretty print to <emphasis>file</emphasis> the basis defined by the input program. See
6678 <link linkend="ShowBasis">ShowBasis</link>.</simpara>
6679 </listitem>
6680 <listitem>
6681 <simpara>
6682 <literal>-show-def-use <emphasis>file</emphasis></literal>
6683 </simpara>
6684 <simpara>Output def-use information to <emphasis>file</emphasis>. Each identifier that is defined
6685 appears on a line, followed on subsequent lines by the position of
6686 each use.</simpara>
6687 </listitem>
6688 <listitem>
6689 <simpara>
6690 <literal>-stop {f|g|o|tc}</literal>
6691 </simpara>
6692 <simpara>Specify when to stop.</simpara>
6693 <informaltable
6694 frame="all"
6695 rowsep="1" colsep="1"
6696 >
6697 <tgroup cols="2">
6698 <colspec colname="col_1" colwidth="25*"/>
6699 <colspec colname="col_2" colwidth="75*"/>
6700 <tbody>
6701 <row>
6702 <entry align="center" valign="top"><simpara><literal>f</literal></simpara></entry>
6703 <entry align="left" valign="top"><simpara>list of files on stdout (only makes sense when input is <literal>foo.mlb</literal>)</simpara></entry>
6704 </row>
6705 <row>
6706 <entry align="center" valign="top"><simpara><literal>g</literal></simpara></entry>
6707 <entry align="left" valign="top"><simpara>generated <literal>.c</literal> and <literal>.s</literal> files</simpara></entry>
6708 </row>
6709 <row>
6710 <entry align="center" valign="top"><simpara><literal>o</literal></simpara></entry>
6711 <entry align="left" valign="top"><simpara>object (<literal>.o</literal>) files</simpara></entry>
6712 </row>
6713 <row>
6714 <entry align="center" valign="top"><simpara><literal>tc</literal></simpara></entry>
6715 <entry align="left" valign="top"><simpara>after type checking</simpara></entry>
6716 </row>
6717 </tbody>
6718 </tgroup>
6719 </informaltable>
6720 <simpara>If you compile with <literal>-stop g</literal> or <literal>-stop o</literal>, you can resume compilation
6721 by running MLton on the generated <literal>.c</literal> and <literal>.s</literal> or <literal>.o</literal> files.</simpara>
6722 </listitem>
6723 <listitem>
6724 <simpara>
6725 <literal>-target {self|<emphasis>&#8230;</emphasis>}</literal>
6726 </simpara>
6727 <simpara>Generate an executable that runs on the specified platform. The
6728 default is <literal>self</literal>, which means to compile for the machine that MLton
6729 is running on. To use any other target, you must first install a
6730 <link linkend="CrossCompiling">cross compiler</link>.</simpara>
6731 </listitem>
6732 <listitem>
6733 <simpara>
6734 <literal>-target-as-opt <emphasis>target</emphasis> <emphasis>option</emphasis></literal>
6735 </simpara>
6736 <simpara>Like <literal>-as-opt</literal>, this passes <emphasis>option</emphasis> to <literal>gcc</literal> when compliling
6737 assembler code, except it only passes <emphasis>option</emphasis> when the target
6738 architecture, operating system, or arch-os pair is <emphasis>target</emphasis>.</simpara>
6739 </listitem>
6740 <listitem>
6741 <simpara>
6742 <literal>-target-cc-opt <emphasis>target</emphasis> <emphasis>option</emphasis></literal>
6743 </simpara>
6744 <simpara>Like <literal>-cc-opt</literal>, this passes <emphasis>option</emphasis> to <literal>gcc</literal> when compiling C code,
6745 except it only passes <emphasis>option</emphasis> when the target architecture, operating
6746 system, or arch-os pair is <emphasis>target</emphasis>.</simpara>
6747 </listitem>
6748 <listitem>
6749 <simpara>
6750 <literal>-target-link-opt <emphasis>target</emphasis> <emphasis>option</emphasis></literal>
6751 </simpara>
6752 <simpara>Like <literal>-link-opt</literal>, this passes <emphasis>option</emphasis> to <literal>gcc</literal> when linking, except
6753 it only passes <emphasis>option</emphasis> when the target architecture, operating
6754 system, or arch-os pair is <emphasis>target</emphasis>.</simpara>
6755 </listitem>
6756 <listitem>
6757 <simpara>
6758 <literal>-verbose {0|1|2|3}</literal>
6759 </simpara>
6760 <simpara>How verbose to be about what passes are running. The default is <literal>0</literal>.</simpara>
6761 <informaltable
6762 frame="all"
6763 rowsep="1" colsep="1"
6764 >
6765 <tgroup cols="2">
6766 <colspec colname="col_1" colwidth="25*"/>
6767 <colspec colname="col_2" colwidth="75*"/>
6768 <tbody>
6769 <row>
6770 <entry align="center" valign="top"><simpara><literal>0</literal></simpara></entry>
6771 <entry align="left" valign="top"><simpara>silent</simpara></entry>
6772 </row>
6773 <row>
6774 <entry align="center" valign="top"><simpara><literal>1</literal></simpara></entry>
6775 <entry align="left" valign="top"><simpara>calls to compiler, assembler, and linker</simpara></entry>
6776 </row>
6777 <row>
6778 <entry align="center" valign="top"><simpara><literal>2</literal></simpara></entry>
6779 <entry align="left" valign="top"><simpara>1, plus intermediate compiler passes</simpara></entry>
6780 </row>
6781 <row>
6782 <entry align="center" valign="top"><simpara><literal>3</literal></simpara></entry>
6783 <entry align="left" valign="top"><simpara>2, plus some data structure sizes</simpara></entry>
6784 </row>
6785 </tbody>
6786 </tgroup>
6787 </informaltable>
6788 </listitem>
6789 </itemizedlist>
6790 <simpara><?asciidoc-pagebreak?></simpara>
6791 </section>
6792 </section>
6793 <section id="CompilingWithSMLNJ">
6794 <title>CompilingWithSMLNJ</title>
6795 <simpara>You can compile MLton with <link linkend="SMLNJ">SML/NJ</link>, however the resulting
6796 compiler will run much more slowly than MLton compiled by itself. We
6797 don&#8217;t recommend using SML/NJ as a means of
6798 <link linkend="PortingMLton">porting MLton</link> to a new platform or bootstrapping on a
6799 new platform.</simpara>
6800 <simpara>If you do want to build MLton with SML/NJ, it is best to have a binary
6801 MLton package installed. If you don&#8217;t, here are some issues you may
6802 encounter when you run <literal>make smlnj-mlton</literal>.</simpara>
6803 <simpara>You will get (many copies of) the error messages:</simpara>
6804 <screen>/bin/sh: mlton: command not found</screen>
6805 <simpara>and</simpara>
6806 <screen>make[2]: mlton: Command not found</screen>
6807 <simpara>The <literal>Makefile</literal> calls <literal>mlton</literal> to determine dependencies, and can
6808 proceed in spite of this error.</simpara>
6809 <simpara>If you don&#8217;t have an <literal>mllex</literal> executable, you will get the error
6810 message:</simpara>
6811 <screen>mllex: Command not found</screen>
6812 <simpara>Building MLton requires <literal>mllex</literal> and <literal>mlyacc</literal> executables, which are
6813 distributed with a binary package of MLton. The easiest solution is
6814 to copy the front-end lexer/parser files from a different machine
6815 (<literal>ml.grm.sml</literal>, <literal>ml.grm.sig</literal>, <literal>ml.lex.sml</literal>, <literal>mlb.grm.sig</literal>,
6816 <literal>mlb.grm.sml</literal>).</simpara>
6817 <simpara><?asciidoc-pagebreak?></simpara>
6818 </section>
6819 <section id="ConcurrentML">
6820 <title>ConcurrentML</title>
6821 <simpara><ulink url="http://cml.cs.uchicago.edu/">Concurrent ML</ulink> is an SML concurrency
6822 library based on synchronous message passing. MLton has an initial
6823 port of CML from SML/NJ, but is missing a thread-safe wrapper around
6824 the Basis Library and event-based equivalents to <literal>IO</literal> and <literal>OS</literal>
6825 functions.</simpara>
6826 <simpara>All of the core CML functionality is present.</simpara>
6827 <programlisting language="sml" linenumbering="unnumbered">structure CML: CML
6828 structure SyncVar: SYNC_VAR
6829 structure Mailbox: MAILBOX
6830 structure Multicast: MULTICAST
6831 structure SimpleRPC: SIMPLE_RPC
6832 structure RunCML: RUN_CML</programlisting>
6833 <simpara>The <literal>RUN_CML</literal> signature is minimal.</simpara>
6834 <programlisting language="sml" linenumbering="unnumbered">signature RUN_CML =
6835 sig
6836 val isRunning: unit -&gt; bool
6837 val doit: (unit -&gt; unit) * Time.time option -&gt; OS.Process.status
6838 val shutdown: OS.Process.status -&gt; 'a
6839 end</programlisting>
6840 <simpara>MLton&#8217;s <literal>RunCML</literal> structure does not include all of the cleanup and
6841 logging operations of SML/NJ&#8217;s <literal>RunCML</literal> structure. However, the
6842 implementation does include the <literal>CML.timeOutEvt</literal> and <literal>CML.atTimeEvt</literal>
6843 functions, and a preemptive scheduler that knows to sleep when there
6844 are no ready threads and some threads blocked on time events.</simpara>
6845 <simpara>Because MLton does not wrap the Basis Library for CML, the "right" way
6846 to call a Basis Library function that is stateful is to wrap the call
6847 with <literal>MLton.Thread.atomically</literal>.</simpara>
6848 <section id="_usage_2">
6849 <title>Usage</title>
6850 <itemizedlist>
6851 <listitem>
6852 <simpara>
6853 You can import the CML Library into an MLB file with:
6854 </simpara>
6855 <informaltable
6856 frame="all"
6857 rowsep="1" colsep="1"
6858 >
6859 <tgroup cols="2">
6860 <colspec colname="col_1" colwidth="50*"/>
6861 <colspec colname="col_2" colwidth="50*"/>
6862 <thead>
6863 <row>
6864 <entry align="left" valign="top">MLB file</entry>
6865 <entry align="left" valign="top">Description</entry>
6866 </row>
6867 </thead>
6868 <tbody>
6869 <row>
6870 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/cml/cml.mlb</literal></simpara></entry>
6871 <entry align="left" valign="top"><simpara></simpara></entry>
6872 </row>
6873 </tbody>
6874 </tgroup>
6875 </informaltable>
6876 </listitem>
6877 <listitem>
6878 <simpara>
6879 If you are porting a project from SML/NJ&#8217;s <link linkend="CompilationManager">CompilationManager</link> to
6880 MLton&#8217;s <link linkend="MLBasis">ML Basis system</link> using <literal>cm2mlb</literal>, note that the
6881 following map is included by default:
6882 </simpara>
6883 <screen># CML Library
6884 $cml $(SML_LIB)/cml
6885 $cml/cml.cm $(SML_LIB)/cml/cml.mlb</screen>
6886 <simpara>This will automatically convert a <literal>$cml/cml.cm</literal> import in an input <literal>.cm</literal> file into a <literal>$(SML_LIB)/cml/cml.mlb</literal> import in the output <literal>.mlb</literal> file.</simpara>
6887 </listitem>
6888 </itemizedlist>
6889 </section>
6890 <section id="_also_see_2">
6891 <title>Also see</title>
6892 <itemizedlist>
6893 <listitem>
6894 <simpara>
6895 <link linkend="ConcurrentMLImplementation">ConcurrentMLImplementation</link>
6896 </simpara>
6897 </listitem>
6898 <listitem>
6899 <simpara>
6900 <link linkend="eXene">eXene</link>
6901 </simpara>
6902 </listitem>
6903 </itemizedlist>
6904 <simpara><?asciidoc-pagebreak?></simpara>
6905 </section>
6906 </section>
6907 <section id="ConcurrentMLImplementation">
6908 <title>ConcurrentMLImplementation</title>
6909 <simpara>Here are some notes on MLton&#8217;s implementation of <link linkend="ConcurrentML">ConcurrentML</link>.</simpara>
6910 <simpara>Concurrent ML was originally implemented for SML/NJ. It was ported to
6911 MLton in the summer of 2004. The main difference between the
6912 implementations is that SML/NJ uses continuations to implement CML
6913 threads, while MLton uses its underlying <link linkend="MLtonThread">thread</link>
6914 package. Presently, MLton&#8217;s threads are a little more heavyweight
6915 than SML/NJ&#8217;s continuations, but it&#8217;s pretty clear that there is some
6916 fat there that could be trimmed.</simpara>
6917 <simpara>The implementation of CML in SML/NJ is built upon the first-class
6918 continuations of the <literal>SMLofNJ.Cont</literal> module.</simpara>
6919 <programlisting language="sml" linenumbering="unnumbered">type 'a cont
6920 val callcc: ('a cont -&gt; 'a) -&gt; 'a
6921 val isolate: ('a -&gt; unit) -&gt; 'a cont
6922 val throw: 'a cont -&gt; 'a -&gt; 'b</programlisting>
6923 <simpara>The implementation of CML in MLton is built upon the first-class
6924 threads of the <link linkend="MLtonThread">MLtonThread</link> module.</simpara>
6925 <programlisting language="sml" linenumbering="unnumbered">type 'a t
6926 val new: ('a -&gt; unit) -&gt; 'a t
6927 val prepare: 'a t * 'a -&gt; Runnable.t
6928 val switch: ('a t -&gt; Runnable.t) -&gt; 'a</programlisting>
6929 <simpara>The port is relatively straightforward, because CML always throws to a
6930 continuation at most once. Hence, an "abstract" implementation of
6931 CML could be built upon first-class one-shot continuations, which map
6932 equally well to SML/NJ&#8217;s continuations and MLton&#8217;s threads.</simpara>
6933 <simpara>The "essence" of the port is to transform:</simpara>
6934 <screen>callcc (fn k =&gt; ... throw k' v')</screen>
6935 <simpara>to</simpara>
6936 <screen>switch (fn t =&gt; ... prepare (t', v'))</screen>
6937 <simpara>which suffices for the vast majority of the CML implementation.</simpara>
6938 <simpara>There was only one complicated transformation: blocking multiple base
6939 events. In SML/NJ CML, the representation of base events is given by:</simpara>
6940 <programlisting language="sml" linenumbering="unnumbered">datatype 'a event_status
6941 = ENABLED of {prio: int, doFn: unit -&gt; 'a}
6942 | BLOCKED of {
6943 transId: trans_id ref,
6944 cleanUp: unit -&gt; unit,
6945 next: unit -&gt; unit
6946 } -&gt; 'a
6947 type 'a base_evt = unit -&gt; 'a event_status</programlisting>
6948 <simpara>When synchronizing on a set of base events, which are all blocked, we
6949 must invoke each <literal>BLOCKED</literal> function with the same <literal>transId</literal> and
6950 <literal>cleanUp</literal> (the <literal>transId</literal> is (checked and) set to <literal>CANCEL</literal> by the
6951 <literal>cleanUp</literal> function, which is invoked by the first enabled event; this
6952 "fizzles" every other event in the synchronization group that later
6953 becomes enabled). However, each <literal>BLOCKED</literal> function is implemented by
6954 a callcc, so that when the event is enabled, it throws back to the
6955 point of synchronization. Hence, the next function (which doesn&#8217;t
6956 return) is invoked by the <literal>BLOCKED</literal> function to escape the callcc and
6957 continue in the thread performing the synchronization. In SML/NJ this
6958 is implemented as follows:</simpara>
6959 <programlisting language="sml" linenumbering="unnumbered">fun ext ([], blockFns) = callcc (fn k =&gt; let
6960 val throw = throw k
6961 val (transId, setFlg) = mkFlg()
6962 fun log [] = S.atomicDispatch ()
6963 | log (blockFn:: r) =
6964 throw (blockFn {
6965 transId = transId,
6966 cleanUp = setFlg,
6967 next = fn () =&gt; log r
6968 })
6969 in
6970 log blockFns; error "[log]"
6971 end)</programlisting>
6972 <simpara>(Note that <literal>S.atomicDispatch</literal> invokes the continuation of the next
6973 continuation on the ready queue.) This doesn&#8217;t map well to the MLton
6974 thread model. Although it follows the</simpara>
6975 <screen>callcc (fn k =&gt; ... throw k v)</screen>
6976 <simpara>model, the fact that <literal>blockFn</literal> will also attempt to do</simpara>
6977 <screen>callcc (fn k' =&gt; ... next ())</screen>
6978 <simpara>means that the naive transformation will result in nested <literal>switch</literal>-es.</simpara>
6979 <simpara>We need to think a little more about what this code is trying to do.
6980 Essentially, each <literal>blockFn</literal> wants to capture this continuation, hold
6981 on to it until the event is enabled, and continue with next; when the
6982 event is enabled, before invoking the continuation and returning to
6983 the synchronization point, the <literal>cleanUp</literal> and other event specific
6984 operations are performed.</simpara>
6985 <simpara>To accomplish the same effect in the MLton thread implementation, we
6986 have the following:</simpara>
6987 <programlisting language="sml" linenumbering="unnumbered">datatype 'a status =
6988 ENABLED of {prio: int, doitFn: unit -&gt; 'a}
6989 | BLOCKED of {transId: trans_id,
6990 cleanUp: unit -&gt; unit,
6991 next: unit -&gt; rdy_thread} -&gt; 'a
6992
6993 type 'a base = unit -&gt; 'a status
6994
6995 fun ext ([], blockFns): 'a =
6996 S.atomicSwitch
6997 (fn (t: 'a S.thread) =&gt;
6998 let
6999 val (transId, cleanUp) = TransID.mkFlg ()
7000 fun log blockFns: S.rdy_thread =
7001 case blockFns of
7002 [] =&gt; S.next ()
7003 | blockFn::blockFns =&gt;
7004 (S.prep o S.new)
7005 (fn _ =&gt; fn () =&gt;
7006 let
7007 val () = S.atomicBegin ()
7008 val x = blockFn {transId = transId,
7009 cleanUp = cleanUp,
7010 next = fn () =&gt; log blockFns}
7011 in S.switch(fn _ =&gt; S.prepVal (t, x))
7012 end)
7013 in
7014 log blockFns
7015 end)</programlisting>
7016 <simpara>To avoid the nested <literal>switch</literal>-es, I run the <literal>blockFn</literal> in it&#8217;s own
7017 thread, whose only purpose is to return to the synchronization point.
7018 This corresponds to the <literal>throw (blockFn {...})</literal> in the SML/NJ
7019 implementation. I&#8217;m worried that this implementation might be a
7020 little expensive, starting a new thread for each blocked event (when
7021 there are only multiple blocked events in a synchronization group).
7022 But, I don&#8217;t see another way of implementing this behavior in the
7023 MLton thread model.</simpara>
7024 <simpara>Note that another way of thinking about what is going on is to
7025 consider each <literal>blockFn</literal> as prepending a different set of actions to
7026 the thread <literal>t</literal>. It might be possible to give a
7027 <literal>MLton.Thread.unsafePrepend</literal>.</simpara>
7028 <programlisting language="sml" linenumbering="unnumbered">fun unsafePrepend (T r: 'a t, f: 'b -&gt; 'a): 'b t =
7029 let
7030 val t =
7031 case !r of
7032 Dead =&gt; raise Fail "prepend to a Dead thread"
7033 | New g =&gt; New (g o f)
7034 | Paused (g, t) =&gt; Paused (fn h =&gt; g (f o h), t)
7035 in (* r := Dead; *)
7036 T (ref t)
7037 end</programlisting>
7038 <simpara>I have commented out the <literal>r := Dead</literal>, which would allow multiple
7039 prepends to the same thread (i.e., not destroying the original thread
7040 in the process). Of course, only one of the threads could be run: if
7041 the original thread were in the <literal>Paused</literal> state, then multiple threads
7042 would share the underlying runtime/primitive thread. Now, this
7043 matches the "one-shot" nature of CML continuations/threads, but I&#8217;m
7044 not comfortable with extending <literal>MLton.Thread</literal> with such an unsafe
7045 operation.</simpara>
7046 <simpara>Other than this complication with blocking multiple base events, the
7047 port was quite routine. (As a very pleasant surprise, the CML
7048 implementation in SML/NJ doesn&#8217;t use any SML/NJ-isms.) There is a
7049 slight difference in the way in which critical sections are handled in
7050 SML/NJ and MLton; since <literal>MLton.Thread.switch</literal> <emphasis>always</emphasis> leaves a
7051 critical section, it is sometimes necessary to add additional
7052 <literal>atomicBegin</literal>-s/<literal>atomicEnd</literal>-s to ensure that we remain in a critical
7053 section after a thread switch.</simpara>
7054 <simpara>While looking at virtually every file in the core CML implementation,
7055 I took the liberty of simplifying things where it seemed possible; in
7056 terms of style, the implementation is about half-way between Reppy&#8217;s
7057 original and MLton&#8217;s.</simpara>
7058 <simpara>Some changes of note:</simpara>
7059 <itemizedlist>
7060 <listitem>
7061 <simpara>
7062 <literal>util/</literal> contains all pertinent data-structures: (functional and
7063 imperative) queues, (functional) priority queues. Hence, it should be
7064 easier to switch in more efficient or real-time implementations.
7065 </simpara>
7066 </listitem>
7067 <listitem>
7068 <simpara>
7069 <literal>core-cml/scheduler.sml</literal>: in both implementations, this is where
7070 most of the interesting action takes place. I&#8217;ve made the connection
7071 between <literal>MLton.Thread.t</literal>-s and <literal>ThreadId.thread_id</literal>-s more abstract
7072 than it is in the SML/NJ implementation, and encapsulated all of the
7073 <literal>MLton.Thread</literal> operations in this module.
7074 </simpara>
7075 </listitem>
7076 <listitem>
7077 <simpara>
7078 eliminated all of the "by hand" inlining
7079 </simpara>
7080 </listitem>
7081 </itemizedlist>
7082 <section id="_future_extensions">
7083 <title>Future Extensions</title>
7084 <simpara>The CML documentation says the following:</simpara>
7085 <blockquote>
7086 <screen>CML.joinEvt: thread_id -&gt; unit event</screen>
7087 <itemizedlist>
7088 <listitem>
7089 <simpara>
7090 <literal>joinEvt tid</literal>
7091 </simpara>
7092 <simpara>creates an event value for synchronizing on the termination of the
7093 thread with the ID tid. There are three ways that a thread may
7094 terminate: the function that was passed to spawn (or spawnc) may
7095 return; it may call the exit function, or it may have an uncaught
7096 exception. Note that <literal>joinEvt</literal> does not distinguish between these
7097 cases; it also does not become enabled if the named thread deadlocks
7098 (even if it is garbage collected).</simpara>
7099 </listitem>
7100 </itemizedlist>
7101 </blockquote>
7102 <simpara>I believe that the <literal>MLton.Finalizable</literal> might be able to relax that
7103 last restriction. Upon the creation of a <literal>'a Scheduler.thread</literal>, we
7104 could attach a finalizer to the underlying <literal>'a MLton.Thread.t</literal> that
7105 enables the <literal>joinEvt</literal> (in the associated <literal>ThreadID.thread_id</literal>) when
7106 the <literal>'a MLton.Thread.t</literal> becomes unreachable.</simpara>
7107 <simpara>I don&#8217;t know why CML doesn&#8217;t have</simpara>
7108 <screen>CML.kill: thread_id -&gt; unit</screen>
7109 <simpara>which has a fairly simple implementation&#8201;&#8212;&#8201;setting a kill flag in the
7110 <literal>thread_id</literal> and adjusting the scheduler to discard any killed threads
7111 that it takes off the ready queue. The fairness of the scheduler
7112 ensures that a killed thread will eventually be discarded. The
7113 semantics are little murky for blocked threads that are killed,
7114 though. For example, consider a thread blocked on <literal>SyncVar.mTake mv</literal>
7115 and a thread blocked on <literal>SyncVar.mGet mv</literal>. If the first thread is
7116 killed while blocked, and a third thread does <literal>SyncVar.mPut (mv, x)</literal>,
7117 then we might expect that we&#8217;ll enable the second thread, and never
7118 the first. But, when only the ready queue is able to discard killed
7119 threads, then the <literal>SyncVar.mPut</literal> could enable the first thread
7120 (putting it on the ready queue, from which it will be discarded) and
7121 leave the second thread blocked. We could solve this by adjusting the
7122 <literal>TransID.trans_id types</literal> and the "cleaner" functions to look for both
7123 canceled transactions and transactions on killed threads.</simpara>
7124 <simpara>John Reppy says that <link linkend="References_MarlowEtAl01">MarlowEtAl01</link> and <link linkend="References_FlattFindler04">FlattFindler04</link>
7125 explain why <literal>CML.kill</literal> would be a bad idea.</simpara>
7126 <simpara>Between <literal>CML.timeOutEvt</literal> and <literal>CML.kill</literal>, one could give an efficient
7127 solution to the recent <literal>comp.lang.ml</literal> post about terminating a
7128 function that doesn&#8217;t complete in a given time.</simpara>
7129 <programlisting language="sml" linenumbering="unnumbered"> fun timeOut (f: unit -&gt; 'a, t: Time.time): 'a option =
7130 let
7131 val iv = SyncVar.iVar ()
7132 val tid = CML.spawn (fn () =&gt; SyncVar.iPut (iv, f ()))
7133 in
7134 CML.select
7135 [CML.wrap (CML.timeOutEvt t, fn () =&gt; (CML.kill tid; NONE)),
7136 CML.wrap (SyncVar.iGetEvt iv, fn x =&gt; SOME x)]
7137 end</programlisting>
7138 </section>
7139 <section id="_space_safety">
7140 <title>Space Safety</title>
7141 <simpara>There are some CML related posts on the MLton mailing list:</simpara>
7142 <itemizedlist>
7143 <listitem>
7144 <simpara>
7145 <ulink url="http://www.mlton.org/pipermail/mlton/2004-May/">http://www.mlton.org/pipermail/mlton/2004-May/</ulink>
7146 </simpara>
7147 </listitem>
7148 </itemizedlist>
7149 <simpara>that discuss concerns that SML/NJ&#8217;s implementation is not space
7150 efficient, because multi-shot continuations can be held indefinitely
7151 on event queues. MLton is better off because of the one-shot nature&#8201;&#8212;&#8201;when an event enables a thread, all other copies of the thread
7152 waiting in other event queues get turned into dead threads (of zero
7153 size).</simpara>
7154 <simpara><?asciidoc-pagebreak?></simpara>
7155 </section>
7156 </section>
7157 <section id="ConstantPropagation">
7158 <title>ConstantPropagation</title>
7159 <simpara><link linkend="ConstantPropagation">ConstantPropagation</link> is an optimization pass for the <link linkend="SSA">SSA</link>
7160 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
7161 <section id="_description_10">
7162 <title>Description</title>
7163 <simpara>This is whole-program constant propagation, even through data
7164 structures. It also performs globalization of (small) values computed
7165 once.</simpara>
7166 <simpara>Uses <link linkend="Multi">Multi</link>.</simpara>
7167 </section>
7168 <section id="_implementation_12">
7169 <title>Implementation</title>
7170 <itemizedlist>
7171 <listitem>
7172 <simpara>
7173 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/constant-propagation.fun"><literal>constant-propagation.fun</literal></ulink>
7174 </simpara>
7175 </listitem>
7176 </itemizedlist>
7177 </section>
7178 <section id="_details_and_notes_12">
7179 <title>Details and Notes</title>
7180 <simpara></simpara>
7181 <simpara><?asciidoc-pagebreak?></simpara>
7182 </section>
7183 </section>
7184 <section id="Contact">
7185 <title>Contact</title>
7186 <section id="_mailing_lists">
7187 <title>Mailing lists</title>
7188 <simpara>There are three mailing lists available.</simpara>
7189 <itemizedlist>
7190 <listitem>
7191 <simpara>
7192 <ulink url="mailto:MLton-user@mlton.org"><literal>MLton-user@mlton.org</literal></ulink>
7193 </simpara>
7194 <simpara>MLton user community discussion</simpara>
7195 <itemizedlist>
7196 <listitem>
7197 <simpara>
7198 <ulink url="https://lists.sourceforge.net/lists/listinfo/mlton-user">subscribe</ulink>
7199 <ulink url="https://sourceforge.net/mailarchive/forum.php?forum_name=mlton-user">archive (SourceForge; current)</ulink>,
7200 <ulink url="http://www.mlton.org/pipermail/mlton-user/">archive (PiperMail; through 201110)</ulink>
7201 </simpara>
7202 </listitem>
7203 </itemizedlist>
7204 </listitem>
7205 <listitem>
7206 <simpara>
7207 <ulink url="mailto:MLton-devel@mlton.org"><literal>MLton-devel@mlton.org</literal></ulink>
7208 </simpara>
7209 <simpara>MLton developer community discussion</simpara>
7210 <itemizedlist>
7211 <listitem>
7212 <simpara>
7213 <ulink url="https://lists.sourceforge.net/lists/listinfo/mlton-devel">subscribe</ulink>
7214 <ulink url="https://sourceforge.net/mailarchive/forum.php?forum_name=mlton-devel">archive (SourceForge; current)</ulink>,
7215 <ulink url="http://www.mlton.org/pipermail/mlton-devel/">archive (PiperMail; through 201110)</ulink>
7216 </simpara>
7217 </listitem>
7218 </itemizedlist>
7219 </listitem>
7220 <listitem>
7221 <simpara>
7222 <ulink url="mailto:MLton-commit@mlton.org"><literal>MLton-commit@mlton.org</literal></ulink>
7223 </simpara>
7224 <simpara>MLton code commits</simpara>
7225 <itemizedlist>
7226 <listitem>
7227 <simpara>
7228 <ulink url="https://lists.sourceforge.net/lists/listinfo/mlton-commit">subscribe</ulink>
7229 </simpara>
7230 </listitem>
7231 <listitem>
7232 <simpara>
7233 <ulink url="https://sourceforge.net/mailarchive/forum.php?forum_name=mlton-commit">archive (SourceForge; current)</ulink>,
7234 <ulink url="http://www.mlton.org/pipermail/mlton-commit/">archive (PiperMail; through 201110)</ulink>
7235 </simpara>
7236 </listitem>
7237 </itemizedlist>
7238 </listitem>
7239 </itemizedlist>
7240 <section id="_mailing_list_policies">
7241 <title>Mailing list policies</title>
7242 <itemizedlist>
7243 <listitem>
7244 <simpara>
7245 Both mailing lists are unmoderated. However, the mailing lists are
7246 configured to discard all spam, to hold all non-subscriber posts
7247 for moderation, to accept all subscriber posts, and to admin approve
7248 subscription requests. Please contact
7249 <ulink url="mailto:matthew.fluet@gmail.com">Matthew Fluet</ulink> if it appears that your
7250 messages are being discarded as spam.
7251 </simpara>
7252 </listitem>
7253 <listitem>
7254 <simpara>
7255 Large messages (over 256K) should not be sent. Rather, please send
7256 an email containing the discussion text and a link to any large files.
7257 </simpara>
7258 </listitem>
7259 </itemizedlist>
7260 <itemizedlist>
7261 <listitem>
7262 <simpara>
7263 Discussions started on the mailing lists should stay on the mailing
7264 lists. Private replies may be bounced to the mailing list for the
7265 benefit of those following the discussion.
7266 </simpara>
7267 </listitem>
7268 <listitem>
7269 <simpara>
7270 Discussions started on
7271 <ulink url="mailto:MLton-user@mlton.org"><literal>MLton-user@mlton.org</literal></ulink> may be migrated to
7272 <ulink url="mailto:MLton-devel@mlton.org"><literal>MLton-devel@mlton.org</literal></ulink>, particularly
7273 when the discussion shifts from how to use MLton to how to modify
7274 MLton (e.g., to fix a bug identified by the initial discussion).
7275 </simpara>
7276 </listitem>
7277 </itemizedlist>
7278 </section>
7279 </section>
7280 <section id="_irc">
7281 <title>IRC</title>
7282 <itemizedlist>
7283 <listitem>
7284 <simpara>
7285 Some MLton developers and users are in channel <literal>#sml</literal> on <ulink url="http://freenode.net">http://freenode.net</ulink>.
7286 </simpara>
7287 </listitem>
7288 </itemizedlist>
7289 <simpara><?asciidoc-pagebreak?></simpara>
7290 </section>
7291 </section>
7292 <section id="Contify">
7293 <title>Contify</title>
7294 <simpara><link linkend="Contify">Contify</link> is an optimization pass for the <link linkend="SSA">SSA</link>
7295 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
7296 <section id="_description_11">
7297 <title>Description</title>
7298 <simpara>Contification is a compiler optimization that turns a function that
7299 always returns to the same place into a continuation. This exposes
7300 control-flow information that is required by many optimizations,
7301 including traditional loop optimizations.</simpara>
7302 </section>
7303 <section id="_implementation_13">
7304 <title>Implementation</title>
7305 <itemizedlist>
7306 <listitem>
7307 <simpara>
7308 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/contify.fun"><literal>contify.fun</literal></ulink>
7309 </simpara>
7310 </listitem>
7311 </itemizedlist>
7312 </section>
7313 <section id="_details_and_notes_13">
7314 <title>Details and Notes</title>
7315 <simpara>See <link linkend="References_FluetWeeks01">Contification Using Dominators</link>. The
7316 intermediate language described in that paper has since evolved to the
7317 <link linkend="SSA">SSA</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>; hence, the complication described in
7318 Section 6.1 is no longer relevant.</simpara>
7319 <simpara><?asciidoc-pagebreak?></simpara>
7320 </section>
7321 </section>
7322 <section id="CoreML">
7323 <title>CoreML</title>
7324 <simpara><link linkend="CoreML">Core ML</link> is an <link linkend="IntermediateLanguage">IntermediateLanguage</link>, translated from
7325 <link linkend="AST">AST</link> by <link linkend="Elaborate">Elaborate</link>, optimized by <link linkend="CoreMLSimplify">CoreMLSimplify</link>, and
7326 translated by <link linkend="Defunctorize">Defunctorize</link> to <link linkend="XML">XML</link>.</simpara>
7327 <section id="_description_12">
7328 <title>Description</title>
7329 <simpara><link linkend="CoreML">CoreML</link> is polymorphic, higher-order, and has nested patterns.</simpara>
7330 </section>
7331 <section id="_implementation_14">
7332 <title>Implementation</title>
7333 <itemizedlist>
7334 <listitem>
7335 <simpara>
7336 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/core-ml/core-ml.sig"><literal>core-ml.sig</literal></ulink>
7337 </simpara>
7338 </listitem>
7339 <listitem>
7340 <simpara>
7341 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/core-ml/core-ml.fun"><literal>core-ml.fun</literal></ulink>
7342 </simpara>
7343 </listitem>
7344 </itemizedlist>
7345 </section>
7346 <section id="_type_checking_2">
7347 <title>Type Checking</title>
7348 <simpara>The <link linkend="CoreML">CoreML</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> has no independent type
7349 checker.</simpara>
7350 </section>
7351 <section id="_details_and_notes_14">
7352 <title>Details and Notes</title>
7353 <simpara></simpara>
7354 <simpara><?asciidoc-pagebreak?></simpara>
7355 </section>
7356 </section>
7357 <section id="CoreMLSimplify">
7358 <title>CoreMLSimplify</title>
7359 <simpara>The single optimization pass for the <link linkend="CoreML">CoreML</link>
7360 <link linkend="IntermediateLanguage">IntermediateLanguage</link> is controlled by the <literal>Compile</literal> functor
7361 (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/main/compile.fun"><literal>compile.fun</literal></ulink>).</simpara>
7362 <simpara>The following optimization pass is implemented:</simpara>
7363 <itemizedlist>
7364 <listitem>
7365 <simpara>
7366 <link linkend="DeadCode">DeadCode</link>
7367 </simpara>
7368 </listitem>
7369 </itemizedlist>
7370 <simpara><?asciidoc-pagebreak?></simpara>
7371 </section>
7372 <section id="Credits">
7373 <title>Credits</title>
7374 <simpara>MLton was designed and implemented by HenryCejtin,
7375 MatthewFluet, SureshJagannathan, and <link linkend="StephenWeeks">StephenWeeks</link>.</simpara>
7376 <itemizedlist>
7377 <listitem>
7378 <simpara>
7379 <link linkend="HenryCejtin">HenryCejtin</link> wrote the <literal>IntInf</literal> implementation, the original
7380 profiler, the original man pages, the <literal>.spec</literal> files for the RPMs,
7381 and lots of little hacks to speed stuff up.
7382 </simpara>
7383 </listitem>
7384 <listitem>
7385 <simpara>
7386 <link linkend="MatthewFluet">MatthewFluet</link> implemented the X86 and AMD64 native code generators,
7387 ported <literal>mlprof</literal> to work with the native code generator, did a lot
7388 of work on the SSA optimizer, both adding new optimizations and
7389 improving or porting existing optimizations, updated the
7390 <link linkend="BasisLibrary">Basis Library</link> implementation, ported
7391 <link linkend="ConcurrentML">ConcurrentML</link> and <link linkend="MLNLFFI">ML-NLFFI</link> to MLton, implemented the
7392 <link linkend="MLBasis">ML Basis system</link>, ported MLton to 64-bit platforms,
7393 and currently leads the project.
7394 </simpara>
7395 </listitem>
7396 <listitem>
7397 <simpara>
7398 <link linkend="SureshJagannathan">SureshJagannathan</link> implemented some early inlining and uncurrying
7399 optimizations.
7400 </simpara>
7401 </listitem>
7402 <listitem>
7403 <simpara>
7404 <link linkend="StephenWeeks">StephenWeeks</link> implemented most of the original version of MLton, and
7405 continues to keep his fingers in most every part.
7406 </simpara>
7407 </listitem>
7408 </itemizedlist>
7409 <simpara>Many people have helped us over the years. Here is an alphabetical
7410 list.</simpara>
7411 <itemizedlist>
7412 <listitem>
7413 <simpara>
7414 <link linkend="JesperLouisAndersen">JesperLouisAndersen</link> sent several patches to improve the runtime on
7415 FreeBSD and ported MLton to run on NetBSD and OpenBSD.
7416 </simpara>
7417 </listitem>
7418 <listitem>
7419 <simpara>
7420 <link linkend="JohnnyAndersen">JohnnyAndersen</link> implemented <literal>BinIO</literal>, modified MLton so it could
7421 cross compile to MinGW, and provided useful discussion about
7422 cross-compilation.
7423 </simpara>
7424 </listitem>
7425 <listitem>
7426 <simpara>
7427 Alexander Abushkevich extended support for OpenBSD.
7428 </simpara>
7429 </listitem>
7430 <listitem>
7431 <simpara>
7432 Ross Bayer added the <literal>-keep ast</literal> compile-time option and experimented with
7433 porting the build system to CMake.
7434 </simpara>
7435 </listitem>
7436 <listitem>
7437 <simpara>
7438 Kevin Bradley added initial support for <link linkend="SuccessorML">SuccessorML</link> features.
7439 </simpara>
7440 </listitem>
7441 <listitem>
7442 <simpara>
7443 Bryan Camp added <literal>-disable-pass _regex_</literal> and <literal>enable-pass _regex_</literal> compile
7444 options to generalize <literal>-drop-pass _regex_</literal> and added <literal>Array_copyArray</literal> and
7445 <literal>Array_copyVector</literal> primitives.
7446 </simpara>
7447 </listitem>
7448 <listitem>
7449 <simpara>
7450 Jason Carr added a parser combinator library and a parser for the <link linkend="SXML">SXML</link>
7451 IR, extended compilation to start with a <literal>.sxml</literal> file, and experimented with
7452 alternate control-flow analyses for <link linkend="ClosureConvert">closure conversion</link>.
7453 </simpara>
7454 </listitem>
7455 <listitem>
7456 <simpara>
7457 Christopher Cramer contributed support for additional
7458 <literal>Posix.ProcEnv.sysconf</literal> variables, performance improvements for
7459 <literal>String.concatWith</literal>, and Debian packaging.
7460 </simpara>
7461 </listitem>
7462 <listitem>
7463 <simpara>
7464 Alain Deutsch and
7465 <ulink url="http://www.polyspace.com/">PolySpace Technologies</ulink> provided many bug
7466 fixes and runtime system improvements, code to help the Sparc/Solaris
7467 port, and funded a number of improvements to MLton.
7468 </simpara>
7469 </listitem>
7470 <listitem>
7471 <simpara>
7472 Armando Doval updated <literal>mlnlffigen</literal> to warn and skip functions with
7473 <literal>struct</literal>/<literal>union</literal> arguments.
7474 </simpara>
7475 </listitem>
7476 <listitem>
7477 <simpara>
7478 Martin Elsman provided helpful discussions in the development of
7479 the <link linkend="MLBasis">ML Basis system</link>.
7480 </simpara>
7481 </listitem>
7482 <listitem>
7483 <simpara>
7484 Brent Fulgham ported MLton most of the way to MinGW.
7485 </simpara>
7486 </listitem>
7487 <listitem>
7488 <simpara>
7489 <link linkend="AdamGoode">AdamGoode</link> provided a script to build the PDF MLton Guide and
7490 maintains the
7491 <ulink url="https://admin.fedoraproject.org/pkgdb/acls/name/mlton">Fedora</ulink>
7492 packages.
7493 </simpara>
7494 </listitem>
7495 <listitem>
7496 <simpara>
7497 Simon Helsen provided bug reports, suggestions, and helpful
7498 discussions.
7499 </simpara>
7500 </listitem>
7501 <listitem>
7502 <simpara>
7503 Joe Hurd provided useful discussion and feedback on source-level
7504 profiling.
7505 </simpara>
7506 </listitem>
7507 <listitem>
7508 <simpara>
7509 <link linkend="VesaKarvonen">VesaKarvonen</link> contributed <literal>esml-mode.el</literal> and <literal>esml-mlb-mode.el</literal> (see <link linkend="Emacs">Emacs</link>),
7510 contributed patches for improving match warnings,
7511 contributed <literal>esml-du-mlton.el</literal> and extended def-use output to include types of variable definitions (see <link linkend="EmacsDefUseMode">EmacsDefUseMode</link>), and
7512 improved constant folding of floating-point operations.
7513 </simpara>
7514 </listitem>
7515 <listitem>
7516 <simpara>
7517 Richard Kelsey provided helpful discussions.
7518 </simpara>
7519 </listitem>
7520 <listitem>
7521 <simpara>
7522 Ville Laurikari ported MLton to IA64/HPUX, HPPA/HPUX, PowerPC/AIX, PowerPC64/AIX.
7523 </simpara>
7524 </listitem>
7525 <listitem>
7526 <simpara>
7527 Brian Leibig implemented the <link linkend="LLVMCodegen">LLVMCodegen</link>.
7528 </simpara>
7529 </listitem>
7530 <listitem>
7531 <simpara>
7532 Geoffrey Mainland helped with FreeBSD packaging.
7533 </simpara>
7534 </listitem>
7535 <listitem>
7536 <simpara>
7537 Eric McCorkle ported MLton to Intel Mac.
7538 </simpara>
7539 </listitem>
7540 <listitem>
7541 <simpara>
7542 <link linkend="TomMurphy">TomMurphy</link> wrote the original version of <literal>MLton.Syslog</literal> as part
7543 of his <literal>mlftpd</literal> project, and has sent many useful bug reports and
7544 suggestions.
7545 </simpara>
7546 </listitem>
7547 <listitem>
7548 <simpara>
7549 Michael Neumann helped to patch the runtime to compile under
7550 FreeBSD.
7551 </simpara>
7552 </listitem>
7553 <listitem>
7554 <simpara>
7555 Barak Pearlmutter built the original
7556 <ulink url="http://packages.debian.org/mlton">Debian package</ulink> for MLton, and
7557 helped us to take over the process.
7558 </simpara>
7559 </listitem>
7560 <listitem>
7561 <simpara>
7562 Filip Pizlo ported MLton to (PowerPC) Darwin.
7563 </simpara>
7564 </listitem>
7565 <listitem>
7566 <simpara>
7567 Vedant Raiththa extended the <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link> with support for
7568 <literal>pure</literal> and <literal>impure</literal> attributes to <literal>_import</literal>.
7569 </simpara>
7570 </listitem>
7571 <listitem>
7572 <simpara>
7573 Krishna Ravikumar added initial support for vector expressions and the
7574 <literal>Vector_vector</literal> primitive.
7575 </simpara>
7576 </listitem>
7577 <listitem>
7578 <simpara>
7579 John Reppy assisted in porting MLton to Intel Mac.
7580 </simpara>
7581 </listitem>
7582 <listitem>
7583 <simpara>
7584 Sam Rushing ported MLton to FreeBSD.
7585 </simpara>
7586 </listitem>
7587 <listitem>
7588 <simpara>
7589 Rob Simmons refactored the array and vector implementation in the
7590 <link linkend="BasisLibrary">Basis Library:</link> into a primitive implementation (using
7591 <literal>SeqInt.int</literal> for indexing) and a wrapper implementation (using the default
7592 <literal>Int.int</literal> for indexing).
7593 </simpara>
7594 </listitem>
7595 <listitem>
7596 <simpara>
7597 Jeffrey Mark Siskind provided helpful discussions and inspiration
7598 with his Stalin Scheme compiler.
7599 </simpara>
7600 </listitem>
7601 <listitem>
7602 <simpara>
7603 Matthew Surawski added <link linkend="LoopUnroll">LoopUnroll</link> and <link linkend="LoopUnswitch">LoopUnswitch</link> SSA optimizations.
7604 </simpara>
7605 </listitem>
7606 <listitem>
7607 <simpara>
7608 <link linkend="WesleyTerpstra">WesleyTerpstra</link> added support for <literal>MLton.Process.create</literal>, made
7609 a number of contributions to the <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link>,
7610 contributed a number of runtime system patches,
7611 added support for compiling to a <link linkend="LibrarySupport">C library</link>,
7612 ported MLton to <ulink url="http://mingw.org">MinGW</ulink> and all <ulink url="http://packages.debian.org/search?keywords=mlton&amp;searchon=names&amp;suite=all&amp;section=all">Debian</ulink> supported architectures with <link linkend="CrossCompiling">cross-compiling</link> support,
7613 and maintains the <ulink url="http://packages.debian.org/search?keywords=mlton&amp;searchon=names&amp;suite=all&amp;section=all">Debian</ulink> and <ulink url="http://mingw.org">MinGW</ulink> packages.
7614 </simpara>
7615 </listitem>
7616 <listitem>
7617 <simpara>
7618 Maksim Yegorov added rudimentary support for <literal>./configure</literal> and other
7619 improvements to the build system and implemented the <link linkend="ShareZeroVec">ShareZeroVec</link> SSA
7620 optimization.
7621 </simpara>
7622 </listitem>
7623 <listitem>
7624 <simpara>
7625 Luke Ziarek assisted in porting MLton to (PowerPC) Darwin.
7626 </simpara>
7627 </listitem>
7628 </itemizedlist>
7629 <simpara>We have also benefited from other software development tools and
7630 used code from other sources.</simpara>
7631 <itemizedlist>
7632 <listitem>
7633 <simpara>
7634 MLton was developed using
7635 <link linkend="SMLNJ">Standard ML of New Jersey</link> and the
7636 <link linkend="CompilationManager">Compilation Manager (CM)</link>
7637 </simpara>
7638 </listitem>
7639 <listitem>
7640 <simpara>
7641 MLton&#8217;s lexer (<literal>mlton/frontend/ml.lex</literal>), parser
7642 (<literal>mlton/frontend/ml.grm</literal>), and precedence-parser
7643 (<literal>mlton/elaborate/precedence-parse.fun</literal>) are modified versions of
7644 code from SML/NJ.
7645 </simpara>
7646 </listitem>
7647 <listitem>
7648 <simpara>
7649 The MLton <link linkend="BasisLibrary">Basis Library</link> implementation of
7650 conversions between binary and decimal representations of reals uses
7651 David Gay&#8217;s <ulink url="http://www.netlib.org/fp/">gdtoa</ulink> library.
7652 </simpara>
7653 </listitem>
7654 <listitem>
7655 <simpara>
7656 The MLton <link linkend="BasisLibrary">Basis Library</link> implementation uses
7657 modified versions of portions of the the SML/NJ Basis Library
7658 implementation modules <literal>OS.IO</literal>, <literal>Posix.IO</literal>, <literal>Process</literal>,
7659 and <literal>Unix</literal>.
7660 </simpara>
7661 </listitem>
7662 <listitem>
7663 <simpara>
7664 The MLton <link linkend="BasisLibrary">Basis Library</link> implementation uses
7665 modified versions of portions of the <link linkend="MLKit">ML Kit</link> Version 4.1.4
7666 Basis Library implementation modules <literal>Path</literal>, <literal>Time</literal>, and
7667 <literal>Date</literal>.
7668 </simpara>
7669 </listitem>
7670 <listitem>
7671 <simpara>
7672 Many of the benchmarks come from the SML/NJ benchmark suite.
7673 </simpara>
7674 </listitem>
7675 <listitem>
7676 <simpara>
7677 Many of the regression tests come from the ML Kit Version 4.1.4
7678 distribution, which borrowed them from the
7679 <ulink url="http://www.dina.kvl.dk/%7Esestoft/mosml.html">Moscow ML</ulink> distribution.
7680 </simpara>
7681 </listitem>
7682 <listitem>
7683 <simpara>
7684 MLton uses the <ulink url="http://www.gnu.org/software/gmp/gmp.html">GNU multiprecision library</ulink> for its implementation of <literal>IntInf</literal>.
7685 </simpara>
7686 </listitem>
7687 <listitem>
7688 <simpara>
7689 MLton&#8217;s implementation of <link linkend="MLLex">mllex</link>, <link linkend="MLYacc">mlyacc</link>,
7690 the <link linkend="CKitLibrary">ckit Library</link>,
7691 the <link linkend="MLLPTLibrary">ML-LPT Library</link>,
7692 the <link linkend="MLRISCLibrary">MLRISC Library</link>,
7693 the <link linkend="SMLNJLibrary">SML/NJ Library</link>,
7694 <link linkend="ConcurrentML">Concurrent ML</link>,
7695 mlnlffigen and <link linkend="MLNLFFI">ML-NLFFI</link>
7696 are modified versions of code from SML/NJ.
7697 </simpara>
7698 </listitem>
7699 </itemizedlist>
7700 <simpara><?asciidoc-pagebreak?></simpara>
7701 </section>
7702 <section id="CrossCompiling">
7703 <title>CrossCompiling</title>
7704 <simpara>MLton&#8217;s <literal>-target</literal> flag directs MLton to cross compile an application
7705 for another platform. By default, MLton is only able to compile for
7706 the machine it is running on. In order to use MLton as a cross
7707 compiler, you need to do two things.</simpara>
7708 <orderedlist numeration="arabic">
7709 <listitem>
7710 <simpara>
7711 Install the GCC cross-compiler tools on the host so that GCC can
7712 compile to the target.
7713 </simpara>
7714 </listitem>
7715 <listitem>
7716 <simpara>
7717 Cross compile the MLton runtime system to build the runtime
7718 libraries for the target.
7719 </simpara>
7720 </listitem>
7721 </orderedlist>
7722 <simpara>To make the terminology clear, we refer to the <emphasis>host</emphasis> as the machine
7723 MLton is running on and the <emphasis>target</emphasis> as the machine that MLton is
7724 compiling for.</simpara>
7725 <simpara>To build a GCC cross-compiler toolset on the host, you can use the
7726 script <literal>bin/build-cross-gcc</literal>, available in the MLton sources, as a
7727 template. The value of the <literal>target</literal> variable in that script is
7728 important, since that is what you will pass to MLton&#8217;s <literal>-target</literal> flag.
7729 Once you have the toolset built, you should be able to test it by
7730 cross compiling a simple hello world program on your host machine.</simpara>
7731 <screen>% gcc -b i386-pc-cygwin -o hello-world hello-world.c</screen>
7732 <simpara>You should now be able to run <literal>hello-world</literal> on the target machine, in
7733 this case, a Cygwin machine.</simpara>
7734 <simpara>Next, you must cross compile the MLton runtime system and inform MLton
7735 of the availability of the new target. The script <literal>bin/add-cross</literal>
7736 from the MLton sources will help you do this. Please read the
7737 comments at the top of the script. Here is a sample run adding a
7738 Solaris cross compiler.</simpara>
7739 <screen>% add-cross sparc-sun-solaris sun blade
7740 Making runtime.
7741 Building print-constants executable.
7742 Running print-constants on blade.</screen>
7743 <simpara>Running <literal>add-cross</literal> uses <literal>ssh</literal> to compile the runtime on the target
7744 machine and to create <literal>print-constants</literal>, which prints out all of the
7745 constants that MLton needs in order to implement the
7746 <link linkend="BasisLibrary">Basis Library</link>. The script runs <literal>print-constants</literal> on
7747 the target machine (<literal>blade</literal> in this case), and saves the output.</simpara>
7748 <simpara>Once you have done all this, you should be able to cross compile SML
7749 applications. For example,</simpara>
7750 <screen>mlton -target i386-pc-cygwin hello-world.sml</screen>
7751 <simpara>will create <literal>hello-world</literal>, which you should be able to run from a
7752 Cygwin shell on your Windows machine.</simpara>
7753 <section id="_cross_compiling_alternatives">
7754 <title>Cross-compiling alternatives</title>
7755 <simpara>Building and maintaining cross-compiling <literal>gcc</literal>'s is complex. You may
7756 find it simpler to use <literal>mlton -keep g</literal> to generate the files on the
7757 host, then copy the files to the target, and then use <literal>gcc</literal> or <literal>mlton</literal>
7758 on the target to compile the files.</simpara>
7759 <simpara><?asciidoc-pagebreak?></simpara>
7760 </section>
7761 </section>
7762 <section id="CVS">
7763 <title>CVS</title>
7764 <simpara><ulink url="http://www.gnu.org/software/cvs/">CVS</ulink> (Concurrent Versions System) is
7765 a version control system. The MLton project used CVS to maintain its
7766 <link linkend="Sources">source code</link>, but switched to <link linkend="Subversion">Subversion</link> on 20050730.</simpara>
7767 <simpara>Here are some online CVS resources.</simpara>
7768 <itemizedlist>
7769 <listitem>
7770 <simpara>
7771 <ulink url="http://cvsbook.red-bean.com/">Open Source Development with CVS</ulink>
7772 </simpara>
7773 </listitem>
7774 </itemizedlist>
7775 <simpara><?asciidoc-pagebreak?></simpara>
7776 </section>
7777 <section id="DeadCode">
7778 <title>DeadCode</title>
7779 <simpara><link linkend="DeadCode">DeadCode</link> is an optimization pass for the <link linkend="CoreML">CoreML</link>
7780 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="CoreMLSimplify">CoreMLSimplify</link>.</simpara>
7781 <section id="_description_13">
7782 <title>Description</title>
7783 <simpara>This pass eliminates declarations from the
7784 <link linkend="BasisLibrary">Basis Library</link> not needed by the user program.</simpara>
7785 </section>
7786 <section id="_implementation_15">
7787 <title>Implementation</title>
7788 <itemizedlist>
7789 <listitem>
7790 <simpara>
7791 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/core-ml/dead-code.sig"><literal>dead-code.sig</literal></ulink>
7792 </simpara>
7793 </listitem>
7794 <listitem>
7795 <simpara>
7796 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/core-ml/dead-code.fun"><literal>dead-code.fun</literal></ulink>
7797 </simpara>
7798 </listitem>
7799 </itemizedlist>
7800 </section>
7801 <section id="_details_and_notes_15">
7802 <title>Details and Notes</title>
7803 <simpara>In order to compile small programs rapidly, a pass of dead code
7804 elimination is run in order to eliminate as much of the Basis Library
7805 as possible. The dead code elimination algorithm used is not safe in
7806 general, and only works because the Basis Library implementation has
7807 special properties:</simpara>
7808 <itemizedlist>
7809 <listitem>
7810 <simpara>
7811 it terminates
7812 </simpara>
7813 </listitem>
7814 <listitem>
7815 <simpara>
7816 it performs no I/O
7817 </simpara>
7818 </listitem>
7819 </itemizedlist>
7820 <simpara>The dead code elimination includes the minimal set of
7821 declarations from the Basis Library so that there are no free
7822 variables in the user program (or remaining Basis Library
7823 implementation). It has a special hack to include all
7824 bindings of the form:</simpara>
7825 <programlisting language="sml" linenumbering="unnumbered"> val _ = ...</programlisting>
7826 <simpara>There is an <link linkend="MLBasisAnnotations">ML Basis annotation</link>,
7827 <literal>deadCode true</literal>, that governs which code is subject to this unsafe
7828 dead-code elimination.</simpara>
7829 <simpara><?asciidoc-pagebreak?></simpara>
7830 </section>
7831 </section>
7832 <section id="DeepFlatten">
7833 <title>DeepFlatten</title>
7834 <simpara><link linkend="DeepFlatten">DeepFlatten</link> is an optimization pass for the <link linkend="SSA2">SSA2</link>
7835 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSA2Simplify">SSA2Simplify</link>.</simpara>
7836 <section id="_description_14">
7837 <title>Description</title>
7838 <simpara>This pass flattens into mutable fields of objects and into vectors.</simpara>
7839 <simpara>For example, an <literal>(int * int) ref</literal> is represented by a 2 word
7840 object, and an <literal>(int * int) array</literal> contains pairs of <literal>int</literal>-s,
7841 rather than pointers to pairs of <literal>int</literal>-s.</simpara>
7842 </section>
7843 <section id="_implementation_16">
7844 <title>Implementation</title>
7845 <itemizedlist>
7846 <listitem>
7847 <simpara>
7848 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/deep-flatten.fun"><literal>deep-flatten.fun</literal></ulink>
7849 </simpara>
7850 </listitem>
7851 </itemizedlist>
7852 </section>
7853 <section id="_details_and_notes_16">
7854 <title>Details and Notes</title>
7855 <simpara>There are some performance issues with the deep flatten pass, where it
7856 consumes an excessive amount of memory.</simpara>
7857 <itemizedlist>
7858 <listitem>
7859 <simpara>
7860 <ulink url="http://www.mlton.org/pipermail/mlton/2005-April/026990.html">http://www.mlton.org/pipermail/mlton/2005-April/026990.html</ulink>
7861 </simpara>
7862 </listitem>
7863 <listitem>
7864 <simpara>
7865 <ulink url="http://www.mlton.org/pipermail/mlton-user/2010-June/001626.html">http://www.mlton.org/pipermail/mlton-user/2010-June/001626.html</ulink>
7866 </simpara>
7867 </listitem>
7868 <listitem>
7869 <simpara>
7870 <ulink url="http://www.mlton.org/pipermail/mlton/2010-December/030876.html">http://www.mlton.org/pipermail/mlton/2010-December/030876.html</ulink>
7871 </simpara>
7872 </listitem>
7873 </itemizedlist>
7874 <simpara>A number of applications require compilation with
7875 <literal>-disable-pass deepFlatten</literal> to avoid exceeding available memory. It is
7876 often asked whether the deep flatten pass usually has a significant
7877 impact on performance. The standard benchmark suite was run with and
7878 without the deep flatten pass enabled when the pass was first
7879 introduced:</simpara>
7880 <itemizedlist>
7881 <listitem>
7882 <simpara>
7883 <ulink url="http://www.mlton.org/pipermail/mlton/2004-August/025760.html">http://www.mlton.org/pipermail/mlton/2004-August/025760.html</ulink>
7884 </simpara>
7885 </listitem>
7886 </itemizedlist>
7887 <simpara>The conclusion is that it does not have a significant impact.
7888 However, these are micro benchmarks; other applications may derive
7889 greater benefit from the pass.</simpara>
7890 <simpara><?asciidoc-pagebreak?></simpara>
7891 </section>
7892 </section>
7893 <section id="DefineTypeBeforeUse">
7894 <title>DefineTypeBeforeUse</title>
7895 <simpara><link linkend="StandardML">Standard ML</link> requires types to be defined before they are
7896 used. Because of type inference, the use of a type can be implicit;
7897 hence, this requirement is more subtle than it might appear. For
7898 example, the following program is not type correct, because the type
7899 of <literal>r</literal> is <literal>t option ref</literal>, but <literal>t</literal> is defined after <literal>r</literal>.</simpara>
7900 <programlisting language="sml" linenumbering="unnumbered">val r = ref NONE
7901 datatype t = A | B
7902 val () = r := SOME A</programlisting>
7903 <simpara>MLton reports the following error, indicating that the type defined on
7904 line 2 is used on line 1.</simpara>
7905 <screen>Error: z.sml 3.10-3.20.
7906 Function applied to incorrect argument.
7907 expects: _ * [???] option
7908 but got: _ * [t] option
7909 in: := (r, SOME A)
7910 note: type would escape its scope: t
7911 escape from: z.sml 2.10-2.10
7912 escape to: z.sml 1.1-1.16
7913 Warning: z.sml 1.5-1.5.
7914 Type of variable was not inferred and could not be generalized: r.
7915 type: ??? option ref
7916 in: val r = ref NONE</screen>
7917 <simpara>While the above example is benign, the following example shows how to
7918 cast an integer to a function by (implicitly) using a type before it
7919 is defined. In the example, the ref cell <literal>r</literal> is of type
7920 <literal>t option ref</literal>, where <literal>t</literal> is defined <emphasis>after</emphasis> <literal>r</literal>, as a parameter to
7921 functor <literal>F</literal>.</simpara>
7922 <programlisting language="sml" linenumbering="unnumbered">val r = ref NONE
7923 functor F (type t
7924 val x: t) =
7925 struct
7926 val () = r := SOME x
7927 fun get () = valOf (!r)
7928 end
7929 structure S1 = F (type t = unit -&gt; unit
7930 val x = fn () =&gt; ())
7931 structure S2 = F (type t = int
7932 val x = 13)
7933 val () = S1.get () ()</programlisting>
7934 <simpara>MLton reports the following error.</simpara>
7935 <screen>Warning: z.sml 1.5-1.5.
7936 Type of variable was not inferred and could not be generalized: r.
7937 type: ??? option ref
7938 in: val r = ref NONE
7939 Error: z.sml 5.16-5.26.
7940 Function applied to incorrect argument.
7941 expects: _ * [???] option
7942 but got: _ * [t] option
7943 in: := (r, SOME x)
7944 note: type would escape its scope: t
7945 escape from: z.sml 2.17-2.17
7946 escape to: z.sml 1.1-1.16
7947 Warning: z.sml 6.11-6.13.
7948 Type of variable was not inferred and could not be generalized: get.
7949 type: unit -&gt; ???
7950 in: fun get () = (valOf (! r))
7951 Error: z.sml 12.10-12.18.
7952 Function not of arrow type.
7953 function: [unit]
7954 in: (S1.get ()) ()</screen>
7955 <simpara><?asciidoc-pagebreak?></simpara>
7956 </section>
7957 <section id="DefinitionOfStandardML">
7958 <title>DefinitionOfStandardML</title>
7959 <simpara><link linkend="References_MilnerEtAl97">The Definition of Standard ML (Revised)</link> is a
7960 terse and formal specification of <link linkend="StandardML">Standard ML</link>'s syntax
7961 and semantics. The language specified by this book is often referred
7962 to as SML 97. You can check its syntax
7963 <ulink url="http://www.mpi-sws.org/~rossberg/sml.html">grammar</ulink> online (thanks to
7964 Andreas Rossberg).</simpara>
7965 <simpara><link linkend="References_MilnerEtAl90">The Definition of Standard ML</link> is an older
7966 version of the definition, published in 1990. The accompanying
7967 <link linkend="References_MilnerTofte91">Commentary</link> introduces and explains the notation
7968 and approach. The same notation is used in the SML 97 definition, so it
7969 is worth keeping the older definition and its commentary at hand if you
7970 intend a close study of the definition.</simpara>
7971 <simpara><?asciidoc-pagebreak?></simpara>
7972 </section>
7973 <section id="Defunctorize">
7974 <title>Defunctorize</title>
7975 <simpara><link linkend="Defunctorize">Defunctorize</link> is a translation pass from the <link linkend="CoreML">CoreML</link>
7976 <link linkend="IntermediateLanguage">IntermediateLanguage</link> to the <link linkend="XML">XML</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>.</simpara>
7977 <section id="_description_15">
7978 <title>Description</title>
7979 <simpara>This pass converts a <link linkend="CoreML">CoreML</link> program to an <link linkend="XML">XML</link> program by
7980 performing:</simpara>
7981 <itemizedlist>
7982 <listitem>
7983 <simpara>
7984 linearization
7985 </simpara>
7986 </listitem>
7987 <listitem>
7988 <simpara>
7989 <link linkend="MatchCompile">MatchCompile</link>
7990 </simpara>
7991 </listitem>
7992 <listitem>
7993 <simpara>
7994 polymorphic <literal>val</literal> dec expansion
7995 </simpara>
7996 </listitem>
7997 <listitem>
7998 <simpara>
7999 <literal>datatype</literal> lifting (to the top-level)
8000 </simpara>
8001 </listitem>
8002 </itemizedlist>
8003 </section>
8004 <section id="_implementation_17">
8005 <title>Implementation</title>
8006 <itemizedlist>
8007 <listitem>
8008 <simpara>
8009 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/defunctorize/defunctorize.sig"><literal>defunctorize.sig</literal></ulink>
8010 </simpara>
8011 </listitem>
8012 <listitem>
8013 <simpara>
8014 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/defunctorize/defunctorize.fun"><literal>defunctorize.fun</literal></ulink>
8015 </simpara>
8016 </listitem>
8017 </itemizedlist>
8018 </section>
8019 <section id="_details_and_notes_17">
8020 <title>Details and Notes</title>
8021 <simpara>This pass is grossly misnamed and does not perform defunctorization.</simpara>
8022 <section id="_datatype_lifting">
8023 <title>Datatype Lifting</title>
8024 <simpara>This pass moves all <literal>datatype</literal> declarations to the top level.</simpara>
8025 <simpara><link linkend="StandardML">Standard ML</link> <literal>datatype</literal> declarations can contain type
8026 variables that are not bound in the declaration itself. For example,
8027 the following program is valid.</simpara>
8028 <programlisting language="sml" linenumbering="unnumbered">fun 'a f (x: 'a) =
8029 let
8030 datatype 'b t = T of 'a * 'b
8031 val y: int t = T (x, 1)
8032 in
8033 13
8034 end</programlisting>
8035 <simpara>Unfortunately, the <literal>datatype</literal> declaration can not be immediately moved
8036 to the top level, because that would leave <literal>'a</literal> free.</simpara>
8037 <programlisting language="sml" linenumbering="unnumbered">datatype 'b t = T of 'a * 'b
8038 fun 'a f (x: 'a) =
8039 let
8040 val y: int t = T (x, 1)
8041 in
8042 13
8043 end</programlisting>
8044 <simpara>In order to safely move `datatype`s, this pass must close them, as
8045 well as add any free type variables as extra arguments to the type
8046 constructor. For example, the above program would be translated to
8047 the following.</simpara>
8048 <programlisting language="sml" linenumbering="unnumbered">datatype ('a, 'b) t = T of 'a * 'b
8049 fun 'a f (x: 'a) =
8050 let
8051 val y: ('a * int) t = T (x, 1)
8052 in
8053 13
8054 end</programlisting>
8055 </section>
8056 </section>
8057 <section id="_historical_notes">
8058 <title>Historical Notes</title>
8059 <simpara>The <link linkend="Defunctorize">Defunctorize</link> pass originally eliminated
8060 <link linkend="StandardML">Standard ML</link> functors by duplicating their body at each
8061 application. These duties have been adopted by the <link linkend="Elaborate">Elaborate</link>
8062 pass.</simpara>
8063 <simpara><?asciidoc-pagebreak?></simpara>
8064 </section>
8065 </section>
8066 <section id="Developers">
8067 <title>Developers</title>
8068 <simpara>Here is a picture of the MLton team at a meeting in Chicago in August
8069 2003. From left to right we have:</simpara>
8070 <informaltable
8071 frame="none"
8072 rowsep="1" colsep="1"
8073 >
8074 <tgroup cols="1">
8075 <colspec colname="col_1" colwidth="100*"/>
8076 <tbody>
8077 <row>
8078 <entry align="center" valign="top"><simpara><link linkend="StephenWeeks">StephenWeeks</link>&#8201;&#8212;&#8201;<link linkend="MatthewFluet">MatthewFluet</link>&#8201;&#8212;&#8201;<link linkend="HenryCejtin">HenryCejtin</link>&#8201;&#8212;&#8201;<link linkend="SureshJagannathan">SureshJagannathan</link></simpara></entry>
8079 </row>
8080 </tbody>
8081 </tgroup>
8082 </informaltable>
8083 <informalfigure>
8084 <mediaobject>
8085 <imageobject>
8086 <imagedata fileref="Developers.attachments/team.jpg" align="center"/>
8087 </imageobject>
8088 <textobject><phrase>Developers.attachments/team.jpg</phrase></textobject>
8089 </mediaobject>
8090 </informalfigure>
8091 <simpara>Also see the <link linkend="Credits">Credits</link> for a list of specific contributions.</simpara>
8092 <section id="_developers_list">
8093 <title>Developers list</title>
8094 <simpara>A number of people read the developers mailing list,
8095 <ulink url="mailto:MLton-devel@mlton.org"><literal>MLton-devel@mlton.org</literal></ulink>, and make
8096 contributions there. Here&#8217;s a list of those who have a page here.</simpara>
8097 <itemizedlist>
8098 <listitem>
8099 <simpara>
8100 <link linkend="AndreiFormiga">AndreiFormiga</link>
8101 </simpara>
8102 </listitem>
8103 <listitem>
8104 <simpara>
8105 <link linkend="JesperLouisAndersen">JesperLouisAndersen</link>
8106 </simpara>
8107 </listitem>
8108 <listitem>
8109 <simpara>
8110 <link linkend="JohnnyAndersen">JohnnyAndersen</link>
8111 </simpara>
8112 </listitem>
8113 <listitem>
8114 <simpara>
8115 <link linkend="MichaelNorrish">MichaelNorrish</link>
8116 </simpara>
8117 </listitem>
8118 <listitem>
8119 <simpara>
8120 <link linkend="MikeThomas">MikeThomas</link>
8121 </simpara>
8122 </listitem>
8123 <listitem>
8124 <simpara>
8125 <link linkend="RayRacine">RayRacine</link>
8126 </simpara>
8127 </listitem>
8128 <listitem>
8129 <simpara>
8130 <link linkend="WesleyTerpstra">WesleyTerpstra</link>
8131 </simpara>
8132 </listitem>
8133 <listitem>
8134 <simpara>
8135 <link linkend="VesaKarvonen">VesaKarvonen</link>
8136 </simpara>
8137 </listitem>
8138 </itemizedlist>
8139 <simpara><?asciidoc-pagebreak?></simpara>
8140 </section>
8141 </section>
8142 <section id="Development">
8143 <title>Development</title>
8144 <simpara>This page is the central point for MLton development.</simpara>
8145 <itemizedlist>
8146 <listitem>
8147 <simpara>
8148 Access the <link linkend="Sources">Sources</link>.
8149 </simpara>
8150 </listitem>
8151 <listitem>
8152 <simpara>
8153 Check the current <ulink url="https://github.com/MLton/mlton/blob/master/CHANGELOG.adoc"><literal>CHANGELOG.adoc</literal></ulink> or recent <ulink url="https://github.com/MLton/mlton/commits/master">commits</ulink>.
8154 </simpara>
8155 </listitem>
8156 <listitem>
8157 <simpara>
8158 Open <ulink url="https://github.com/MLton/mlton/issues">Issues</ulink>.
8159 </simpara>
8160 </listitem>
8161 <listitem>
8162 <simpara>
8163 Ideas for <link linkend="Projects">Projects</link> to improve MLton.
8164 </simpara>
8165 </listitem>
8166 <listitem>
8167 <simpara>
8168 <link linkend="Developers">Developers</link> that are or have been involved in the project.
8169 </simpara>
8170 </listitem>
8171 </itemizedlist>
8172 <section id="_notes">
8173 <title>Notes</title>
8174 <itemizedlist>
8175 <listitem>
8176 <simpara>
8177 <link linkend="CompilerOverview">CompilerOverview</link>
8178 </simpara>
8179 </listitem>
8180 <listitem>
8181 <simpara>
8182 <link linkend="CompilingWithSMLNJ">CompilingWithSMLNJ</link>
8183 </simpara>
8184 </listitem>
8185 <listitem>
8186 <simpara>
8187 <link linkend="CrossCompiling">CrossCompiling</link>
8188 </simpara>
8189 </listitem>
8190 <listitem>
8191 <simpara>
8192 <link linkend="License">License</link>
8193 </simpara>
8194 </listitem>
8195 <listitem>
8196 <simpara>
8197 <link linkend="NeedsReview">NeedsReview</link>
8198 </simpara>
8199 </listitem>
8200 <listitem>
8201 <simpara>
8202 <link linkend="PortingMLton">PortingMLton</link>
8203 </simpara>
8204 </listitem>
8205 <listitem>
8206 <simpara>
8207 <link linkend="ReleaseChecklist">ReleaseChecklist</link>
8208 </simpara>
8209 </listitem>
8210 <listitem>
8211 <simpara>
8212 <link linkend="SelfCompiling">SelfCompiling</link>
8213 </simpara>
8214 </listitem>
8215 </itemizedlist>
8216 <simpara><?asciidoc-pagebreak?></simpara>
8217 </section>
8218 </section>
8219 <section id="Documentation">
8220 <title>Documentation</title>
8221 <simpara>Documentation is available on the following topics.</simpara>
8222 <itemizedlist>
8223 <listitem>
8224 <simpara>
8225 <link linkend="StandardML">Standard ML</link>
8226 </simpara>
8227 <itemizedlist>
8228 <listitem>
8229 <simpara>
8230 <link linkend="BasisLibrary">Basis Library</link>
8231 </simpara>
8232 </listitem>
8233 <listitem>
8234 <simpara>
8235 <link linkend="Libraries">Additional libraries</link>
8236 </simpara>
8237 </listitem>
8238 </itemizedlist>
8239 </listitem>
8240 <listitem>
8241 <simpara>
8242 <link linkend="Installation">Installing MLton</link>
8243 </simpara>
8244 </listitem>
8245 <listitem>
8246 <simpara>
8247 Using MLton
8248 </simpara>
8249 <itemizedlist>
8250 <listitem>
8251 <simpara>
8252 <link linkend="ForeignFunctionInterface">Foreign function interface (FFI)</link>
8253 </simpara>
8254 </listitem>
8255 <listitem>
8256 <simpara>
8257 <link linkend="ManualPage">Manual page</link> (<link linkend="CompileTimeOptions">compile-time options</link> <link linkend="RunTimeOptions">run-time options</link>)
8258 </simpara>
8259 </listitem>
8260 <listitem>
8261 <simpara>
8262 <link linkend="MLBasis">ML Basis system</link>
8263 </simpara>
8264 </listitem>
8265 <listitem>
8266 <simpara>
8267 <link linkend="MLtonStructure">MLton structure</link>
8268 </simpara>
8269 </listitem>
8270 <listitem>
8271 <simpara>
8272 <link linkend="PlatformSpecificNotes">Platform-specific notes</link>
8273 </simpara>
8274 </listitem>
8275 <listitem>
8276 <simpara>
8277 <link linkend="Profiling">Profiling</link>
8278 </simpara>
8279 </listitem>
8280 <listitem>
8281 <simpara>
8282 <link linkend="TypeChecking">Type checking</link>
8283 </simpara>
8284 </listitem>
8285 <listitem>
8286 <simpara>
8287 Help for porting from <link linkend="SMLNJ">SML/NJ</link> to MLton.
8288 </simpara>
8289 </listitem>
8290 </itemizedlist>
8291 </listitem>
8292 <listitem>
8293 <simpara>
8294 About MLton
8295 </simpara>
8296 <itemizedlist>
8297 <listitem>
8298 <simpara>
8299 <link linkend="Credits">Credits</link>
8300 </simpara>
8301 </listitem>
8302 <listitem>
8303 <simpara>
8304 <link linkend="Drawbacks">Drawbacks</link>
8305 </simpara>
8306 </listitem>
8307 <listitem>
8308 <simpara>
8309 <link linkend="Features">Features</link>
8310 </simpara>
8311 </listitem>
8312 <listitem>
8313 <simpara>
8314 <link linkend="History">History</link>
8315 </simpara>
8316 </listitem>
8317 <listitem>
8318 <simpara>
8319 <link linkend="License">License</link>
8320 </simpara>
8321 </listitem>
8322 <listitem>
8323 <simpara>
8324 <link linkend="Talk">Talk</link>
8325 </simpara>
8326 </listitem>
8327 <listitem>
8328 <simpara>
8329 <link linkend="WishList">WishList</link>
8330 </simpara>
8331 </listitem>
8332 </itemizedlist>
8333 </listitem>
8334 <listitem>
8335 <simpara>
8336 Tools
8337 </simpara>
8338 <itemizedlist>
8339 <listitem>
8340 <simpara>
8341 <link linkend="MLLex">MLLex</link> (<ulink url="guide/Documentation.attachments/mllex.pdf"><literal>mllex.pdf</literal></ulink>)
8342 </simpara>
8343 </listitem>
8344 <listitem>
8345 <simpara>
8346 <link linkend="MLYacc">MLYacc</link> (<ulink url="guide/Documentation.attachments/mlyacc.pdf"><literal>mlyacc.pdf</literal></ulink>)
8347 </simpara>
8348 </listitem>
8349 <listitem>
8350 <simpara>
8351 <link linkend="MLNLFFIGen">MLNLFFIGen</link> (<ulink url="guide/Documentation.attachments/mlyacc.pdf"><literal>mlyacc.pdf</literal></ulink>)
8352 </simpara>
8353 </listitem>
8354 </itemizedlist>
8355 </listitem>
8356 <listitem>
8357 <simpara>
8358 <link linkend="References">References</link>
8359 </simpara>
8360 </listitem>
8361 </itemizedlist>
8362 <simpara><?asciidoc-pagebreak?></simpara>
8363 </section>
8364 <section id="Drawbacks">
8365 <title>Drawbacks</title>
8366 <simpara>MLton has several drawbacks due to its use of whole-program
8367 compilation.</simpara>
8368 <itemizedlist>
8369 <listitem>
8370 <simpara>
8371 Large compile-time memory requirement.
8372 </simpara>
8373 <simpara>Because MLton performs whole-program analysis and optimization,
8374 compilation requires a large amount of memory. For example, compiling
8375 MLton (over 140K lines) requires at least 512M RAM.</simpara>
8376 </listitem>
8377 <listitem>
8378 <simpara>
8379 Long compile times.
8380 </simpara>
8381 <simpara>Whole-program compilation can take a long time. For example,
8382 compiling MLton (over 140K lines) on a 1.6GHz machine takes five to
8383 ten minutes.</simpara>
8384 </listitem>
8385 <listitem>
8386 <simpara>
8387 No interactive top level.
8388 </simpara>
8389 <simpara>Because of whole-program compilation, MLton does not provide an
8390 interactive top level. In particular, it does not implement the
8391 optional <link linkend="BasisLibrary">Basis Library</link> function <literal>use</literal>.</simpara>
8392 </listitem>
8393 </itemizedlist>
8394 <simpara><?asciidoc-pagebreak?></simpara>
8395 </section>
8396 <section id="Eclipse">
8397 <title>Eclipse</title>
8398 <simpara><ulink url="http://eclipse.org/">Eclipse</ulink> is an open, extensible IDE.</simpara>
8399 <simpara><ulink url="http://www.cse.iitd.ernet.in/%7Ecsu02132/mldev/">ML-Dev</ulink> is a plug-in
8400 for Eclipse, based on <link linkend="SMLNJ">SML/NJ</link>.</simpara>
8401 <simpara>There has been some talk on the MLton mailing list about adding
8402 support to Eclipse for MLton/SML, and in particular, using
8403 <ulink url="http://eclipsefp.sourceforge.net/">http://eclipsefp.sourceforge.net/</ulink>. We are unaware of any progress
8404 along those lines.</simpara>
8405 <simpara><?asciidoc-pagebreak?></simpara>
8406 </section>
8407 <section id="Elaborate">
8408 <title>Elaborate</title>
8409 <simpara><link linkend="Elaborate">Elaborate</link> is a translation pass from the <link linkend="AST">AST</link>
8410 <link linkend="IntermediateLanguage">IntermediateLanguage</link> to the <link linkend="CoreML">CoreML</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>.</simpara>
8411 <section id="_description_16">
8412 <title>Description</title>
8413 <simpara>This pass performs type inference and type checking according to the
8414 <link linkend="DefinitionOfStandardML">Definition</link>. It also defunctorizes the
8415 program, eliminating all module-level constructs.</simpara>
8416 </section>
8417 <section id="_implementation_18">
8418 <title>Implementation</title>
8419 <itemizedlist>
8420 <listitem>
8421 <simpara>
8422 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/elaborate.sig"><literal>elaborate.sig</literal></ulink>
8423 </simpara>
8424 </listitem>
8425 <listitem>
8426 <simpara>
8427 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/elaborate.fun"><literal>elaborate.fun</literal></ulink>
8428 </simpara>
8429 </listitem>
8430 <listitem>
8431 <simpara>
8432 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/elaborate-env.sig"><literal>elaborate-env.sig</literal></ulink>
8433 </simpara>
8434 </listitem>
8435 <listitem>
8436 <simpara>
8437 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/elaborate-env.fun"><literal>elaborate-env.fun</literal></ulink>
8438 </simpara>
8439 </listitem>
8440 <listitem>
8441 <simpara>
8442 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/elaborate-modules.sig"><literal>elaborate-modules.sig</literal></ulink>
8443 </simpara>
8444 </listitem>
8445 <listitem>
8446 <simpara>
8447 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/elaborate-modules.fun"><literal>elaborate-modules.fun</literal></ulink>
8448 </simpara>
8449 </listitem>
8450 <listitem>
8451 <simpara>
8452 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/elaborate-core.sig"><literal>elaborate-core.sig</literal></ulink>
8453 </simpara>
8454 </listitem>
8455 <listitem>
8456 <simpara>
8457 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/elaborate-core.fun"><literal>elaborate-core.fun</literal></ulink>
8458 </simpara>
8459 </listitem>
8460 <listitem>
8461 <simpara>
8462 <ulink url="https://github.com/MLton/mlton/tree/master/mlton/elaborate"><literal>elaborate</literal></ulink>
8463 </simpara>
8464 </listitem>
8465 </itemizedlist>
8466 </section>
8467 <section id="_details_and_notes_18">
8468 <title>Details and Notes</title>
8469 <simpara>At the modules level, the <link linkend="Elaborate">Elaborate</link> pass:</simpara>
8470 <itemizedlist>
8471 <listitem>
8472 <simpara>
8473 elaborates signatures with interfaces (see
8474 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/interface.sig"><literal>interface.sig</literal></ulink> and
8475 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/interface.fun"><literal>interface.fun</literal></ulink>)
8476 </simpara>
8477 <simpara>The main trick is to use disjoint sets to efficiently handle sharing
8478 of tycons and of structures and then to copy signatures as dags rather
8479 than as trees.</simpara>
8480 </listitem>
8481 <listitem>
8482 <simpara>
8483 checks functors at the point of definition, using functor summaries
8484 to speed up checking of functor applications.
8485 </simpara>
8486 <simpara>When a functor is first type checked, we keep track of the dummy
8487 argument structure and the dummy result structure, as well as all the
8488 tycons that were created while elaborating the body. Then, if we
8489 later need to type check an application of the functor (as opposed to
8490 defunctorize an application), we pair up tycons in the dummy argument
8491 structure with the actual argument structure and then replace the
8492 dummy tycons with the actual tycons in the dummy result structure,
8493 yielding the actual result structure. We also generate new tycons for
8494 all the tycons that we created while originally elaborating the body.</simpara>
8495 </listitem>
8496 <listitem>
8497 <simpara>
8498 handles opaque signature constraints.
8499 </simpara>
8500 <simpara>This is implemented by building a dummy structure realized from the
8501 signature, just as we would for a functor argument when type checking
8502 a functor. The dummy structure contains exactly the type information
8503 that is in the signature, which is what opacity requires. We then
8504 replace the variables (and constructors) in the dummy structure with
8505 the corresponding variables (and constructors) from the actual
8506 structure so that the translation to <link linkend="CoreML">CoreML</link> uses the right stuff.
8507 For each tycon in the dummy structure, we keep track of the
8508 corresponding type structure in the actual structure. This is used
8509 when producing the <link linkend="CoreML">CoreML</link> types (see <literal>expandOpaque</literal> in
8510 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/type-env.sig"><literal>type-env.sig</literal></ulink> and
8511 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/type-env.fun"><literal>type-env.fun</literal></ulink>).</simpara>
8512 <simpara>Then, within each <literal>structure</literal> or <literal>functor</literal> body, for each declaration
8513 (<literal>&lt;dec&gt;</literal> in the <link linkend="StandardML">Standard ML</link> grammar), the <link linkend="Elaborate">Elaborate</link>
8514 pass does three steps:</simpara>
8515 <orderedlist numeration="arabic">
8516 <listitem>
8517 <simpara>
8518 <link linkend="ScopeInference">ScopeInference</link>
8519 </simpara>
8520 </listitem>
8521 <listitem>
8522 <simpara>
8523 </simpara>
8524 <itemizedlist>
8525 <listitem>
8526 <simpara>
8527 <link linkend="PrecedenceParse">PrecedenceParse</link>
8528 </simpara>
8529 </listitem>
8530 <listitem>
8531 <simpara>
8532 <literal>_{ex,im}port</literal> expansion
8533 </simpara>
8534 </listitem>
8535 <listitem>
8536 <simpara>
8537 profiling insertion
8538 </simpara>
8539 </listitem>
8540 <listitem>
8541 <simpara>
8542 unification
8543 </simpara>
8544 </listitem>
8545 </itemizedlist>
8546 </listitem>
8547 <listitem>
8548 <simpara>
8549 Overloaded {constant, function, record pattern} resolution
8550 </simpara>
8551 </listitem>
8552 </orderedlist>
8553 </listitem>
8554 </itemizedlist>
8555 <section id="_defunctorization">
8556 <title>Defunctorization</title>
8557 <simpara>The <link linkend="Elaborate">Elaborate</link> pass performs a number of duties historically
8558 assigned to the <link linkend="Defunctorize">Defunctorize</link> pass.</simpara>
8559 <simpara>As part of the <link linkend="Elaborate">Elaborate</link> pass, all module level constructs
8560 (<literal>open</literal>, <literal>signature</literal>, <literal>structure</literal>, <literal>functor</literal>, long identifiers) are
8561 removed. This works because the <link linkend="Elaborate">Elaborate</link> pass assigns a unique
8562 name to every type and variable in the program. This also allows the
8563 <link linkend="Elaborate">Elaborate</link> pass to eliminate <literal>local</literal> declarations, which are purely
8564 for namespace management.</simpara>
8565 </section>
8566 </section>
8567 <section id="_examples">
8568 <title>Examples</title>
8569 <simpara>Here are a number of examples of elaboration.</simpara>
8570 <itemizedlist>
8571 <listitem>
8572 <simpara>
8573 All variables bound in <literal>val</literal> declarations are renamed.
8574 </simpara>
8575 <programlisting language="sml" linenumbering="unnumbered">val x = 13
8576 val y = x</programlisting>
8577 <screen>val x_0 = 13
8578 val y_0 = x_0</screen>
8579 </listitem>
8580 <listitem>
8581 <simpara>
8582 All variables in <literal>fun</literal> declarations are renamed.
8583 </simpara>
8584 <programlisting language="sml" linenumbering="unnumbered">fun f x = g x
8585 and g y = f y</programlisting>
8586 <screen>fun f_0 x_0 = g_0 x_0
8587 and g_0 y_0 = f_0 y_0</screen>
8588 </listitem>
8589 <listitem>
8590 <simpara>
8591 Type abbreviations are removed, and the abbreviation is expanded
8592 wherever it is used.
8593 </simpara>
8594 <programlisting language="sml" linenumbering="unnumbered">type 'a u = int * 'a
8595 type 'b t = 'b u * real
8596 fun f (x : bool t) = x</programlisting>
8597 <screen>fun f_0 (x_0 : (int * bool) * real) = x_0</screen>
8598 </listitem>
8599 <listitem>
8600 <simpara>
8601 Exception declarations create a new constructor and rename the type.
8602 </simpara>
8603 <programlisting language="sml" linenumbering="unnumbered">type t = int
8604 exception E of t * real</programlisting>
8605 <screen>exception E_0 of int * real</screen>
8606 </listitem>
8607 <listitem>
8608 <simpara>
8609 The type and value constructors in datatype declarations are renamed.
8610 </simpara>
8611 <programlisting language="sml" linenumbering="unnumbered">datatype t = A of int | B of real * t</programlisting>
8612 <screen>datatype t_0 = A_0 of int | B_0 of real * t_0</screen>
8613 </listitem>
8614 <listitem>
8615 <simpara>
8616 Local declarations are moved to the top-level. The environment
8617 keeps track of the variables in scope.
8618 </simpara>
8619 <programlisting language="sml" linenumbering="unnumbered">val x = 13
8620 local val x = 14
8621 in val y = x
8622 end
8623 val z = x</programlisting>
8624 <screen>val x_0 = 13
8625 val x_1 = 14
8626 val y_0 = x_1
8627 val z_0 = x_0</screen>
8628 </listitem>
8629 <listitem>
8630 <simpara>
8631 Structure declarations are eliminated, with all declarations moved
8632 to the top level. Long identifiers are renamed.
8633 </simpara>
8634 <programlisting language="sml" linenumbering="unnumbered">structure S =
8635 struct
8636 type t = int
8637 val x : t = 13
8638 end
8639 val y : S.t = S.x</programlisting>
8640 <screen>val x_0 : int = 13
8641 val y_0 : int = x_0</screen>
8642 </listitem>
8643 <listitem>
8644 <simpara>
8645 Open declarations are eliminated.
8646 </simpara>
8647 <programlisting language="sml" linenumbering="unnumbered">val x = 13
8648 val y = 14
8649 structure S =
8650 struct
8651 val x = 15
8652 end
8653 open S
8654 val z = x + y</programlisting>
8655 <screen>val x_0 = 13
8656 val y_0 = 14
8657 val x_1 = 15
8658 val z_0 = x_1 + y_0</screen>
8659 </listitem>
8660 <listitem>
8661 <simpara>
8662 Functor declarations are eliminated, and the body of a functor is
8663 duplicated wherever the functor is applied.
8664 </simpara>
8665 <programlisting language="sml" linenumbering="unnumbered">functor F(val x : int) =
8666 struct
8667 val y = x
8668 end
8669 structure F1 = F(val x = 13)
8670 structure F2 = F(val x = 14)
8671 val z = F1.y + F2.y</programlisting>
8672 <screen>val x_0 = 13
8673 val y_0 = x_0
8674 val x_1 = 14
8675 val y_1 = x_1
8676 val z_0 = y_0 + y_1</screen>
8677 </listitem>
8678 <listitem>
8679 <simpara>
8680 Signature constraints are eliminated. Note that signatures do
8681 affect how subsequent variables are renamed.
8682 </simpara>
8683 <programlisting language="sml" linenumbering="unnumbered">val y = 13
8684 structure S : sig
8685 val x : int
8686 end =
8687 struct
8688 val x = 14
8689 val y = x
8690 end
8691 open S
8692 val z = x + y</programlisting>
8693 <screen>val y_0 = 13
8694 val x_0 = 14
8695 val y_1 = x_0
8696 val z_0 = x_0 + y_0</screen>
8697 </listitem>
8698 </itemizedlist>
8699 <simpara><?asciidoc-pagebreak?></simpara>
8700 </section>
8701 </section>
8702 <section id="Emacs">
8703 <title>Emacs</title>
8704 <section id="_sml_modes">
8705 <title>SML modes</title>
8706 <simpara>There are a few Emacs modes for SML.</simpara>
8707 <itemizedlist>
8708 <listitem>
8709 <simpara>
8710 <literal>sml-mode</literal>
8711 </simpara>
8712 <itemizedlist>
8713 <listitem>
8714 <simpara>
8715 <ulink url="http://www.xemacs.org/Documentation/packages/html/sml-mode_3.html">http://www.xemacs.org/Documentation/packages/html/sml-mode_3.html</ulink>
8716 </simpara>
8717 </listitem>
8718 <listitem>
8719 <simpara>
8720 <ulink url="http://www.smlnj.org/doc/Emacs/sml-mode.html">http://www.smlnj.org/doc/Emacs/sml-mode.html</ulink>
8721 </simpara>
8722 </listitem>
8723 <listitem>
8724 <simpara>
8725 <ulink url="http://www.iro.umontreal.ca/%7Emonnier/elisp/">http://www.iro.umontreal.ca/%7Emonnier/elisp/</ulink>
8726 </simpara>
8727 </listitem>
8728 </itemizedlist>
8729 </listitem>
8730 <listitem>
8731 <simpara>
8732 <ulink url="https://github.com/MLton/mlton/blob/master/ide/emacs/mlton.el"><literal>mlton.el</literal></ulink> contains the Emacs lisp that <link linkend="StephenWeeks">StephenWeeks</link> uses to interact with MLton (in addition to using <literal>sml-mode</literal>).
8733 </simpara>
8734 </listitem>
8735 <listitem>
8736 <simpara>
8737 <ulink url="http://primate.net/%7Eitz/mindent.tar">http://primate.net/%7Eitz/mindent.tar</ulink>, developed by Ian Zimmerman, who writes:
8738 </simpara>
8739 <blockquote>
8740 <simpara>Unlike the widespread <literal>sml-mode.el</literal> it doesn&#8217;t try to indent code
8741 based on ML syntax. I gradually got skeptical about this approach
8742 after writing the initial indentation support for caml mode and
8743 watching it bloat insanely as the language added new features. Also,
8744 any such attempts that I know of impose a particular coding style, or
8745 at best a choice among a limited set of styles, which I now oppose.
8746 Instead my mode is based on a generic package which provides manual
8747 bindable commands for common indentation operations (example: indent
8748 the current line under the n-th occurrence of a particular character
8749 in the previous non-blank line).</simpara>
8750 </blockquote>
8751 </listitem>
8752 </itemizedlist>
8753 </section>
8754 <section id="_mlb_modes">
8755 <title>MLB modes</title>
8756 <simpara>There is a mode for editing <link linkend="MLBasis">ML Basis</link> files.</simpara>
8757 <itemizedlist>
8758 <listitem>
8759 <simpara>
8760 <ulink url="https://github.com/MLton/mlton/blob/master/ide/emacs/esml-mlb-mode.el"><literal>esml-mlb-mode.el</literal></ulink> (plus other files)
8761 </simpara>
8762 </listitem>
8763 </itemizedlist>
8764 </section>
8765 <section id="_definitions_and_uses">
8766 <title>Definitions and uses</title>
8767 <simpara>There is a mode that supports the precise def-use information that
8768 MLton can output. It highlights definitions and uses and provides
8769 commands for navigation (e.g., <literal>jump-to-def</literal>, <literal>jump-to-next</literal>,
8770 <literal>list-all-refs</literal>). It can be handy, for example, for navigating in the
8771 MLton compiler source code. See <link linkend="EmacsDefUseMode">EmacsDefUseMode</link> for further
8772 information.</simpara>
8773 </section>
8774 <section id="_building_on_the_background">
8775 <title>Building on the background</title>
8776 <simpara>Tired of manually starting/stopping/restarting builds after editing
8777 files? Now you don&#8217;t have to. See <link linkend="EmacsBgBuildMode">EmacsBgBuildMode</link> for further
8778 information.</simpara>
8779 </section>
8780 <section id="_error_messages">
8781 <title>Error messages</title>
8782 <simpara>MLton&#8217;s error messages are not among those that the Emacs <literal>next-error</literal>
8783 parser natively understands. The easiest way to fix this is to add
8784 the following to your <literal>.emacs</literal> to teach Emacs to recognize MLton&#8217;s
8785 error messages.</simpara>
8786 <programlisting language="cl" linenumbering="unnumbered">(require 'compile)
8787 (add-to-list 'compilation-error-regexp-alist 'mlton)
8788 (add-to-list 'compilation-error-regexp-alist-alist
8789 '(mlton
8790 "^[[:space:]]*\\(\\(?:\\(Error\\)\\|\\(Warning\\)\\|\\(\\(?:\\(?:defn\\|spec\\) at\\)\\|\\(?:escape \\(?:from\\|to\\)\\)\\|\\(?:scoped at\\)\\)\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\(?:-\\([0-9]+\\)\\.\\([0-9]+\\)\\)?\\.?\\)$"
8791 5 (6 . 8) (7 . 9) (3 . 4) 1))</programlisting>
8792 <simpara><?asciidoc-pagebreak?></simpara>
8793 </section>
8794 </section>
8795 <section id="EmacsBgBuildMode">
8796 <title>EmacsBgBuildMode</title>
8797 <simpara>Do you really want to think about starting a build of you project?
8798 What if you had a personal slave that would restart a build of your
8799 project whenever you save any file belonging to that project? The
8800 bg-build mode does just that. Just save the file, a compile is
8801 started (silently!), you can continue working without even thinking
8802 about starting a build, and if there are errors, you are notified
8803 (with a message), and can then jump to errors.</simpara>
8804 <simpara>This mode is not specific to MLton per se, but is particularly useful
8805 for working with MLton due to the longer compile times. By the time
8806 you start wondering about possible errors, the build is already on the
8807 way.</simpara>
8808 <section id="_functionality_and_features">
8809 <title>Functionality and Features</title>
8810 <itemizedlist>
8811 <listitem>
8812 <simpara>
8813 Each time a file is saved, and after a user configurable delay
8814 period has been exhausted, a build is started silently in the
8815 background.
8816 </simpara>
8817 </listitem>
8818 <listitem>
8819 <simpara>
8820 When the build is finished, a status indicator (message) is
8821 displayed non-intrusively.
8822 </simpara>
8823 </listitem>
8824 <listitem>
8825 <simpara>
8826 At any time, you can switch to a build process buffer where all the
8827 messages from the build are shown.
8828 </simpara>
8829 </listitem>
8830 <listitem>
8831 <simpara>
8832 Optionally highlights (error/warning) message locations in (source
8833 code) buffers after a finished build.
8834 </simpara>
8835 </listitem>
8836 <listitem>
8837 <simpara>
8838 After a build has finished, you can jump to locations of warnings
8839 and errors from the build process buffer or by using the <literal>first-error</literal>
8840 and <literal>next-error</literal> commands.
8841 </simpara>
8842 </listitem>
8843 <listitem>
8844 <simpara>
8845 When a build fails, bg-build mode can optionally execute a user
8846 specified command. By default, bg-build mode executes <literal>first-error</literal>.
8847 </simpara>
8848 </listitem>
8849 <listitem>
8850 <simpara>
8851 When starting a build of a particular project, a possible previous
8852 live build of the same project is interrupted first.
8853 </simpara>
8854 </listitem>
8855 <listitem>
8856 <simpara>
8857 A project configuration file specifies the commands required to
8858 build a project.
8859 </simpara>
8860 </listitem>
8861 <listitem>
8862 <simpara>
8863 Multiple projects can be loaded into bg-build mode and bg-build mode
8864 can build a given maximum number of projects concurrently.
8865 </simpara>
8866 </listitem>
8867 <listitem>
8868 <simpara>
8869 Supports both <ulink url="http://www.gnu.org/software/emacs/">Gnu Emacs</ulink> and
8870 <ulink url="http://www.xemacs.org">XEmacs</ulink>.
8871 </simpara>
8872 </listitem>
8873 </itemizedlist>
8874 </section>
8875 <section id="_download_4">
8876 <title>Download</title>
8877 <simpara>There is no package for the mode at the moment. To install the mode you
8878 need to fetch the Emacs Lisp, <literal>*.el</literal>, files from the MLton repository:
8879 <ulink url="https://github.com/MLton/mlton/tree/master/ide/emacs"><literal>emacs</literal></ulink>.</simpara>
8880 </section>
8881 <section id="_setup">
8882 <title>Setup</title>
8883 <simpara>The easiest way to load the mode is to first tell Emacs where to find the
8884 files. For example, add</simpara>
8885 <programlisting language="cl" linenumbering="unnumbered">(add-to-list 'load-path (file-truename "path-to-the-el-files"))</programlisting>
8886 <simpara>to your <literal>~/.emacs</literal> or <literal>~/.xemacs/init.el</literal>. You&#8217;ll probably also want
8887 to start the mode automatically by adding</simpara>
8888 <programlisting language="cl" linenumbering="unnumbered">(require 'bg-build-mode)
8889 (bg-build-mode)</programlisting>
8890 <simpara>to your Emacs init file. Once the mode is activated, you should see
8891 the <literal>BGB</literal> indicator on the mode line.</simpara>
8892 <section id="_mlton_and_compilation_mode">
8893 <title>MLton and Compilation-Mode</title>
8894 <simpara>At the time of writing, neither Gnu Emacs nor XEmacs contain an error
8895 regexp that would match MLton&#8217;s messages.</simpara>
8896 <simpara>If you use Gnu Emacs, insert the following code into your <literal>.emacs</literal> file:</simpara>
8897 <programlisting language="cl" linenumbering="unnumbered">(require 'compile)
8898 (add-to-list
8899 'compilation-error-regexp-alist
8900 '("^\\(Warning\\|Error\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\.$"
8901 2 3 4))</programlisting>
8902 <simpara>If you use XEmacs, insert the following code into your <literal>init.el</literal> file:</simpara>
8903 <programlisting language="cl" linenumbering="unnumbered">(require 'compile)
8904 (add-to-list
8905 'compilation-error-regexp-alist-alist
8906 '(mlton
8907 ("^\\(Warning\\|Error\\): \\(.+\\) \\([0-9]+\\)\\.\\([0-9]+\\)\\.$"
8908 2 3 4)))
8909 (compilation-build-compilation-error-regexp-alist)</programlisting>
8910 </section>
8911 </section>
8912 <section id="_usage_3">
8913 <title>Usage</title>
8914 <simpara>Typically projects are built (or compiled) using a tool like <ulink url="http://www.gnu.org/software/make/"><literal>make</literal></ulink>,
8915 but the details vary. The bg-build mode needs a project configuration file to
8916 know how to build your project. A project configuration file basically contains
8917 an Emacs Lisp expression calling a function named <literal>bg-build</literal> that returns a
8918 project object. A simple example of a project configuration file would be the
8919 (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/async/unstable/example/smlbot/Build.bgb"><literal>Build.bgb</literal></ulink>)
8920 file used with smlbot:</simpara>
8921 <programlisting language="cl" linenumbering="unnumbered">(bg-build
8922 :name "SML-Bot"
8923 :shell "nice -n5 make all")</programlisting>
8924 <simpara>The <literal>bg-build</literal> function takes a number of keyword arguments:</simpara>
8925 <itemizedlist>
8926 <listitem>
8927 <simpara>
8928 <literal>:name</literal> specifies the name of the project. This can be any
8929 expression that evaluates to a string or to a nullary function that
8930 returns a string.
8931 </simpara>
8932 </listitem>
8933 <listitem>
8934 <simpara>
8935 <literal>:shell</literal> specifies a shell command to execute. This can be any
8936 expression that evaluates to a string, a list of strings, or to a
8937 nullary function returning a list of strings.
8938 </simpara>
8939 </listitem>
8940 <listitem>
8941 <simpara>
8942 <literal>:build?</literal> specifies a predicate to determine whether the project
8943 should be built after some files have been modified. The predicate is
8944 given a list of filenames and should return a non-nil value when the
8945 project should be built and nil otherwise.
8946 </simpara>
8947 </listitem>
8948 </itemizedlist>
8949 <simpara>All of the keyword arguments, except <literal>:shell</literal>, are optional and can be left out.</simpara>
8950 <simpara>Note the use of the <literal>nice</literal> command above. It means that background
8951 build process is given a lower priority by the system process
8952 scheduler. Assuming your machine has enough memory, using nice
8953 ensures that your computer remains responsive. (You probably won&#8217;t
8954 even notice when a build is started.)</simpara>
8955 <simpara>Once you have written a project file for bg-build mode. Use the
8956 <literal>bg-build-add-project</literal> command to load the project file for bg-build
8957 mode. The bg-build mode can also optionally load recent project files
8958 automatically at startup.</simpara>
8959 <simpara>After the project file has been loaded and bg-build mode activated,
8960 each time you save a file in Emacs, the bg-build mode tries to build
8961 your project.</simpara>
8962 <simpara>The <literal>bg-build-status</literal> command creates a buffer that displays some
8963 status information on builds and allows you to manage projects (start
8964 builds explicitly, remove a project from bg-build, &#8230;) as well as
8965 visit buffers created by bg-build. Notice the count of started
8966 builds. At the end of the day it can be in the hundreds or thousands.
8967 Imagine the number of times you&#8217;ve been relieved of starting a build
8968 explicitly!</simpara>
8969 <simpara><?asciidoc-pagebreak?></simpara>
8970 </section>
8971 </section>
8972 <section id="EmacsDefUseMode">
8973 <title>EmacsDefUseMode</title>
8974 <simpara>MLton provides an <link linkend="CompileTimeOptions">option</link>,
8975 <literal>-show-def-use <emphasis>file</emphasis></literal>, to output precise (giving exact source
8976 locations) and accurate (including all uses and no false data)
8977 whole-program def-use information to a file. Unlike typical tags
8978 facilities, the information includes local variables and distinguishes
8979 between different definitions even when they have the same name. The
8980 def-use Emacs mode uses the information to provide navigation support,
8981 which can be particularly useful while reading SML programs compiled
8982 with MLton (such as the MLton compiler itself).</simpara>
8983 <section id="_screen_capture">
8984 <title>Screen Capture</title>
8985 <simpara>Note the highlighting and the type displayed in the minibuffer.</simpara>
8986 <informalfigure>
8987 <mediaobject>
8988 <imageobject>
8989 <imagedata fileref="EmacsDefUseMode.attachments/def-use-capture.png" align="center"/>
8990 </imageobject>
8991 <textobject><phrase>EmacsDefUseMode.attachments/def-use-capture.png</phrase></textobject>
8992 </mediaobject>
8993 </informalfigure>
8994 </section>
8995 <section id="_features">
8996 <title>Features</title>
8997 <itemizedlist>
8998 <listitem>
8999 <simpara>
9000 Highlights definitions and uses. Different colors for definitions, unused definitions, and uses.
9001 </simpara>
9002 </listitem>
9003 <listitem>
9004 <simpara>
9005 Shows types (with highlighting) of variable definitions in the minibuffer.
9006 </simpara>
9007 </listitem>
9008 <listitem>
9009 <simpara>
9010 Navigation: <literal>jump-to-def</literal>, <literal>jump-to-next</literal>, and <literal>jump-to-prev</literal>. These work precisely (no searching involved).
9011 </simpara>
9012 </listitem>
9013 <listitem>
9014 <simpara>
9015 Can list, visit and mark all references to a definition (within a program).
9016 </simpara>
9017 </listitem>
9018 <listitem>
9019 <simpara>
9020 Automatically reloads updated def-use files.
9021 </simpara>
9022 </listitem>
9023 <listitem>
9024 <simpara>
9025 Automatically loads previously used def-use files at startup.
9026 </simpara>
9027 </listitem>
9028 <listitem>
9029 <simpara>
9030 Supports both <ulink url="http://www.gnu.org/software/emacs/">Gnu Emacs</ulink> and <ulink url="http://www.xemacs.org">XEmacs</ulink>.
9031 </simpara>
9032 </listitem>
9033 </itemizedlist>
9034 </section>
9035 <section id="_download_5">
9036 <title>Download</title>
9037 <simpara>There is no separate package for the def-use mode although the mode
9038 has been relatively stable for some time already. To install the mode
9039 you need to get the Emacs Lisp, <literal>*.el</literal>, files from MLton&#8217;s repository:
9040 <ulink url="https://github.com/MLton/mlton/tree/master/ide/emacs"><literal>emacs</literal></ulink>. The easiest way to get the files
9041 is to use <link linkend="Git">Git</link> to access MLton&#8217;s <link linkend="Sources">sources</link>.</simpara>
9042 </section>
9043 <section id="_setup_2">
9044 <title>Setup</title>
9045 <simpara>The easiest way to load def-use mode is to first tell Emacs where to
9046 find the files. For example, add</simpara>
9047 <programlisting language="cl" linenumbering="unnumbered">(add-to-list 'load-path (file-truename "path-to-the-el-files"))</programlisting>
9048 <simpara>to your <literal>~/.emacs</literal> or <literal>~/.xemacs/init.el</literal>. You&#8217;ll probably
9049 also want to start <literal>def-use-mode</literal> automatically by adding</simpara>
9050 <programlisting language="cl" linenumbering="unnumbered">(require 'esml-du-mlton)
9051 (def-use-mode)</programlisting>
9052 <simpara>to your Emacs init file. Once the def-use mode is activated, you
9053 should see the <literal>DU</literal> indicator on the mode line.</simpara>
9054 </section>
9055 <section id="_usage_4">
9056 <title>Usage</title>
9057 <simpara>To use def-use mode one typically first sets up the program&#8217;s makefile
9058 or build script so that the def-use information is saved each time the
9059 program is compiled. In addition to the <literal>-show-def-use <emphasis>file</emphasis></literal>
9060 option, the <literal>-prefer-abs-paths true</literal> expert option is required.
9061 Note that the time it takes to save the information is small (compared
9062 to type-checking), so it is recommended to simply add the options to
9063 the MLton invocation that compiles the program. However, it is only
9064 necessary to type check the program (or library), so one can specify
9065 the <literal>-stop tc</literal> option. For example, suppose you have a program
9066 defined by an MLB file named <literal>my-prg.mlb</literal>, you can save the def-use
9067 information to the file <literal>my-prg.du</literal> by invoking MLton as:</simpara>
9068 <screen>mlton -prefer-abs-paths true -show-def-use my-prg.du -stop tc my-prg.mlb</screen>
9069 <simpara>Finally, one needs to tell the mode where to find the def-use
9070 information. This is done with the <literal>esml-du-mlton</literal> command. For
9071 example, to load the <literal>my-prg.du</literal> file, one would type:</simpara>
9072 <screen>M-x esml-du-mlton my-prg.du</screen>
9073 <simpara>After doing all of the above, find an SML file covered by the
9074 previously saved and loaded def-use information, and place the cursor
9075 at some variable (definition or use, it doesn&#8217;t matter). You should
9076 see the variable being highlighted. (Note that specifications in
9077 signatures do not define variables.)</simpara>
9078 <simpara>You might also want to setup and use the
9079 <link linkend="EmacsBgBuildMode">Bg-Build mode</link> to start builds automatically.</simpara>
9080 </section>
9081 <section id="_types">
9082 <title>Types</title>
9083 <simpara><literal>-show-def-use</literal> output was extended to include types of variable
9084 definitions in revision <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6333"><literal>r6333</literal></ulink>. To get good type names, the
9085 types must be in scope at the end of the program. If you are using the
9086 <link linkend="MLBasis">ML Basis</link> system, this means that the root MLB-file for your
9087 application should not wrap the libraries used in the application inside
9088 <literal>local ... in ... end</literal>, because that would remove them from the scope before
9089 the end of the program.</simpara>
9090 <simpara><?asciidoc-pagebreak?></simpara>
9091 </section>
9092 </section>
9093 <section id="Enscript">
9094 <title>Enscript</title>
9095 <simpara><ulink url="http://www.gnu.org/s/enscript/">GNU Enscript</ulink> converts ASCII files to
9096 PostScript, HTML, and other output languages, applying language
9097 sensitive highlighting (similar to <link linkend="Emacs">Emacs</link>'s font lock mode). Here
9098 are a few <emphasis>states</emphasis> files for highlighting <link linkend="StandardML">Standard ML</link>.</simpara>
9099 <itemizedlist>
9100 <listitem>
9101 <simpara>
9102 <ulink url="https://github.com/MLton/mlton/blob/master/ide/enscript/sml_simple.st"><literal>sml_simple.st</literal></ulink>&#8201;&#8212;&#8201;Provides highlighting of keywords, string and character constants, and (nested) comments.
9103 </simpara>
9104 </listitem>
9105 </itemizedlist>
9106 <itemizedlist>
9107 <listitem>
9108 <simpara>
9109 <ulink url="https://github.com/MLton/mlton/blob/master/ide/enscript/sml_verbose.st"><literal>sml_verbose.st</literal></ulink>&#8201;&#8212;&#8201;Supersedes
9110 the above, adding highlighting of numeric constants. Due to the
9111 limited parsing available, numeric record labels are highlighted as
9112 numeric constants, in all contexts. Likewise, a binding precedence
9113 separated from <literal>infix</literal> or <literal>infixr</literal> by a newline is highlighted as a
9114 numeric constant and a numeric record label selector separated from
9115 <literal>#</literal> by a newline is highlighted as a numeric constant.
9116 </simpara>
9117 </listitem>
9118 </itemizedlist>
9119 <itemizedlist>
9120 <listitem>
9121 <simpara>
9122 <ulink url="https://github.com/MLton/mlton/blob/master/ide/enscript/sml_fancy.st"><literal>sml_fancy.st</literal></ulink>&#8201;&#8212;&#8201;Supersedes the
9123 above, adding highlighting of type and constructor bindings,
9124 highlighting of explicit binding of type variables at <literal>val</literal> and <literal>fun</literal>
9125 declarations, and separate highlighting of core and modules level
9126 keywords. Due to the limited parsing available, it is assumed that
9127 the input is a syntactically correct, top-level declaration.
9128 </simpara>
9129 </listitem>
9130 </itemizedlist>
9131 <itemizedlist>
9132 <listitem>
9133 <simpara>
9134 <ulink url="https://github.com/MLton/mlton/blob/master/ide/enscript/sml_gaudy.st"><literal>sml_gaudy.st</literal></ulink>&#8201;&#8212;&#8201;Supersedes the
9135 above, adding highlighting of type annotations, in both expressions
9136 and signatures. Due to the limited parsing available, it is assumed
9137 that the input is a syntactically correct, top-level declaration.
9138 </simpara>
9139 </listitem>
9140 </itemizedlist>
9141 <section id="_install_and_use">
9142 <title>Install and use</title>
9143 <itemizedlist>
9144 <listitem>
9145 <simpara>
9146 Version 1.6.3 of <ulink url="http://people.ssh.com/mtr/genscript">GNU Enscript</ulink>
9147 </simpara>
9148 <itemizedlist>
9149 <listitem>
9150 <simpara>
9151 Copy all files to <literal>/usr/share/enscript/hl/</literal> or <literal>.enscript/</literal> in your home directory.
9152 </simpara>
9153 </listitem>
9154 <listitem>
9155 <simpara>
9156 Invoke <literal>enscript</literal> with <literal>--highlight=sml_simple</literal> (or <literal>--highlight=sml_verbose</literal> or <literal>--highlight=sml_fancy</literal> or <literal>--highlight=sml_gaudy</literal>).
9157 </simpara>
9158 </listitem>
9159 </itemizedlist>
9160 </listitem>
9161 <listitem>
9162 <simpara>
9163 Version 1.6.1 of <ulink url="http://people.ssh.com/mtr/genscript">GNU Enscript</ulink>
9164 </simpara>
9165 <itemizedlist>
9166 <listitem>
9167 <simpara>
9168 Append <ulink url="https://github.com/MLton/mlton/blob/master/ide/enscript/sml_all.st"><literal>sml_all.st</literal></ulink> to <literal>/usr/share/enscript/enscript.st</literal>
9169 </simpara>
9170 </listitem>
9171 <listitem>
9172 <simpara>
9173 Invoke <literal>enscript</literal> with <literal>--pretty-print=sml_simple</literal> (or <literal>--pretty-print=sml_verbose</literal> or <literal>--pretty-print=sml_fancy</literal> or <literal>--pretty-print=sml_gaudy</literal>).
9174 </simpara>
9175 </listitem>
9176 </itemizedlist>
9177 </listitem>
9178 </itemizedlist>
9179 </section>
9180 <section id="_feedback">
9181 <title>Feedback</title>
9182 <simpara>Comments and suggestions should be directed to <link linkend="MatthewFluet">MatthewFluet</link>.</simpara>
9183 <simpara><?asciidoc-pagebreak?></simpara>
9184 </section>
9185 </section>
9186 <section id="EqualityType">
9187 <title>EqualityType</title>
9188 <simpara>An equality type is a type to which <link linkend="PolymorphicEquality">PolymorphicEquality</link> can be
9189 applied. The <link linkend="DefinitionOfStandardML">Definition</link> and the
9190 <link linkend="BasisLibrary">Basis Library</link> precisely spell out which types are
9191 equality types.</simpara>
9192 <itemizedlist>
9193 <listitem>
9194 <simpara>
9195 <literal>bool</literal>, <literal>char</literal>, <literal>IntInf.int</literal>, <literal>Int<emphasis>&lt;N&gt;</emphasis>.int</literal>, <literal>string</literal>, and <literal>Word<emphasis>&lt;N&gt;</emphasis>.word</literal> are equality types.
9196 </simpara>
9197 </listitem>
9198 <listitem>
9199 <simpara>
9200 for any <literal>t</literal>, both <literal>t array</literal> and <literal>t ref</literal> are equality types.
9201 </simpara>
9202 </listitem>
9203 <listitem>
9204 <simpara>
9205 if <literal>t</literal> is an equality type, then <literal>t list</literal>, and <literal>t vector</literal> are equality types.
9206 </simpara>
9207 </listitem>
9208 <listitem>
9209 <simpara>
9210 if <literal>t1</literal>, &#8230;, <literal>tn</literal> are equality types, then <literal>t1 * ... * tn</literal> and <literal>{l1: t1, ..., ln: tn}</literal> are equality types.
9211 </simpara>
9212 </listitem>
9213 <listitem>
9214 <simpara>
9215 if <literal>t1</literal>, &#8230;, <literal>tn</literal> are equality types and <literal>t</literal> <link linkend="AdmitsEquality">AdmitsEquality</link>, then <literal>(t1, ..., tn) t</literal> is an equality type.
9216 </simpara>
9217 </listitem>
9218 </itemizedlist>
9219 <simpara>To check that a type t is an equality type, use the following idiom.</simpara>
9220 <programlisting language="sml" linenumbering="unnumbered">structure S: sig eqtype t end =
9221 struct
9222 type t = ...
9223 end</programlisting>
9224 <simpara>Notably, <literal>exn</literal> and <literal>real</literal> are not equality types. Neither is <literal>t1 -&gt; t2</literal>, for any <literal>t1</literal> and <literal>t2</literal>.</simpara>
9225 <simpara>Equality on arrays and ref cells is by identity, not structure.
9226 For example, <literal>ref 13 = ref 13</literal> is <literal>false</literal>.
9227 On the other hand, equality for lists, strings, and vectors is by
9228 structure, not identity. For example, the following equalities hold.</simpara>
9229 <programlisting language="sml" linenumbering="unnumbered">val _ = [1, 2, 3] = 1 :: [2, 3]
9230 val _ = "foo" = concat ["f", "o", "o"]
9231 val _ = Vector.fromList [1, 2, 3] = Vector.tabulate (3, fn i =&gt; i + 1)</programlisting>
9232 <simpara><?asciidoc-pagebreak?></simpara>
9233 </section>
9234 <section id="EqualityTypeVariable">
9235 <title>EqualityTypeVariable</title>
9236 <simpara>An equality type variable is a type variable that starts with two or
9237 more primes, as in <literal>''a</literal> or <literal>''b</literal>. The canonical use of equality type
9238 variables is in specifying the type of the <link linkend="PolymorphicEquality">PolymorphicEquality</link>
9239 function, which is <literal>''a * ''a -&gt; bool</literal>. Equality type variables
9240 ensure that polymorphic equality is only used on
9241 <link linkend="EqualityType">equality types</link>, by requiring that at every use of a
9242 polymorphic value, equality type variables are instantiated by
9243 equality types.</simpara>
9244 <simpara>For example, the following program is type correct because polymorphic
9245 equality is applied to variables of type <literal>''a</literal>.</simpara>
9246 <programlisting language="sml" linenumbering="unnumbered">fun f (x: ''a, y: ''a): bool = x = y</programlisting>
9247 <simpara>On the other hand, the following program is not type correct, because
9248 polymorphic equality is applied to variables of type <literal>'a</literal>, which is
9249 not an equality type.</simpara>
9250 <programlisting language="sml" linenumbering="unnumbered">fun f (x: 'a, y: 'a): bool = x = y</programlisting>
9251 <simpara>MLton reports the following error, indicating that polymorphic
9252 equality expects equality types, but didn&#8217;t get them.</simpara>
9253 <screen>Error: z.sml 1.30-1.34.
9254 Function applied to incorrect argument.
9255 expects: [&lt;equality&gt;] * [&lt;equality&gt;]
9256 but got: ['a] * ['a]
9257 in: = (x, y)</screen>
9258 <simpara>As an example of using such a function that requires equality types,
9259 suppose that <literal>f</literal> has polymorphic type <literal>''a -&gt; unit</literal>. Then, <literal>f 13</literal> is
9260 type correct because <literal>int</literal> is an equality type. On the other hand,
9261 <literal>f 13.0</literal> and <literal>f (fn x =&gt; x)</literal> are not type correct, because <literal>real</literal> and
9262 arrow types are not equality types. We can test these facts with the
9263 following short programs. First, we verify that such an <literal>f</literal> can be
9264 applied to integers.</simpara>
9265 <programlisting language="sml" linenumbering="unnumbered">functor Ok (val f: ''a -&gt; unit): sig end =
9266 struct
9267 val () = f 13
9268 val () = f 14
9269 end</programlisting>
9270 <simpara>We can do better, and verify that such an <literal>f</literal> can be applied to
9271 any integer.</simpara>
9272 <programlisting language="sml" linenumbering="unnumbered">functor Ok (val f: ''a -&gt; unit): sig end =
9273 struct
9274 fun g (x: int) = f x
9275 end</programlisting>
9276 <simpara>Even better, we don&#8217;t need to introduce a dummy function name; we can
9277 use a type constraint.</simpara>
9278 <programlisting language="sml" linenumbering="unnumbered">functor Ok (val f: ''a -&gt; unit): sig end =
9279 struct
9280 val _ = f: int -&gt; unit
9281 end</programlisting>
9282 <simpara>Even better, we can use a signature constraint.</simpara>
9283 <programlisting language="sml" linenumbering="unnumbered">functor Ok (S: sig val f: ''a -&gt; unit end):
9284 sig val f: int -&gt; unit end = S</programlisting>
9285 <simpara>This functor concisely verifies that a function of polymorphic type
9286 <literal>''a -&gt; unit</literal> can be safely used as a function of type <literal>int -&gt; unit</literal>.</simpara>
9287 <simpara>As above, we can verify that such an <literal>f</literal> can not be used at
9288 non-equality types.</simpara>
9289 <programlisting language="sml" linenumbering="unnumbered">functor Bad (S: sig val f: ''a -&gt; unit end):
9290 sig val f: real -&gt; unit end = S
9291
9292 functor Bad (S: sig val f: ''a -&gt; unit end):
9293 sig val f: ('a -&gt; 'a) -&gt; unit end = S</programlisting>
9294 <simpara>MLton reports the following errors.</simpara>
9295 <screen>Error: z.sml 2.4-2.30.
9296 Variable in structure disagrees with signature (type): f.
9297 structure: val f: [&lt;equality&gt;] -&gt; _
9298 defn at: z.sml 1.25-1.25
9299 signature: val f: [real] -&gt; _
9300 spec at: z.sml 2.12-2.12
9301 Error: z.sml 5.4-5.36.
9302 Variable in structure disagrees with signature (type): f.
9303 structure: val f: [&lt;equality&gt;] -&gt; _
9304 defn at: z.sml 4.25-4.25
9305 signature: val f: [_ -&gt; _] -&gt; _
9306 spec at: z.sml 5.12-5.12</screen>
9307 <section id="_equality_type_variables_in_type_and_datatype_declarations">
9308 <title>Equality type variables in type and datatype declarations</title>
9309 <simpara>Equality type variables can be used in type and datatype declarations;
9310 however they play no special role. For example,</simpara>
9311 <programlisting language="sml" linenumbering="unnumbered">type 'a t = 'a * int</programlisting>
9312 <simpara>is completely identical to</simpara>
9313 <programlisting language="sml" linenumbering="unnumbered">type ''a t = ''a * int</programlisting>
9314 <simpara>In particular, such a definition does <emphasis>not</emphasis> require that <literal>t</literal> only be
9315 applied to equality types.</simpara>
9316 <simpara>Similarly,</simpara>
9317 <programlisting language="sml" linenumbering="unnumbered">datatype 'a t = A | B of 'a</programlisting>
9318 <simpara>is completely identical to</simpara>
9319 <programlisting language="sml" linenumbering="unnumbered">datatype ''a t = A | B of ''a</programlisting>
9320 <simpara><?asciidoc-pagebreak?></simpara>
9321 </section>
9322 </section>
9323 <section id="EtaExpansion">
9324 <title>EtaExpansion</title>
9325 <simpara>Eta expansion is a simple syntactic change used to work around the
9326 <link linkend="ValueRestriction">ValueRestriction</link> in <link linkend="StandardML">Standard ML</link>.</simpara>
9327 <simpara>The eta expansion of an expression <literal>e</literal> is the expression
9328 <literal>fn z =&gt; e z</literal>, where <literal>z</literal> does not occur in <literal>e</literal>. This only
9329 makes sense if <literal>e</literal> denotes a function, i.e. is of arrow type. Eta
9330 expansion delays the evaluation of <literal>e</literal> until the function is
9331 applied, and will re-evaluate <literal>e</literal> each time the function is
9332 applied.</simpara>
9333 <simpara>The name "eta expansion" comes from the eta-conversion rule of the
9334 <link linkend="LambdaCalculus">lambda calculus</link>. Expansion refers to the
9335 directionality of the equivalence being used, namely taking <literal>e</literal> to
9336 <literal>fn z =&gt; e z</literal> rather than <literal>fn z =&gt; e z</literal> to <literal>e</literal> (eta
9337 contraction).</simpara>
9338 <simpara><?asciidoc-pagebreak?></simpara>
9339 </section>
9340 <section id="eXene">
9341 <title>eXene</title>
9342 <simpara><ulink url="http://people.cs.uchicago.edu/%7Ejhr/eXene/index.html">eXene</ulink> is a
9343 multi-threaded X Window System toolkit written in <link linkend="ConcurrentML">ConcurrentML</link>.</simpara>
9344 <simpara>There is a group at K-State working toward
9345 <ulink url="http://www.cis.ksu.edu/%7Estough/eXene/">eXene 2.0</ulink>.</simpara>
9346 <simpara><?asciidoc-pagebreak?></simpara>
9347 </section>
9348 <section id="FAQ">
9349 <title>FAQ</title>
9350 <simpara>Feel free to ask questions and to update answers by editing this page.
9351 Since we try to make as much information as possible available on the
9352 web site and we like to avoid duplication, many of the answers are
9353 simply links to a web page that answers the question.</simpara>
9354 <section id="_how_do_you_pronounce_mlton">
9355 <title>How do you pronounce MLton?</title>
9356 <simpara><link linkend="Pronounce">Pronounce</link></simpara>
9357 </section>
9358 <section id="_what_sml_software_has_been_ported_to_mlton">
9359 <title>What SML software has been ported to MLton?</title>
9360 <simpara><link linkend="Libraries">Libraries</link></simpara>
9361 </section>
9362 <section id="_what_graphical_libraries_are_available_for_mlton">
9363 <title>What graphical libraries are available for MLton?</title>
9364 <simpara><link linkend="Libraries">Libraries</link></simpara>
9365 </section>
9366 <section id="_how_does_mlton_8217_s_performance_compare_to_other_sml_compilers_and_to_other_languages">
9367 <title>How does MLton&#8217;s performance compare to other SML compilers and to other languages?</title>
9368 <simpara>MLton has <link linkend="Performance">excellent performance</link>.</simpara>
9369 </section>
9370 <section id="_does_mlton_treat_monomorphic_arrays_and_vectors_specially">
9371 <title>Does MLton treat monomorphic arrays and vectors specially?</title>
9372 <simpara>MLton implements monomorphic arrays and vectors (e.g. <literal>BoolArray</literal>,
9373 <literal>Word8Vector</literal>) exactly as instantiations of their polymorphic
9374 counterpart (e.g. <literal>bool array</literal>, <literal>Word8.word vector</literal>). Thus, there is
9375 no need to use the monomorphic versions except when required to
9376 interface with the <link linkend="BasisLibrary">Basis Library</link> or for portability
9377 with other SML implementations.</simpara>
9378 </section>
9379 <section id="_why_do_i_get_a_segfault_bus_error_in_a_program_that_uses_literal_intinf_literal_literal_largeint_literal_to_calculate_numbers_with_several_hundred_thousand_digits">
9380 <title>Why do I get a Segfault/Bus error in a program that uses <literal>IntInf</literal>/<literal>LargeInt</literal> to calculate numbers with several hundred thousand digits?</title>
9381 <simpara><link linkend="GnuMP">GnuMP</link></simpara>
9382 </section>
9383 <section id="_how_can_i_decrease_compile_time_memory_usage">
9384 <title>How can I decrease compile-time memory usage?</title>
9385 <itemizedlist>
9386 <listitem>
9387 <simpara>
9388 Compile with <literal>-verbose 3</literal> to find out if the problem is due to an
9389 SSA optimization pass. If so, compile with <literal>-disable-pass <emphasis>pass</emphasis></literal> to
9390 skip that pass.
9391 </simpara>
9392 </listitem>
9393 <listitem>
9394 <simpara>
9395 Compile with <literal>@MLton hash-cons 0.5 --</literal>, which will instruct the
9396 runtime to hash cons the heap every other GC.
9397 </simpara>
9398 </listitem>
9399 <listitem>
9400 <simpara>
9401 Compile with <literal>-polyvariance false</literal>, which is an undocumented option
9402 that causes less code duplication.
9403 </simpara>
9404 </listitem>
9405 </itemizedlist>
9406 <simpara>Also, please <link linkend="Contact">Contact</link> us to let us know the problem to help us
9407 better understand MLton&#8217;s limitations.</simpara>
9408 </section>
9409 <section id="_how_portable_is_sml_code_across_sml_compilers">
9410 <title>How portable is SML code across SML compilers?</title>
9411 <simpara><link linkend="StandardMLPortability">StandardMLPortability</link></simpara>
9412 <simpara><?asciidoc-pagebreak?></simpara>
9413 </section>
9414 </section>
9415 <section id="Features">
9416 <title>Features</title>
9417 <simpara>MLton has the following features.</simpara>
9418 <section id="_portability">
9419 <title>Portability</title>
9420 <itemizedlist>
9421 <listitem>
9422 <simpara>
9423 Runs on a variety of platforms.
9424 </simpara>
9425 <itemizedlist>
9426 <listitem>
9427 <simpara>
9428 <link linkend="RunningOnARM">ARM</link>:
9429 </simpara>
9430 <itemizedlist>
9431 <listitem>
9432 <simpara>
9433 <link linkend="RunningOnLinux">Linux</link> (Debian)
9434 </simpara>
9435 </listitem>
9436 </itemizedlist>
9437 </listitem>
9438 <listitem>
9439 <simpara>
9440 <link linkend="RunningOnAlpha">Alpha</link>:
9441 </simpara>
9442 <itemizedlist>
9443 <listitem>
9444 <simpara>
9445 <link linkend="RunningOnLinux">Linux</link> (Debian)
9446 </simpara>
9447 </listitem>
9448 </itemizedlist>
9449 </listitem>
9450 <listitem>
9451 <simpara>
9452 <link linkend="RunningOnAMD64">AMD64</link>:
9453 </simpara>
9454 <itemizedlist>
9455 <listitem>
9456 <simpara>
9457 <link linkend="RunningOnDarwin">Darwin</link> (Mac OS X)
9458 </simpara>
9459 </listitem>
9460 <listitem>
9461 <simpara>
9462 <link linkend="RunningOnFreeBSD">FreeBSD</link>
9463 </simpara>
9464 </listitem>
9465 <listitem>
9466 <simpara>
9467 <link linkend="RunningOnLinux">Linux</link> (Debian, Fedora, Ubuntu, &#8230;)
9468 </simpara>
9469 </listitem>
9470 <listitem>
9471 <simpara>
9472 <link linkend="RunningOnOpenBSD">OpenBSD</link>
9473 </simpara>
9474 </listitem>
9475 <listitem>
9476 <simpara>
9477 <link linkend="RunningOnSolaris">Solaris</link> (10 and above)
9478 </simpara>
9479 </listitem>
9480 </itemizedlist>
9481 </listitem>
9482 <listitem>
9483 <simpara>
9484 <link linkend="RunningOnHPPA">HPPA</link>:
9485 </simpara>
9486 <itemizedlist>
9487 <listitem>
9488 <simpara>
9489 <link linkend="RunningOnHPUX">HPUX</link> (11.11 and above)
9490 </simpara>
9491 </listitem>
9492 <listitem>
9493 <simpara>
9494 <link linkend="RunningOnLinux">Linux</link> (Debian)
9495 </simpara>
9496 </listitem>
9497 </itemizedlist>
9498 </listitem>
9499 <listitem>
9500 <simpara>
9501 <link linkend="RunningOnIA64">IA64</link>:
9502 </simpara>
9503 <itemizedlist>
9504 <listitem>
9505 <simpara>
9506 <link linkend="RunningOnHPUX">HPUX</link> (11.11 and above)
9507 </simpara>
9508 </listitem>
9509 <listitem>
9510 <simpara>
9511 <link linkend="RunningOnLinux">Linux</link> (Debian)
9512 </simpara>
9513 </listitem>
9514 </itemizedlist>
9515 </listitem>
9516 <listitem>
9517 <simpara>
9518 <link linkend="RunningOnPowerPC">PowerPC</link>:
9519 </simpara>
9520 <itemizedlist>
9521 <listitem>
9522 <simpara>
9523 <link linkend="RunningOnAIX">AIX</link> (5.2 and above)
9524 </simpara>
9525 </listitem>
9526 <listitem>
9527 <simpara>
9528 <link linkend="RunningOnDarwin">Darwin</link> (Mac OS X)
9529 </simpara>
9530 </listitem>
9531 <listitem>
9532 <simpara>
9533 <link linkend="RunningOnLinux">Linux</link> (Debian, Fedora, &#8230;)
9534 </simpara>
9535 </listitem>
9536 </itemizedlist>
9537 </listitem>
9538 <listitem>
9539 <simpara>
9540 <link linkend="RunningOnPowerPC64">PowerPC64</link>:
9541 </simpara>
9542 <itemizedlist>
9543 <listitem>
9544 <simpara>
9545 <link linkend="RunningOnAIX">AIX</link> (5.2 and above)
9546 </simpara>
9547 </listitem>
9548 </itemizedlist>
9549 </listitem>
9550 <listitem>
9551 <simpara>
9552 <link linkend="RunningOnS390">S390</link>
9553 </simpara>
9554 <itemizedlist>
9555 <listitem>
9556 <simpara>
9557 <link linkend="RunningOnLinux">Linux</link> (Debian)
9558 </simpara>
9559 </listitem>
9560 </itemizedlist>
9561 </listitem>
9562 <listitem>
9563 <simpara>
9564 <link linkend="RunningOnSparc">Sparc</link>
9565 </simpara>
9566 <itemizedlist>
9567 <listitem>
9568 <simpara>
9569 <link linkend="RunningOnLinux">Linux</link> (Debian)
9570 </simpara>
9571 </listitem>
9572 <listitem>
9573 <simpara>
9574 <link linkend="RunningOnSolaris">Solaris</link> (8 and above)
9575 </simpara>
9576 </listitem>
9577 </itemizedlist>
9578 </listitem>
9579 <listitem>
9580 <simpara>
9581 <link linkend="RunningOnX86">X86</link>:
9582 </simpara>
9583 <itemizedlist>
9584 <listitem>
9585 <simpara>
9586 <link linkend="RunningOnCygwin">Cygwin</link>/Windows
9587 </simpara>
9588 </listitem>
9589 <listitem>
9590 <simpara>
9591 <link linkend="RunningOnDarwin">Darwin</link> (Mac OS X)
9592 </simpara>
9593 </listitem>
9594 <listitem>
9595 <simpara>
9596 <link linkend="RunningOnFreeBSD">FreeBSD</link>
9597 </simpara>
9598 </listitem>
9599 <listitem>
9600 <simpara>
9601 <link linkend="RunningOnLinux">Linux</link> (Debian, Fedora, Ubuntu, &#8230;)
9602 </simpara>
9603 </listitem>
9604 <listitem>
9605 <simpara>
9606 <link linkend="RunningOnMinGW">MinGW</link>/Windows
9607 </simpara>
9608 </listitem>
9609 <listitem>
9610 <simpara>
9611 <link linkend="RunningOnNetBSD">NetBSD</link>
9612 </simpara>
9613 </listitem>
9614 <listitem>
9615 <simpara>
9616 <link linkend="RunningOnOpenBSD">OpenBSD</link>
9617 </simpara>
9618 </listitem>
9619 <listitem>
9620 <simpara>
9621 <link linkend="RunningOnSolaris">Solaris</link> (10 and above)
9622 </simpara>
9623 </listitem>
9624 </itemizedlist>
9625 </listitem>
9626 </itemizedlist>
9627 </listitem>
9628 </itemizedlist>
9629 </section>
9630 <section id="_robustness">
9631 <title>Robustness</title>
9632 <itemizedlist>
9633 <listitem>
9634 <simpara>
9635 Supports the full SML 97 language as given in <link linkend="DefinitionOfStandardML">The Definition of Standard ML (Revised)</link>.
9636 </simpara>
9637 <simpara>If there is a program that is valid according to the
9638 <link linkend="DefinitionOfStandardML">Definition</link> that is rejected by MLton, or a
9639 program that is invalid according to the
9640 <link linkend="DefinitionOfStandardML">Definition</link> that is accepted by MLton, it is
9641 a bug. For a list of known bugs, see <link linkend="UnresolvedBugs">UnresolvedBugs</link>.</simpara>
9642 </listitem>
9643 <listitem>
9644 <simpara>
9645 A complete implementation of the <link linkend="BasisLibrary">Basis Library</link>.
9646 </simpara>
9647 <simpara>MLton&#8217;s implementation matches latest <link linkend="BasisLibrary">Basis Library</link>
9648 <ulink url="http://www.standardml.org/Basis">specification</ulink>, and includes a
9649 complete implementation of all the required modules, as well as many
9650 of the optional modules.</simpara>
9651 </listitem>
9652 <listitem>
9653 <simpara>
9654 Generates standalone executables.
9655 </simpara>
9656 <simpara>No additional code or libraries are necessary in order to run an
9657 executable, except for the standard shared libraries. MLton can also
9658 generate statically linked executables.</simpara>
9659 </listitem>
9660 <listitem>
9661 <simpara>
9662 Compiles large programs.
9663 </simpara>
9664 <simpara>MLton is sufficiently efficient and robust that it can compile large
9665 programs, including itself (over 190K lines). The distributed version
9666 of MLton was compiled by MLton.</simpara>
9667 </listitem>
9668 <listitem>
9669 <simpara>
9670 Support for large amounts of memory (up to 4G on 32-bit systems; more on 64-bit systems).
9671 </simpara>
9672 </listitem>
9673 <listitem>
9674 <simpara>
9675 Support for large array lengths (up to 2<superscript>31</superscript>-1 on 32-bit systems; up to 2<superscript>63</superscript>-1 on 64-bit systems).
9676 </simpara>
9677 </listitem>
9678 <listitem>
9679 <simpara>
9680 Support for large files, using 64-bit file positions.
9681 </simpara>
9682 </listitem>
9683 </itemizedlist>
9684 </section>
9685 <section id="_performance">
9686 <title>Performance</title>
9687 <itemizedlist>
9688 <listitem>
9689 <simpara>
9690 Executables have <link linkend="Performance">excellent running times</link>.
9691 </simpara>
9692 </listitem>
9693 <listitem>
9694 <simpara>
9695 Generates small executables.
9696 </simpara>
9697 <simpara>MLton takes advantage of whole-program compilation to perform very
9698 aggressive dead-code elimination, which often leads to smaller
9699 executables than with other SML compilers.</simpara>
9700 </listitem>
9701 <listitem>
9702 <simpara>
9703 Untagged and unboxed native integers, reals, and words.
9704 </simpara>
9705 <simpara>In MLton, integers and words are 8 bits, 16 bits, 32 bits, and 64 bits
9706 and arithmetic does not have any overhead due to tagging or boxing.
9707 Also, reals (32-bit and 64-bit) are stored unboxed, avoiding any
9708 overhead due to boxing.</simpara>
9709 </listitem>
9710 <listitem>
9711 <simpara>
9712 Unboxed native arrays.
9713 </simpara>
9714 <simpara>In MLton, an array (or vector) of integers, reals, or words uses the
9715 natural C-like representation. This is fast and supports easy
9716 exchange of data with C. Monomorphic arrays (and vectors) use the
9717 same C-like representations as their polymorphic counterparts.</simpara>
9718 </listitem>
9719 <listitem>
9720 <simpara>
9721 Multiple <link linkend="GarbageCollection">garbage collection</link> strategies.
9722 </simpara>
9723 </listitem>
9724 <listitem>
9725 <simpara>
9726 Fast arbitrary precision arithmetic (<literal>IntInf</literal>) based on <link linkend="GnuMP">GnuMP</link>.
9727 </simpara>
9728 <simpara>For <literal>IntInf</literal> intensive programs, MLton can be an order of magnitude or
9729 more faster than Poly/ML or SML/NJ.</simpara>
9730 </listitem>
9731 </itemizedlist>
9732 </section>
9733 <section id="_tools">
9734 <title>Tools</title>
9735 <itemizedlist>
9736 <listitem>
9737 <simpara>
9738 Source-level <link linkend="Profiling">Profiling</link> of both time and allocation.
9739 </simpara>
9740 </listitem>
9741 <listitem>
9742 <simpara>
9743 <link linkend="MLLex">MLLex</link> lexer generator
9744 </simpara>
9745 </listitem>
9746 <listitem>
9747 <simpara>
9748 <link linkend="MLYacc">MLYacc</link> parser generator
9749 </simpara>
9750 </listitem>
9751 <listitem>
9752 <simpara>
9753 <link linkend="MLNLFFIGen">MLNLFFIGen</link> foreign-function-interface generator
9754 </simpara>
9755 </listitem>
9756 </itemizedlist>
9757 </section>
9758 <section id="_extensions">
9759 <title>Extensions</title>
9760 <itemizedlist>
9761 <listitem>
9762 <simpara>
9763 A simple and fast C <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link> that supports calling from SML to C and from C to SML.
9764 </simpara>
9765 </listitem>
9766 <listitem>
9767 <simpara>
9768 The <link linkend="MLBasis">ML Basis system</link> for programming in the very large, separate delivery of library sources, and more.
9769 </simpara>
9770 </listitem>
9771 <listitem>
9772 <simpara>
9773 A number of extension libraries that provide useful functionality
9774 that cannot be implemented with the <link linkend="BasisLibrary">Basis Library</link>.
9775 See below for an overview and <link linkend="MLtonStructure">MLtonStructure</link> for details.
9776 </simpara>
9777 <itemizedlist>
9778 <listitem>
9779 <simpara>
9780 <link linkend="MLtonCont">continuations</link>
9781 </simpara>
9782 <simpara>MLton supports continuations via <literal>callcc</literal> and <literal>throw</literal>.</simpara>
9783 </listitem>
9784 <listitem>
9785 <simpara>
9786 <link linkend="MLtonFinalizable">finalization</link>
9787 </simpara>
9788 <simpara>MLton supports finalizable values of arbitrary type.</simpara>
9789 </listitem>
9790 <listitem>
9791 <simpara>
9792 <link linkend="MLtonItimer">interval timers</link>
9793 </simpara>
9794 <simpara>MLton supports the functionality of the C <literal>setitimer</literal> function.</simpara>
9795 </listitem>
9796 <listitem>
9797 <simpara>
9798 <link linkend="MLtonRandom">random numbers</link>
9799 </simpara>
9800 <simpara>MLton has functions similar to the C <literal>rand</literal> and <literal>srand</literal> functions, as well as support for access to <literal>/dev/random</literal> and <literal>/dev/urandom</literal>.</simpara>
9801 </listitem>
9802 <listitem>
9803 <simpara>
9804 <link linkend="MLtonRlimit">resource limits</link>
9805 </simpara>
9806 <simpara>MLton has functions similar to the C <literal>getrlimit</literal> and <literal>setrlimit</literal> functions.</simpara>
9807 </listitem>
9808 <listitem>
9809 <simpara>
9810 <link linkend="MLtonRusage">resource usage</link>
9811 </simpara>
9812 <simpara>MLton supports a subset of the functionality of the C <literal>getrusage</literal> function.</simpara>
9813 </listitem>
9814 <listitem>
9815 <simpara>
9816 <link linkend="MLtonSignal">signal handlers</link>
9817 </simpara>
9818 <simpara>MLton supports signal handlers written in SML. Signal handlers run in
9819 a separate MLton thread, and have access to the thread that was
9820 interrupted by the signal. Signal handlers can be used in conjunction
9821 with threads to implement preemptive multitasking.</simpara>
9822 </listitem>
9823 <listitem>
9824 <simpara>
9825 <link linkend="MLtonStructure">size primitive</link>
9826 </simpara>
9827 <simpara>MLton includes a primitive that returns the size (in bytes) of any
9828 object. This can be useful in understanding the space behavior of a
9829 program.</simpara>
9830 </listitem>
9831 <listitem>
9832 <simpara>
9833 <link linkend="MLtonSyslog">system logging</link>
9834 </simpara>
9835 <simpara>MLton has a complete interface to the C <literal>syslog</literal> function.</simpara>
9836 </listitem>
9837 <listitem>
9838 <simpara>
9839 <link linkend="MLtonThread">threads</link>
9840 </simpara>
9841 <simpara>MLton has support for its own threads, upon which either preemptive or
9842 non-preemptive multitasking can be implemented. MLton also has
9843 support for <link linkend="ConcurrentML">Concurrent ML</link> (CML).</simpara>
9844 </listitem>
9845 <listitem>
9846 <simpara>
9847 <link linkend="MLtonWeak">weak pointers</link>
9848 </simpara>
9849 <simpara>MLton supports weak pointers, which allow the garbage collector to
9850 reclaim objects that it would otherwise be forced to keep. Weak
9851 pointers are also used to provide finalization.</simpara>
9852 </listitem>
9853 <listitem>
9854 <simpara>
9855 <link linkend="MLtonWorld">world save and restore</link>
9856 </simpara>
9857 <simpara>MLton has a facility for saving the entire state of a computation to a
9858 file and restarting it later. This facility can be used for staging
9859 and for checkpointing computations. It can even be used from within
9860 signal handlers, allowing interrupt driven checkpointing.</simpara>
9861 </listitem>
9862 </itemizedlist>
9863 </listitem>
9864 </itemizedlist>
9865 <simpara><?asciidoc-pagebreak?></simpara>
9866 </section>
9867 </section>
9868 <section id="FirstClassPolymorphism">
9869 <title>FirstClassPolymorphism</title>
9870 <simpara>First-class polymorphism is the ability to treat polymorphic functions
9871 just like other values: pass them as arguments, store them in data
9872 structures, etc. Although <link linkend="StandardML">Standard ML</link> does have
9873 polymorphic functions, it does not support first-class polymorphism.</simpara>
9874 <simpara>For example, the following declares and uses the polymorphic function
9875 <literal>id</literal>.</simpara>
9876 <programlisting language="sml" linenumbering="unnumbered">val id = fn x =&gt; x
9877 val _ = id 13
9878 val _ = id "foo"</programlisting>
9879 <simpara>If SML supported first-class polymorphism, we could write the
9880 following.</simpara>
9881 <programlisting language="sml" linenumbering="unnumbered">fun useId id = (id 13; id "foo")</programlisting>
9882 <simpara>However, this does not type check. MLton reports the following error.</simpara>
9883 <screen>Error: z.sml 1.24-1.31.
9884 Function applied to incorrect argument.
9885 expects: [int]
9886 but got: [string]
9887 in: id "foo"</screen>
9888 <simpara>The error message arises because MLton infers from <literal>id 13</literal> that <literal>id</literal>
9889 accepts an integer argument, but that <literal>id "foo"</literal> is passing a string.</simpara>
9890 <simpara>Using explicit types sheds some light on the problem.</simpara>
9891 <programlisting language="sml" linenumbering="unnumbered">fun useId (id: 'a -&gt; 'a) = (id 13; id "foo")</programlisting>
9892 <simpara>On this, MLton reports the following errors.</simpara>
9893 <screen>Error: z.sml 1.29-1.33.
9894 Function applied to incorrect argument.
9895 expects: ['a]
9896 but got: [int]
9897 in: id 13
9898 Error: z.sml 1.36-1.43.
9899 Function applied to incorrect argument.
9900 expects: ['a]
9901 but got: [string]
9902 in: id "foo"</screen>
9903 <simpara>The errors arise because the argument <literal>id</literal> is <emphasis>not</emphasis> polymorphic;
9904 rather, it is monomorphic, with type <literal>'a -&gt; 'a</literal>. It is perfectly
9905 valid to apply <literal>id</literal> to a value of type <literal>'a</literal>, as in the following</simpara>
9906 <programlisting language="sml" linenumbering="unnumbered">fun useId (id: 'a -&gt; 'a, x: 'a) = id x (* type correct *)</programlisting>
9907 <simpara>So, what is the difference between the type specification on <literal>id</literal> in
9908 the following two declarations?</simpara>
9909 <programlisting language="sml" linenumbering="unnumbered">val id: 'a -&gt; 'a = fn x =&gt; x
9910 fun useId (id: 'a -&gt; 'a) = (id 13; id "foo")</programlisting>
9911 <simpara>While the type specifications on <literal>id</literal> look identical, they mean
9912 different things. The difference can be made clearer by explicitly
9913 <link linkend="TypeVariableScope">scoping the type variables</link>.</simpara>
9914 <programlisting language="sml" linenumbering="unnumbered">val 'a id: 'a -&gt; 'a = fn x =&gt; x
9915 fun 'a useId (id: 'a -&gt; 'a) = (id 13; id "foo") (* type error *)</programlisting>
9916 <simpara>In <literal>val 'a id</literal>, the type variable scoping means that for any <literal>'a</literal>,
9917 <literal>id</literal> has type <literal>'a -&gt; 'a</literal>. Hence, <literal>id</literal> can be applied to arguments of
9918 type <literal>int</literal>, <literal>real</literal>, etc. Similarly, in <literal>fun 'a useId</literal>, the scoping
9919 means that <literal>useId</literal> is a polymorphic function that for any <literal>'a</literal> takes a
9920 function of type <literal>'a -&gt; 'a</literal> and does something. Thus, <literal>useId</literal> could
9921 be applied to a function of type <literal>int -&gt; int</literal>, <literal>real -&gt; real</literal>, etc.</simpara>
9922 <simpara>One could imagine an extension of SML that allowed scoping of type
9923 variables at places other than <literal>fun</literal> or <literal>val</literal> declarations, as in the
9924 following.</simpara>
9925 <screen>fun useId (id: ('a).'a -&gt; 'a) = (id 13; id "foo") (* not SML *)</screen>
9926 <simpara>Such an extension would need to be thought through very carefully, as
9927 it could cause significant complications with <link linkend="TypeInference">TypeInference</link>,
9928 possible even undecidability.</simpara>
9929 <simpara><?asciidoc-pagebreak?></simpara>
9930 </section>
9931 <section id="Fixpoints">
9932 <title>Fixpoints</title>
9933 <simpara>This page discusses a framework that makes it possible to compute
9934 fixpoints over arbitrary products of abstract types. The code is from
9935 an Extended Basis library
9936 (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/extended-basis/unstable/README"><literal>README</literal></ulink>).</simpara>
9937 <simpara>First the signature of the framework
9938 (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/extended-basis/unstable/public/generic/tie.sig"><literal>tie.sig</literal></ulink>):</simpara>
9939 <programlisting language="sml" linenumbering="unnumbered">(**
9940 * A framework for computing fixpoints.
9941 *
9942 * In a strict language you sometimes want to provide a fixpoint
9943 * combinator for an abstract type {t} to make it possible to write
9944 * recursive definitions. Unfortunately, a single combinator {fix} of the
9945 * type {(t -&gt; t) -&gt; t} does not support mutual recursion. To support
9946 * mutual recursion, you would need to provide a family of fixpoint
9947 * combinators having types of the form {(u -&gt; u) -&gt; u} where {u} is a
9948 * type of the form {t * ... * t}. Unfortunately, even such a family of
9949 * fixpoint combinators does not support mutual recursion over different
9950 * abstract types.
9951 *)
9952 signature TIE = sig
9953 include ETAEXP'
9954 type 'a t = 'a etaexp
9955 (** The type of fixpoint witnesses. *)
9956
9957 val fix : 'a t -&gt; 'a Fix.t
9958 (**
9959 * Produces a fixpoint combinator from the given witness. For example,
9960 * one can make a mutually recursive definition of functions:
9961 *
9962 *&gt; val isEven &amp; isOdd =
9963 *&gt; let open Tie in fix (function *` function) end
9964 *&gt; (fn isEven &amp; isOdd =&gt;
9965 *&gt; (fn 0 =&gt; true
9966 *&gt; | 1 =&gt; false
9967 *&gt; | n =&gt; isOdd (n-1)) &amp;
9968 *&gt; (fn 0 =&gt; false
9969 *&gt; | 1 =&gt; true
9970 *&gt; | n =&gt; isEven (n-1)))
9971 *)
9972
9973 (** == Making New Witnesses == *)
9974
9975 val pure : ('a * 'a UnOp.t) Thunk.t -&gt; 'a t
9976 (**
9977 * {pure} is a more general version of {tier}. It is mostly useful for
9978 * computing fixpoints in a non-imperative manner.
9979 *)
9980
9981 val tier : ('a * 'a Effect.t) Thunk.t -&gt; 'a t
9982 (**
9983 * {tier} is used to define fixpoint witnesses for new abstract types
9984 * by providing a thunk whose instantiation allocates a mutable proxy
9985 * and a procedure for updating it with the result.
9986 *)
9987
9988 val id : 'a -&gt; 'a t
9989 (** {id x} is equivalent to {pure (const (x, id))}. *)
9990
9991 (** == Combining Existing Witnesses == *)
9992
9993 val iso : 'b t -&gt; ('a, 'b) Iso.t -&gt; 'a t
9994 (**
9995 * Given an isomorphism between {'a} and {'b} and a witness for {'b},
9996 * produces a witness for {'a}. This is useful when you have a new
9997 * type that is isomorphic to some old type for which you already have
9998 * a witness.
9999 *)
10000
10001 val product : 'a t * ('a -&gt; 'b t) -&gt; ('a, 'b) Product.t t
10002 (**
10003 * Dependent product combinator. Given a witness for {'a} and a
10004 * constructor from a {'a} to witness for {'b}, produces a witness for
10005 * the product {('a, 'b) Product.t}. The constructor for {'b} should
10006 * not access the (proxy) value {'a} before it has been fixed.
10007 *)
10008
10009 val *` : 'a t * 'b t -&gt; ('a, 'b) Product.t t
10010 (** {a *` b} is equivalent to {product (a, const b)}. *)
10011
10012 val tuple2 : 'a t * 'b t -&gt; ('a * 'b) t
10013 (**
10014 * Given witnesses for {'a} and {'b} produces a witness for the product
10015 * {'a * 'b}.
10016 *)
10017
10018 (** == Particular Witnesses == *)
10019
10020 val function : ('a -&gt; 'b) t
10021 (** Witness for functions. *)
10022 end</programlisting>
10023 <simpara><literal>fix</literal> is a <link linkend="TypeIndexedValues">type-indexed</link> function. The type-index
10024 parameter to <literal>fix</literal> is called a "witness". To compute fixpoints over
10025 products, one uses the <literal>*&grave;</literal> operator to combine witnesses. To provide
10026 a fixpoint combinator for an abstract type, one implements a witness
10027 providing a thunk whose instantiation allocates a fresh, mutable proxy
10028 and a procedure for updating the proxy with the solution. Naturally
10029 this means that not all possible ways of computing a fixpoint of a
10030 particular type are possible under the framework. The <literal>pure</literal>
10031 combinator is a generalization of <literal>tier</literal>. The <literal>iso</literal> combinator is
10032 provided for reusing existing witnesses.</simpara>
10033 <simpara>Note that instead of using an infix operator, we could alternatively
10034 employ an interface using <link linkend="Fold">Fold</link>. Also, witnesses are eta-expanded
10035 to work around the <link linkend="ValueRestriction">value restriction</link>, while
10036 maintaining abstraction.</simpara>
10037 <simpara>Here is the implementation
10038 (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/extended-basis/unstable/detail/generic/tie.sml"><literal>tie.sml</literal></ulink>):</simpara>
10039 <programlisting language="sml" linenumbering="unnumbered">structure Tie :&gt; TIE = struct
10040 open Product
10041 infix &amp;
10042 type 'a etaexp_dom = Unit.t
10043 type 'a etaexp_cod = ('a * 'a UnOp.t) Thunk.t
10044 type 'a etaexp = 'a etaexp_dom -&gt; 'a etaexp_cod
10045 type 'a t = 'a etaexp
10046 fun fix aT f = let val (a, ta) = aT () () in ta (f a) end
10047 val pure = Thunk.mk
10048 fun iso bT (iso as (_, b2a)) () () = let
10049 val (b, fB) = bT () ()
10050 in
10051 (b2a b, Fn.map iso fB)
10052 end
10053 fun product (aT, a2bT) () () = let
10054 val (a, fA) = aT () ()
10055 val (b, fB) = a2bT a () ()
10056 in
10057 (a &amp; b, Product.map (fA, fB))
10058 end
10059 (* The rest are not primitive operations. *)
10060 fun op *` (aT, bT) = product (aT, Fn.const bT)
10061 fun tuple2 ab = iso (op *` ab) Product.isoTuple2
10062 fun tier th = pure ((fn (a, ua) =&gt; (a, Fn.const a o ua)) o th)
10063 fun id x = pure (Fn.const (x, Fn.id))
10064 fun function ? =
10065 pure (fn () =&gt; let
10066 val r = ref (Basic.raising Fix.Fix)
10067 in
10068 (fn x =&gt; !r x, fn f =&gt; (r := f ; f))
10069 end) ?
10070 end</programlisting>
10071 <simpara>Let&#8217;s then take a look at a couple of additional examples.</simpara>
10072 <simpara>Here is a naive implementation of lazy promises:</simpara>
10073 <programlisting language="sml" linenumbering="unnumbered">structure Promise :&gt; sig
10074 type 'a t
10075 val lazy : 'a Thunk.t -&gt; 'a t
10076 val force : 'a t -&gt; 'a
10077 val Y : 'a t Tie.t
10078 end = struct
10079 datatype 'a t' =
10080 EXN of exn
10081 | THUNK of 'a Thunk.t
10082 | VALUE of 'a
10083 type 'a t = 'a t' Ref.t
10084 fun lazy f = ref (THUNK f)
10085 fun force t =
10086 case !t
10087 of EXN e =&gt; raise e
10088 | THUNK f =&gt; (t := VALUE (f ()) handle e =&gt; t := EXN e ; force t)
10089 | VALUE v =&gt; v
10090 fun Y ? = Tie.tier (fn () =&gt; let
10091 val r = lazy (raising Fix.Fix)
10092 in
10093 (r, r &lt;\ op := o !)
10094 end) ?
10095 end</programlisting>
10096 <simpara>An example use of our naive lazy promises is to implement equally naive
10097 lazy streams:</simpara>
10098 <programlisting language="sml" linenumbering="unnumbered">structure Stream :&gt; sig
10099 type 'a t
10100 val cons : 'a * 'a t -&gt; 'a t
10101 val get : 'a t -&gt; ('a * 'a t) Option.t
10102 val Y : 'a t Tie.t
10103 end = struct
10104 datatype 'a t = IN of ('a * 'a t) Option.t Promise.t
10105 fun cons (x, xs) = IN (Promise.lazy (fn () =&gt; SOME (x, xs)))
10106 fun get (IN p) = Promise.force p
10107 fun Y ? = Tie.iso Promise.Y (fn IN p =&gt; p, IN) ?
10108 end</programlisting>
10109 <simpara>Note that above we make use of the <literal>iso</literal> combinator. Here is a finite
10110 representation of an infinite stream of ones:</simpara>
10111 <programlisting language="sml" linenumbering="unnumbered">val ones = let
10112 open Tie Stream
10113 in
10114 fix Y (fn ones =&gt; cons (1, ones))
10115 end</programlisting>
10116 <simpara><?asciidoc-pagebreak?></simpara>
10117 </section>
10118 <section id="Flatten">
10119 <title>Flatten</title>
10120 <simpara><link linkend="Flatten">Flatten</link> is an optimization pass for the <link linkend="SSA">SSA</link>
10121 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
10122 <section id="_description_17">
10123 <title>Description</title>
10124 <simpara>This pass flattens arguments to <link linkend="SSA">SSA</link> constructors, blocks, and
10125 functions.</simpara>
10126 <simpara>If a tuple is explicitly available at all uses of a function
10127 (resp. block), then:</simpara>
10128 <itemizedlist>
10129 <listitem>
10130 <simpara>
10131 The formals and call sites are changed so that the components of the
10132 tuple are passed.
10133 </simpara>
10134 </listitem>
10135 <listitem>
10136 <simpara>
10137 The tuple is reconstructed at the beginning of the body of the
10138 function (resp. block).
10139 </simpara>
10140 </listitem>
10141 </itemizedlist>
10142 <simpara>Similarly, if a tuple is explicitly available at all uses of a
10143 constructor, then:</simpara>
10144 <itemizedlist>
10145 <listitem>
10146 <simpara>
10147 The constructor argument datatype is changed to flatten the tuple
10148 type.
10149 </simpara>
10150 </listitem>
10151 <listitem>
10152 <simpara>
10153 The tuple is passed flat at each <literal>ConApp</literal>.
10154 </simpara>
10155 </listitem>
10156 <listitem>
10157 <simpara>
10158 The tuple is reconstructed at each <literal>Case</literal> transfer target.
10159 </simpara>
10160 </listitem>
10161 </itemizedlist>
10162 </section>
10163 <section id="_implementation_19">
10164 <title>Implementation</title>
10165 <itemizedlist>
10166 <listitem>
10167 <simpara>
10168 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/flatten.fun"><literal>flatten.fun</literal></ulink>
10169 </simpara>
10170 </listitem>
10171 </itemizedlist>
10172 </section>
10173 <section id="_details_and_notes_19">
10174 <title>Details and Notes</title>
10175 <simpara></simpara>
10176 <simpara><?asciidoc-pagebreak?></simpara>
10177 </section>
10178 </section>
10179 <section id="Fold">
10180 <title>Fold</title>
10181 <simpara>This page describes a technique that enables convenient syntax for a
10182 number of language features that are not explicitly supported by
10183 <link linkend="StandardML">Standard ML</link>, including: variable number of arguments,
10184 <link linkend="OptionalArguments">optional arguments and labeled arguments</link>,
10185 <link linkend="ArrayLiteral">array and vector literals</link>,
10186 <link linkend="FunctionalRecordUpdate">functional record update</link>,
10187 and (seemingly) dependently typed functions like <link linkend="Printf">printf</link> and scanf.</simpara>
10188 <simpara>The key idea to <emphasis>fold</emphasis> is to define functions <literal>fold</literal>, <literal>step0</literal>,
10189 and <literal>$</literal> such that the following equation holds.</simpara>
10190 <programlisting language="sml" linenumbering="unnumbered">fold (a, f) (step0 h1) (step0 h2) ... (step0 hn) $
10191 = f (hn (... (h2 (h1 a))))</programlisting>
10192 <simpara>The name <literal>fold</literal> comes because this is like a traditional list fold,
10193 where <literal>a</literal> is the <emphasis>base element</emphasis>, and each <emphasis>step function</emphasis>,
10194 <literal>step0 hi</literal>, corresponds to one element of the list and does one
10195 step of the fold. The name <literal>$</literal> is chosen to mean "end of
10196 arguments" from its common use in regular-expression syntax.</simpara>
10197 <simpara>Unlike the usual list fold in which the same function is used to step
10198 over each element in the list, this fold allows the step functions to
10199 be different from each other, and even to be of different types. Also
10200 unlike the usual list fold, this fold includes a "finishing
10201 function", <literal>f</literal>, that is applied to the result of the fold. The
10202 presence of the finishing function may seem odd because there is no
10203 analogy in list fold. However, the finishing function is essential;
10204 without it, there would be no way for the folder to perform an
10205 arbitrary computation after processing all the arguments. The
10206 examples below will make this clear.</simpara>
10207 <simpara>The functions <literal>fold</literal>, <literal>step0</literal>, and <literal>$</literal> are easy to
10208 define.</simpara>
10209 <programlisting language="sml" linenumbering="unnumbered">fun $ (a, f) = f a
10210 fun id x = x
10211 structure Fold =
10212 struct
10213 fun fold (a, f) g = g (a, f)
10214 fun step0 h (a, f) = fold (h a, f)
10215 end</programlisting>
10216 <simpara>We&#8217;ve placed <literal>fold</literal> and <literal>step0</literal> in the <literal>Fold</literal> structure
10217 but left <literal>$</literal> at the toplevel because it is convenient in code to
10218 always have <literal>$</literal> in scope. We&#8217;ve also defined the identity
10219 function, <literal>id</literal>, at the toplevel since we use it so frequently.</simpara>
10220 <simpara>Plugging in the definitions, it is easy to verify the equation from
10221 above.</simpara>
10222 <programlisting language="sml" linenumbering="unnumbered">fold (a, f) (step0 h1) (step0 h2) ... (step0 hn) $
10223 = step0 h1 (a, f) (step0 h2) ... (step0 hn) $
10224 = fold (h1 a, f) (step0 h2) ... (step0 hn) $
10225 = step0 h2 (h1 a, f) ... (step0 hn) $
10226 = fold (h2 (h1 a), f) ... (step0 hn) $
10227 ...
10228 = fold (hn (... (h2 (h1 a))), f) $
10229 = $ (hn (... (h2 (h1 a))), f)
10230 = f (hn (... (h2 (h1 a))))</programlisting>
10231 <section id="_example_variable_number_of_arguments">
10232 <title>Example: variable number of arguments</title>
10233 <simpara>The simplest example of fold is accepting a variable number of
10234 (curried) arguments. We&#8217;ll define a function <literal>f</literal> and argument
10235 <literal>a</literal> such that all of the following expressions are valid.</simpara>
10236 <programlisting language="sml" linenumbering="unnumbered">f $
10237 f a $
10238 f a a $
10239 f a a a $
10240 f a a a ... a a a $ (* as many a's as we want *)</programlisting>
10241 <simpara>Off-hand it may appear impossible that all of the above expressions
10242 are type correct SML&#8201;&#8212;&#8201;how can a function <literal>f</literal> accept a variable
10243 number of curried arguments? What could the type of <literal>f</literal> be?
10244 We&#8217;ll have more to say later on how type checking works. For now,
10245 once we have supplied the definitions below, you can check that the
10246 expressions are type correct by feeding them to your favorite SML
10247 implementation.</simpara>
10248 <simpara>It is simple to define <literal>f</literal> and <literal>a</literal>. We define <literal>f</literal> as a
10249 folder whose base element is <literal>()</literal> and whose finish function does
10250 nothing. We define <literal>a</literal> as the step function that does nothing.
10251 The only trickiness is that we must <link linkend="EtaExpansion">eta expand</link> the
10252 definition of <literal>f</literal> and <literal>a</literal> to work around the ValueRestriction;
10253 we frequently use eta expansion for this purpose without mention.</simpara>
10254 <programlisting language="sml" linenumbering="unnumbered">val base = ()
10255 fun finish () = ()
10256 fun step () = ()
10257 val f = fn z =&gt; Fold.fold (base, finish) z
10258 val a = fn z =&gt; Fold.step0 step z</programlisting>
10259 <simpara>One can easily apply the fold equation to verify by hand that <literal>f</literal>
10260 applied to any number of <literal>a</literal>'s evaluates to <literal>()</literal>.</simpara>
10261 <programlisting language="sml" linenumbering="unnumbered">f a ... a $
10262 = finish (step (... (step base)))
10263 = finish (step (... ()))
10264 ...
10265 = finish ()
10266 = ()</programlisting>
10267 </section>
10268 <section id="_example_variable_argument_sum">
10269 <title>Example: variable-argument sum</title>
10270 <simpara>Let&#8217;s look at an example that computes something: a variable-argument
10271 function <literal>sum</literal> and a stepper <literal>a</literal> such that</simpara>
10272 <programlisting language="sml" linenumbering="unnumbered">sum (a i1) (a i2) ... (a im) $ = i1 + i2 + ... + im</programlisting>
10273 <simpara>The idea is simple&#8201;&#8212;&#8201;the folder starts with a base accumulator of
10274 <literal>0</literal> and the stepper adds each element to the accumulator, <literal>s</literal>,
10275 which the folder simply returns at the end.</simpara>
10276 <programlisting language="sml" linenumbering="unnumbered">val sum = fn z =&gt; Fold.fold (0, fn s =&gt; s) z
10277 fun a i = Fold.step0 (fn s =&gt; i + s)</programlisting>
10278 <simpara>Using the fold equation, one can verify the following.</simpara>
10279 <programlisting language="sml" linenumbering="unnumbered">sum (a 1) (a 2) (a 3) $ = 6</programlisting>
10280 </section>
10281 <section id="_step1">
10282 <title>Step1</title>
10283 <simpara>It is sometimes syntactically convenient to omit the parentheses
10284 around the steps in a fold. This is easily done by defining a new
10285 function, <literal>step1</literal>, as follows.</simpara>
10286 <programlisting language="sml" linenumbering="unnumbered">structure Fold =
10287 struct
10288 open Fold
10289 fun step1 h (a, f) b = fold (h (b, a), f)
10290 end</programlisting>
10291 <simpara>From the definition of <literal>step1</literal>, we have the following
10292 equivalence.</simpara>
10293 <programlisting language="sml" linenumbering="unnumbered">fold (a, f) (step1 h) b
10294 = step1 h (a, f) b
10295 = fold (h (b, a), f)</programlisting>
10296 <simpara>Using the above equivalence, we can compute the following equation for
10297 <literal>step1</literal>.</simpara>
10298 <programlisting language="sml" linenumbering="unnumbered">fold (a, f) (step1 h1) b1 (step1 h2) b2 ... (step1 hn) bn $
10299 = fold (h1 (b1, a), f) (step1 h2) b2 ... (step1 hn) bn $
10300 = fold (h2 (b2, h1 (b1, a)), f) ... (step1 hn) bn $
10301 = fold (hn (bn, ... (h2 (b2, h1 (b1, a)))), f) $
10302 = f (hn (bn, ... (h2 (b2, h1 (b1, a)))))</programlisting>
10303 <simpara>Here is an example using <literal>step1</literal> to define a variable-argument
10304 product function, <literal>prod</literal>, with a convenient syntax.</simpara>
10305 <programlisting language="sml" linenumbering="unnumbered">val prod = fn z =&gt; Fold.fold (1, fn p =&gt; p) z
10306 val ` = fn z =&gt; Fold.step1 (fn (i, p) =&gt; i * p) z</programlisting>
10307 <simpara>The functions <literal>prod</literal> and <literal>&grave;</literal> satisfy the following equation.</simpara>
10308 <programlisting language="sml" linenumbering="unnumbered">prod `i1 `i2 ... `im $ = i1 * i2 * ... * im</programlisting>
10309 <simpara>Note that in SML, <literal>&grave;i1</literal> is two different tokens, <literal>&grave;</literal> and
10310 <literal>i1</literal>. We often use <literal>&grave;</literal> for an instance of a <literal>step1</literal> function
10311 because of its syntactic unobtrusiveness and because no space is
10312 required to separate it from an alphanumeric token.</simpara>
10313 <simpara>Also note that there are no parenthesis around the steps. That is,
10314 the following expression is not the same as the above one (in fact, it
10315 is not type correct).</simpara>
10316 <programlisting language="sml" linenumbering="unnumbered">prod (`i1) (`i2) ... (`im) $</programlisting>
10317 </section>
10318 <section id="_example_list_literals">
10319 <title>Example: list literals</title>
10320 <simpara>SML already has a syntax for list literals, e.g. <literal>[w, x, y, z]</literal>.
10321 However, using fold, we can define our own syntax.</simpara>
10322 <programlisting language="sml" linenumbering="unnumbered">val list = fn z =&gt; Fold.fold ([], rev) z
10323 val ` = fn z =&gt; Fold.step1 (op ::) z</programlisting>
10324 <simpara>The idea is that the folder starts out with the empty list, the steps
10325 accumulate the elements into a list, and then the finishing function
10326 reverses the list at the end.</simpara>
10327 <simpara>With these definitions one can write a list like:</simpara>
10328 <programlisting language="sml" linenumbering="unnumbered">list `w `x `y `z $</programlisting>
10329 <simpara>While the example is not practically useful, it does demonstrate the
10330 need for the finishing function to be incorporated in <literal>fold</literal>.
10331 Without a finishing function, every use of <literal>list</literal> would need to be
10332 wrapped in <literal>rev</literal>, as follows.</simpara>
10333 <programlisting language="sml" linenumbering="unnumbered">rev (list `w `x `y `z $)</programlisting>
10334 <simpara>The finishing function allows us to incorporate the reversal into the
10335 definition of <literal>list</literal>, and to treat <literal>list</literal> as a truly variable
10336 argument function, performing an arbitrary computation after receiving
10337 all of its arguments.</simpara>
10338 <simpara>See <link linkend="ArrayLiteral">ArrayLiteral</link> for a similar use of <literal>fold</literal> that provides a
10339 syntax for array and vector literals, which are not built in to SML.</simpara>
10340 </section>
10341 <section id="_fold_right">
10342 <title>Fold right</title>
10343 <simpara>Just as <literal>fold</literal> is analogous to a fold left, in which the functions
10344 are applied to the accumulator left-to-right, we can define a variant
10345 of <literal>fold</literal> that is analogous to a fold right, in which the
10346 functions are applied to the accumulator right-to-left. That is, we
10347 can define functions <literal>foldr</literal> and <literal>step0</literal> such that the
10348 following equation holds.</simpara>
10349 <programlisting language="sml" linenumbering="unnumbered">foldr (a, f) (step0 h1) (step0 h2) ... (step0 hn) $
10350 = f (h1 (h2 (... (hn a))))</programlisting>
10351 <simpara>The implementation of fold right is easy, using fold. The idea is for
10352 the fold to start with <literal>f</literal> and for each step to precompose the
10353 next <literal>hi</literal>. Then, the finisher applies the composed function to
10354 the base value, <literal>a</literal>. Here is the code.</simpara>
10355 <programlisting language="sml" linenumbering="unnumbered">structure Foldr =
10356 struct
10357 fun foldr (a, f) = Fold.fold (f, fn g =&gt; g a)
10358 fun step0 h = Fold.step0 (fn g =&gt; g o h)
10359 end</programlisting>
10360 <simpara>Verifying the fold-right equation is straightforward, using the
10361 fold-left equation.</simpara>
10362 <programlisting language="sml" linenumbering="unnumbered">foldr (a, f) (Foldr.step0 h1) (Foldr.step0 h2) ... (Foldr.step0 hn) $
10363 = fold (f, fn g =&gt; g a)
10364 (Fold.step0 (fn g =&gt; g o h1))
10365 (Fold.step0 (fn g =&gt; g o h2))
10366 ...
10367 (Fold.step0 (fn g =&gt; g o hn)) $
10368 = (fn g =&gt; g a)
10369 ((fn g =&gt; g o hn) (... ((fn g =&gt; g o h2) ((fn g =&gt; g o h1) f))))
10370 = (fn g =&gt; g a)
10371 ((fn g =&gt; g o hn) (... ((fn g =&gt; g o h2) (f o h1))))
10372 = (fn g =&gt; g a) ((fn g =&gt; g o hn) (... (f o h1 o h2)))
10373 = (fn g =&gt; g a) (f o h1 o h2 o ... o hn)
10374 = (f o h1 o h2 o ... o hn) a
10375 = f (h1 (h2 (... (hn a))))</programlisting>
10376 <simpara>One can also define the fold-right analogue of <literal>step1</literal>.</simpara>
10377 <programlisting language="sml" linenumbering="unnumbered">structure Foldr =
10378 struct
10379 open Foldr
10380 fun step1 h = Fold.step1 (fn (b, g) =&gt; g o (fn a =&gt; h (b, a)))
10381 end</programlisting>
10382 </section>
10383 <section id="_example_list_literals_via_fold_right">
10384 <title>Example: list literals via fold right</title>
10385 <simpara>Revisiting the list literal example from earlier, we can use fold
10386 right to define a syntax for list literals that doesn&#8217;t do a reversal.</simpara>
10387 <programlisting language="sml" linenumbering="unnumbered">val list = fn z =&gt; Foldr.foldr ([], fn l =&gt; l) z
10388 val ` = fn z =&gt; Foldr.step1 (op ::) z</programlisting>
10389 <simpara>As before, with these definitions, one can write a list like:</simpara>
10390 <programlisting language="sml" linenumbering="unnumbered">list `w `x `y `z $</programlisting>
10391 <simpara>The difference between the fold-left and fold-right approaches is that
10392 the fold-right approach does not have to reverse the list at the end,
10393 since it accumulates the elements in the correct order. In practice,
10394 MLton will simplify away all of the intermediate function composition,
10395 so the the fold-right approach will be more efficient.</simpara>
10396 </section>
10397 <section id="_mixing_steppers">
10398 <title>Mixing steppers</title>
10399 <simpara>All of the examples so far have used the same step function throughout
10400 a fold. This need not be the case. For example, consider the
10401 following.</simpara>
10402 <programlisting language="sml" linenumbering="unnumbered">val n = fn z =&gt; Fold.fold (0, fn i =&gt; i) z
10403 val I = fn z =&gt; Fold.step0 (fn i =&gt; i * 2) z
10404 val O = fn z =&gt; Fold.step0 (fn i =&gt; i * 2 + 1) z</programlisting>
10405 <simpara>Here we have one folder, <literal>n</literal>, that can be used with two different
10406 steppers, <literal>I</literal> and <literal>O</literal>. By using the fold equation, one can
10407 verify the following equations.</simpara>
10408 <programlisting language="sml" linenumbering="unnumbered">n O $ = 0
10409 n I $ = 1
10410 n I O $ = 2
10411 n I O I $ = 5
10412 n I I I O $ = 14</programlisting>
10413 <simpara>That is, we&#8217;ve defined a syntax for writing binary integer constants.</simpara>
10414 <simpara>Not only can one use different instances of <literal>step0</literal> in the same
10415 fold, one can also intermix uses of <literal>step0</literal> and <literal>step1</literal>. For
10416 example, consider the following.</simpara>
10417 <programlisting language="sml" linenumbering="unnumbered">val n = fn z =&gt; Fold.fold (0, fn i =&gt; i) z
10418 val O = fn z =&gt; Fold.step0 (fn i =&gt; n * 8) z
10419 val ` = fn z =&gt; Fold.step1 (fn (i, n) =&gt; n * 8 + i) z</programlisting>
10420 <simpara>Using the straightforward generalization of the fold equation to mixed
10421 steppers, one can verify the following equations.</simpara>
10422 <programlisting language="sml" linenumbering="unnumbered">n 0 $ = 0
10423 n `3 O $ = 24
10424 n `1 O `7 $ = 71</programlisting>
10425 <simpara>That is, we&#8217;ve defined a syntax for writing octal integer constants,
10426 with a special syntax, <literal>O</literal>, for the zero digit (admittedly
10427 contrived, since one could just write <literal>&grave;0</literal> instead of <literal>O</literal>).</simpara>
10428 <simpara>See <link linkend="NumericLiteral">NumericLiteral</link> for a practical extension of this approach that
10429 supports numeric constants in any base and of any type.</simpara>
10430 </section>
10431 <section id="_seemingly_dependent_types">
10432 <title>(Seemingly) dependent types</title>
10433 <simpara>A normal list fold always returns the same type no matter what
10434 elements are in the list or how long the list is. Variable-argument
10435 fold is more powerful, because the result type can vary based both on
10436 the arguments that are passed and on their number. This can provide
10437 the illusion of dependent types.</simpara>
10438 <simpara>For example, consider the following.</simpara>
10439 <programlisting language="sml" linenumbering="unnumbered">val f = fn z =&gt; Fold.fold ((), id) z
10440 val a = fn z =&gt; Fold.step0 (fn () =&gt; "hello") z
10441 val b = fn z =&gt; Fold.step0 (fn () =&gt; 13) z
10442 val c = fn z =&gt; Fold.step0 (fn () =&gt; (1, 2)) z</programlisting>
10443 <simpara>Using the fold equation, one can verify the following equations.</simpara>
10444 <programlisting language="sml" linenumbering="unnumbered">f a $ = "hello": string
10445 f b $ = 13: int
10446 f c $ = (1, 2): int * int</programlisting>
10447 <simpara>That is, <literal>f</literal> returns a value of a different type depending on
10448 whether it is applied to argument <literal>a</literal>, argument <literal>b</literal>, or
10449 argument <literal>c</literal>.</simpara>
10450 <simpara>The following example shows how the type of a fold can depend on the
10451 number of arguments.</simpara>
10452 <programlisting language="sml" linenumbering="unnumbered">val grow = fn z =&gt; Fold.fold ([], fn l =&gt; l) z
10453 val a = fn z =&gt; Fold.step0 (fn x =&gt; [x]) z</programlisting>
10454 <simpara>Using the fold equation, one can verify the following equations.</simpara>
10455 <programlisting language="sml" linenumbering="unnumbered">grow $ = []: 'a list
10456 grow a $ = [[]]: 'a list list
10457 grow a a $ = [[[]]]: 'a list list list</programlisting>
10458 <simpara>Clearly, the result type of a call to the variable argument <literal>grow</literal>
10459 function depends on the number of arguments that are passed.</simpara>
10460 <simpara>As a reminder, this is well-typed SML. You can check it out in any
10461 implementation.</simpara>
10462 </section>
10463 <section id="_seemingly_dependently_typed_functional_results">
10464 <title>(Seemingly) dependently-typed functional results</title>
10465 <simpara>Fold is especially useful when it returns a curried function whose
10466 arity depends on the number of arguments. For example, consider the
10467 following.</simpara>
10468 <programlisting language="sml" linenumbering="unnumbered">val makeSum = fn z =&gt; Fold.fold (id, fn f =&gt; f 0) z
10469 val I = fn z =&gt; Fold.step0 (fn f =&gt; fn i =&gt; fn x =&gt; f (x + i)) z</programlisting>
10470 <simpara>The <literal>makeSum</literal> folder constructs a function whose arity depends on
10471 the number of <literal>I</literal> arguments and that adds together all of its
10472 arguments. For example,
10473 <literal>makeSum I $</literal> is of type <literal>int -&gt; int</literal> and
10474 <literal>makeSum I I $</literal> is of type <literal>int -&gt; int -&gt; int</literal>.</simpara>
10475 <simpara>One can use the fold equation to verify that the <literal>makeSum</literal> works
10476 correctly. For example, one can easily check by hand the following
10477 equations.</simpara>
10478 <programlisting language="sml" linenumbering="unnumbered">makeSum I $ 1 = 1
10479 makeSum I I $ 1 2 = 3
10480 makeSum I I I $ 1 2 3 = 6</programlisting>
10481 <simpara>Returning a function becomes especially interesting when there are
10482 steppers of different types. For example, the following <literal>makeSum</literal>
10483 folder constructs functions that sum integers and reals.</simpara>
10484 <programlisting language="sml" linenumbering="unnumbered">val makeSum = fn z =&gt; Foldr.foldr (id, fn f =&gt; f 0.0) z
10485 val I = fn z =&gt; Foldr.step0 (fn f =&gt; fn x =&gt; fn i =&gt; f (x + real i)) z
10486 val R = fn z =&gt; Foldr.step0 (fn f =&gt; fn x: real =&gt; fn r =&gt; f (x + r)) z</programlisting>
10487 <simpara>With these definitions, <literal>makeSum I R $</literal> is of type
10488 <literal>int -&gt; real -&gt; real</literal> and <literal>makeSum R I I $</literal> is of type
10489 <literal>real -&gt; int -&gt; int -&gt; real</literal>. One can use the foldr equation to
10490 check the following equations.</simpara>
10491 <programlisting language="sml" linenumbering="unnumbered">makeSum I $ 1 = 1.0
10492 makeSum I R $ 1 2.5 = 3.5
10493 makeSum R I I $ 1.5 2 3 = 6.5</programlisting>
10494 <simpara>We used <literal>foldr</literal> instead of <literal>fold</literal> for this so that the order
10495 in which the specifiers <literal>I</literal> and <literal>R</literal> appear is the same as the
10496 order in which the arguments appear. Had we used <literal>fold</literal>, things
10497 would have been reversed.</simpara>
10498 <simpara>An extension of this idea is sufficient to define <link linkend="Printf">Printf</link>-like
10499 functions in SML.</simpara>
10500 </section>
10501 <section id="_an_idiom_for_combining_steps">
10502 <title>An idiom for combining steps</title>
10503 <simpara>It is sometimes useful to combine a number of steps together and name
10504 them as a single step. As a simple example, suppose that one often
10505 sees an integer follower by a real in the <literal>makeSum</literal> example above.
10506 One can define a new <emphasis>compound step</emphasis> <literal>IR</literal> as follows.</simpara>
10507 <programlisting language="sml" linenumbering="unnumbered">val IR = fn u =&gt; Fold.fold u I R</programlisting>
10508 <simpara>With this definition in place, one can verify the following.</simpara>
10509 <programlisting language="sml" linenumbering="unnumbered">makeSum IR IR $ 1 2.2 3 4.4 = 10.6</programlisting>
10510 <simpara>In general, one can combine steps <literal>s1</literal>, <literal>s2</literal>, &#8230; <literal>sn</literal> as</simpara>
10511 <programlisting language="sml" linenumbering="unnumbered">fn u =&gt; Fold.fold u s1 s2 ... sn</programlisting>
10512 <simpara>The following calculation shows why a compound step behaves as the
10513 composition of its constituent steps.</simpara>
10514 <programlisting language="sml" linenumbering="unnumbered">fold u (fn u =&gt; fold u s1 s2 ... sn)
10515 = (fn u =&gt; fold u s1 s2 ... sn) u
10516 = fold u s1 s2 ... sn</programlisting>
10517 </section>
10518 <section id="_post_composition">
10519 <title>Post composition</title>
10520 <simpara>Suppose we already have a function defined via fold,
10521 <literal>w = fold (a, f)</literal>, and we would like to construct a new fold
10522 function that is like <literal>w</literal>, but applies <literal>g</literal> to the result
10523 produced by <literal>w</literal>. This is similar to function composition, but we
10524 can&#8217;t just do <literal>g o w</literal>, because we don&#8217;t want to use <literal>g</literal> until
10525 <literal>w</literal> has been applied to all of its arguments and received the
10526 end-of-arguments terminator <literal>$</literal>.</simpara>
10527 <simpara>More precisely, we want to define a post-composition function
10528 <literal>post</literal> that satisfies the following equation.</simpara>
10529 <programlisting language="sml" linenumbering="unnumbered">post (w, g) s1 ... sn $ = g (w s1 ... sn $)</programlisting>
10530 <simpara>Here is the definition of <literal>post</literal>.</simpara>
10531 <programlisting language="sml" linenumbering="unnumbered">structure Fold =
10532 struct
10533 open Fold
10534 fun post (w, g) s = w (fn (a, h) =&gt; s (a, g o h))
10535 end</programlisting>
10536 <simpara>The following calculations show that <literal>post</literal> satisfies the desired
10537 equation, where <literal>w = fold (a, f)</literal>.</simpara>
10538 <programlisting language="sml" linenumbering="unnumbered">post (w, g) s
10539 = w (fn (a, h) =&gt; s (a, g o h))
10540 = fold (a, f) (fn (a, h) =&gt; s (a, g o h))
10541 = (fn (a, h) =&gt; s (a, g o h)) (a, f)
10542 = s (a, g o f)
10543 = fold (a, g o f) s</programlisting>
10544 <simpara>Now, suppose <literal>si = step0 hi</literal> for <literal>i</literal> from <literal>1</literal> to <literal>n</literal>.</simpara>
10545 <programlisting language="sml" linenumbering="unnumbered">post (w, g) s1 s2 ... sn $
10546 = fold (a, g o f) s1 s2 ... sn $
10547 = (g o f) (hn (... (h1 a)))
10548 = g (f (hn (... (h1 a))))
10549 = g (fold (a, f) s1 ... sn $)
10550 = g (w s1 ... sn $)</programlisting>
10551 <simpara>For a practical example of post composition, see <link linkend="ArrayLiteral">ArrayLiteral</link>.</simpara>
10552 </section>
10553 <section id="_lift">
10554 <title>Lift</title>
10555 <simpara>We now define a peculiar-looking function, <literal>lift0</literal>, that is,
10556 equationally speaking, equivalent to the identity function on a step
10557 function.</simpara>
10558 <programlisting language="sml" linenumbering="unnumbered">fun lift0 s (a, f) = fold (fold (a, id) s $, f)</programlisting>
10559 <simpara>Using the definitions, we can prove the following equation.</simpara>
10560 <programlisting language="sml" linenumbering="unnumbered">fold (a, f) (lift0 (step0 h)) = fold (a, f) (step0 h)</programlisting>
10561 <simpara>Here is the proof.</simpara>
10562 <programlisting language="sml" linenumbering="unnumbered">fold (a, f) (lift0 (step0 h))
10563 = lift0 (step0 h) (a, f)
10564 = fold (fold (a, id) (step0 h) $, f)
10565 = fold (step0 h (a, id) $, f)
10566 = fold (fold (h a, id) $, f)
10567 = fold ($ (h a, id), f)
10568 = fold (id (h a), f)
10569 = fold (h a, f)
10570 = step0 h (a, f)
10571 = fold (a, f) (step0 h)</programlisting>
10572 <simpara>If <literal>lift0</literal> is the identity, then why even define it? The answer
10573 lies in the typing of fold expressions, which we have, until now, left
10574 unexplained.</simpara>
10575 </section>
10576 <section id="_typing">
10577 <title>Typing</title>
10578 <simpara>Perhaps the most surprising aspect of fold is that it can be checked
10579 by the SML type system. The types involved in fold expressions are
10580 complex; fortunately type inference is able to deduce them.
10581 Nevertheless, it is instructive to study the types of fold functions
10582 and steppers. More importantly, it is essential to understand the
10583 typing aspects of fold in order to write down signatures of functions
10584 defined using fold and step.</simpara>
10585 <simpara>Here is the <literal>FOLD</literal> signature, and a recapitulation of the entire
10586 <literal>Fold</literal> structure, with additional type annotations.</simpara>
10587 <programlisting language="sml" linenumbering="unnumbered">signature FOLD =
10588 sig
10589 type ('a, 'b, 'c, 'd) step = 'a * ('b -&gt; 'c) -&gt; 'd
10590 type ('a, 'b, 'c, 'd) t = ('a, 'b, 'c, 'd) step -&gt; 'd
10591 type ('a1, 'a2, 'b, 'c, 'd) step0 =
10592 ('a1, 'b, 'c, ('a2, 'b, 'c, 'd) t) step
10593 type ('a11, 'a12, 'a2, 'b, 'c, 'd) step1 =
10594 ('a12, 'b, 'c, 'a11 -&gt; ('a2, 'b, 'c, 'd) t) step
10595
10596 val fold: 'a * ('b -&gt; 'c) -&gt; ('a, 'b, 'c, 'd) t
10597 val lift0: ('a1, 'a2, 'a2, 'a2, 'a2) step0
10598 -&gt; ('a1, 'a2, 'b, 'c, 'd) step0
10599 val post: ('a, 'b, 'c1, 'd) t * ('c1 -&gt; 'c2)
10600 -&gt; ('a, 'b, 'c2, 'd) t
10601 val step0: ('a1 -&gt; 'a2) -&gt; ('a1, 'a2, 'b, 'c, 'd) step0
10602 val step1: ('a11 * 'a12 -&gt; 'a2)
10603 -&gt; ('a11, 'a12, 'a2, 'b, 'c, 'd) step1
10604 end
10605
10606 structure Fold:&gt; FOLD =
10607 struct
10608 type ('a, 'b, 'c, 'd) step = 'a * ('b -&gt; 'c) -&gt; 'd
10609
10610 type ('a, 'b, 'c, 'd) t = ('a, 'b, 'c, 'd) step -&gt; 'd
10611
10612 type ('a1, 'a2, 'b, 'c, 'd) step0 =
10613 ('a1, 'b, 'c, ('a2, 'b, 'c, 'd) t) step
10614
10615 type ('a11, 'a12, 'a2, 'b, 'c, 'd) step1 =
10616 ('a12, 'b, 'c, 'a11 -&gt; ('a2, 'b, 'c, 'd) t) step
10617
10618 fun fold (a: 'a, f: 'b -&gt; 'c)
10619 (g: ('a, 'b, 'c, 'd) step): 'd =
10620 g (a, f)
10621
10622 fun step0 (h: 'a1 -&gt; 'a2)
10623 (a1: 'a1, f: 'b -&gt; 'c): ('a2, 'b, 'c, 'd) t =
10624 fold (h a1, f)
10625
10626 fun step1 (h: 'a11 * 'a12 -&gt; 'a2)
10627 (a12: 'a12, f: 'b -&gt; 'c)
10628 (a11: 'a11): ('a2, 'b, 'c, 'd) t =
10629 fold (h (a11, a12), f)
10630
10631 fun lift0 (s: ('a1, 'a2, 'a2, 'a2, 'a2) step0)
10632 (a: 'a1, f: 'b -&gt; 'c): ('a2, 'b, 'c, 'd) t =
10633 fold (fold (a, id) s $, f)
10634
10635 fun post (w: ('a, 'b, 'c1, 'd) t,
10636 g: 'c1 -&gt; 'c2)
10637 (s: ('a, 'b, 'c2, 'd) step): 'd =
10638 w (fn (a, h) =&gt; s (a, g o h))
10639 end</programlisting>
10640 <simpara>That&#8217;s a lot to swallow, so let&#8217;s walk through it one step at a time.
10641 First, we have the definition of type <literal>Fold.step</literal>.</simpara>
10642 <programlisting language="sml" linenumbering="unnumbered">type ('a, 'b, 'c, 'd) step = 'a * ('b -&gt; 'c) -&gt; 'd</programlisting>
10643 <simpara>As a fold proceeds over its arguments, it maintains two things: the
10644 accumulator, of type <literal>'a</literal>, and the finishing function, of type
10645 <literal>'b -&gt; 'c</literal>. Each step in the fold is a function that takes those
10646 two pieces (i.e. <literal>'a * ('b -&gt; 'c)</literal> and does something to them
10647 (i.e. produces <literal>'d</literal>). The result type of the step is completely
10648 left open to be filled in by type inference, as it is an arrow type
10649 that is capable of consuming the rest of the arguments to the fold.</simpara>
10650 <simpara>A folder, of type <literal>Fold.t</literal>, is a function that consumes a single
10651 step.</simpara>
10652 <programlisting language="sml" linenumbering="unnumbered">type ('a, 'b, 'c, 'd) t = ('a, 'b, 'c, 'd) step -&gt; 'd</programlisting>
10653 <simpara>Expanding out the type, we have:</simpara>
10654 <programlisting language="sml" linenumbering="unnumbered">type ('a, 'b, 'c, 'd) t = ('a * ('b -&gt; 'c) -&gt; 'd) -&gt; 'd</programlisting>
10655 <simpara>This shows that the only thing a folder does is to hand its
10656 accumulator (<literal>'a</literal>) and finisher (<literal>'b -&gt; 'c</literal>) to the next step
10657 (<literal>'a * ('b -&gt; 'c) -&gt; 'd</literal>). If SML had <link linkend="FirstClassPolymorphism">first-class polymorphism</link>,
10658 we would write the fold type as follows.</simpara>
10659 <programlisting language="sml" linenumbering="unnumbered">type ('a, 'b, 'c) t = Forall 'd . ('a, 'b, 'c, 'd) step -&gt; 'd</programlisting>
10660 <simpara>This type definition shows that a folder had nothing to do with
10661 the rest of the fold, it only deals with the next step.</simpara>
10662 <simpara>We now can understand the type of <literal>fold</literal>, which takes the initial
10663 value of the accumulator and the finishing function, and constructs a
10664 folder, i.e. a function awaiting the next step.</simpara>
10665 <programlisting language="sml" linenumbering="unnumbered">val fold: 'a * ('b -&gt; 'c) -&gt; ('a, 'b, 'c, 'd) t
10666 fun fold (a: 'a, f: 'b -&gt; 'c)
10667 (g: ('a, 'b, 'c, 'd) step): 'd =
10668 g (a, f)</programlisting>
10669 <simpara>Continuing on, we have the type of step functions.</simpara>
10670 <programlisting language="sml" linenumbering="unnumbered">type ('a1, 'a2, 'b, 'c, 'd) step0 =
10671 ('a1, 'b, 'c, ('a2, 'b, 'c, 'd) t) step</programlisting>
10672 <simpara>Expanding out the type a bit gives:</simpara>
10673 <programlisting language="sml" linenumbering="unnumbered">type ('a1, 'a2, 'b, 'c, 'd) step0 =
10674 'a1 * ('b -&gt; 'c) -&gt; ('a2, 'b, 'c, 'd) t</programlisting>
10675 <simpara>So, a step function takes the accumulator (<literal>'a1</literal>) and finishing
10676 function (<literal>'b -&gt; 'c</literal>), which will be passed to it by the previous
10677 folder, and transforms them to a new folder. This new folder has a
10678 new accumulator (<literal>'a2</literal>) and the same finishing function.</simpara>
10679 <simpara>Again, imagining that SML had <link linkend="FirstClassPolymorphism">first-class polymorphism</link> makes the type
10680 clearer.</simpara>
10681 <programlisting language="sml" linenumbering="unnumbered">type ('a1, 'a2) step0 =
10682 Forall ('b, 'c) . ('a1, 'b, 'c, ('a2, 'b, 'c) t) step</programlisting>
10683 <simpara>Thus, in essence, a <literal>step0</literal> function is a wrapper around a
10684 function of type <literal>'a1 -&gt; 'a2</literal>, which is exactly what the
10685 definition of <literal>step0</literal> does.</simpara>
10686 <programlisting language="sml" linenumbering="unnumbered">val step0: ('a1 -&gt; 'a2) -&gt; ('a1, 'a2, 'b, 'c, 'd) step0
10687 fun step0 (h: 'a1 -&gt; 'a2)
10688 (a1: 'a1, f: 'b -&gt; 'c): ('a2, 'b, 'c, 'd) t =
10689 fold (h a1, f)</programlisting>
10690 <simpara>It is not much beyond <literal>step0</literal> to understand <literal>step1</literal>.</simpara>
10691 <programlisting language="sml" linenumbering="unnumbered">type ('a11, 'a12, 'a2, 'b, 'c, 'd) step1 =
10692 ('a12, 'b, 'c, 'a11 -&gt; ('a2, 'b, 'c, 'd) t) step</programlisting>
10693 <simpara>A <literal>step1</literal> function takes the accumulator (<literal>'a12</literal>) and finisher
10694 (<literal>'b -&gt; 'c</literal>) passed to it by the previous folder and transforms
10695 them into a function that consumes the next argument (<literal>'a11</literal>) and
10696 produces a folder that will continue the fold with a new accumulator
10697 (<literal>'a2</literal>) and the same finisher.</simpara>
10698 <programlisting language="sml" linenumbering="unnumbered">fun step1 (h: 'a11 * 'a12 -&gt; 'a2)
10699 (a12: 'a12, f: 'b -&gt; 'c)
10700 (a11: 'a11): ('a2, 'b, 'c, 'd) t =
10701 fold (h (a11, a12), f)</programlisting>
10702 <simpara>With <link linkend="FirstClassPolymorphism">first-class polymorphism</link>, a <literal>step1</literal> function is more clearly
10703 seen as a wrapper around a binary function of type
10704 <literal>'a11 * 'a12 -&gt; 'a2</literal>.</simpara>
10705 <programlisting language="sml" linenumbering="unnumbered">type ('a11, 'a12, 'a2) step1 =
10706 Forall ('b, 'c) . ('a12, 'b, 'c, 'a11 -&gt; ('a2, 'b, 'c) t) step</programlisting>
10707 <simpara>The type of <literal>post</literal> is clear: it takes a folder with a finishing
10708 function that produces type <literal>'c1</literal>, and a function of type
10709 <literal>'c1 -&gt; 'c2</literal> to postcompose onto the folder. It returns a new
10710 folder with a finishing function that produces type <literal>'c2</literal>.</simpara>
10711 <programlisting language="sml" linenumbering="unnumbered">val post: ('a, 'b, 'c1, 'd) t * ('c1 -&gt; 'c2)
10712 -&gt; ('a, 'b, 'c2, 'd) t
10713 fun post (w: ('a, 'b, 'c1, 'd) t,
10714 g: 'c1 -&gt; 'c2)
10715 (s: ('a, 'b, 'c2, 'd) step): 'd =
10716 w (fn (a, h) =&gt; s (a, g o h))</programlisting>
10717 <simpara>We will return to <literal>lift0</literal> after an example.</simpara>
10718 </section>
10719 <section id="_an_example_typing">
10720 <title>An example typing</title>
10721 <simpara>Let&#8217;s type check our simplest example, a variable-argument fold.
10722 Recall that we have a folder <literal>f</literal> and a stepper <literal>a</literal> defined as
10723 follows.</simpara>
10724 <programlisting language="sml" linenumbering="unnumbered">val f = fn z =&gt; Fold.fold ((), fn () =&gt; ()) z
10725 val a = fn z =&gt; Fold.step0 (fn () =&gt; ()) z</programlisting>
10726 <simpara>Since the accumulator and finisher are uninteresting, we&#8217;ll use some
10727 abbreviations to simplify things.</simpara>
10728 <programlisting language="sml" linenumbering="unnumbered">type 'd step = (unit, unit, unit, 'd) Fold.step
10729 type 'd fold = 'd step -&gt; 'd</programlisting>
10730 <simpara>With these abbreviations, <literal>f</literal> and <literal>a</literal> have the following polymorphic
10731 types.</simpara>
10732 <programlisting language="sml" linenumbering="unnumbered">f: 'd fold
10733 a: 'd step</programlisting>
10734 <simpara>Suppose we want to type check</simpara>
10735 <programlisting language="sml" linenumbering="unnumbered">f a a a $: unit</programlisting>
10736 <simpara>As a reminder, the fully parenthesized expression is</simpara>
10737 <programlisting language="sml" linenumbering="unnumbered">((((f a) a) a) a) $</programlisting>
10738 <simpara>The observation that we will use repeatedly is that for any type
10739 <literal>z</literal>, if <literal>f: z fold</literal> and <literal>s: z step</literal>, then <literal>f s: z</literal>.
10740 So, if we want</simpara>
10741 <programlisting language="sml" linenumbering="unnumbered">(f a a a) $: unit</programlisting>
10742 <simpara>then we must have</simpara>
10743 <programlisting language="sml" linenumbering="unnumbered">f a a a: unit fold
10744 $: unit step</programlisting>
10745 <simpara>Applying the observation again, we must have</simpara>
10746 <programlisting language="sml" linenumbering="unnumbered">f a a: unit fold fold
10747 a: unit fold step</programlisting>
10748 <simpara>Applying the observation two more times leads to the following type
10749 derivation.</simpara>
10750 <programlisting language="sml" linenumbering="unnumbered">f: unit fold fold fold fold a: unit fold fold fold step
10751 f a: unit fold fold fold a: unit fold fold step
10752 f a a: unit fold fold a: unit fold step
10753 f a a a: unit fold $: unit step
10754 f a a a $: unit</programlisting>
10755 <simpara>So, each application is a fold that consumes the next step, producing
10756 a fold of one smaller type.</simpara>
10757 <simpara>One can expand some of the type definitions in <literal>f</literal> to see that it is
10758 indeed a function that takes four curried arguments, each one a step
10759 function.</simpara>
10760 <programlisting language="sml" linenumbering="unnumbered">f: unit fold fold fold step
10761 -&gt; unit fold fold step
10762 -&gt; unit fold step
10763 -&gt; unit step
10764 -&gt; unit</programlisting>
10765 <simpara>This example shows why we must eta expand uses of <literal>fold</literal> and <literal>step0</literal>
10766 to work around the value restriction and make folders and steppers
10767 polymorphic. The type of a fold function like <literal>f</literal> depends on the
10768 number of arguments, and so will vary from use to use. Similarly,
10769 each occurrence of an argument like <literal>a</literal> has a different type,
10770 depending on the number of remaining arguments.</simpara>
10771 <simpara>This example also shows that the type of a folder, when fully
10772 expanded, is exponential in the number of arguments: there are as many
10773 nested occurrences of the <literal>fold</literal> type constructor as there are
10774 arguments, and each occurrence duplicates its type argument. One can
10775 observe this exponential behavior in a type checker that doesn&#8217;t share
10776 enough of the representation of types (e.g. one that represents types
10777 as trees rather than directed acyclic graphs).</simpara>
10778 <simpara>Generalizing this type derivation to uses of fold where the
10779 accumulator and finisher are more interesting is straightforward. One
10780 simply includes the type of the accumulator, which may change, for
10781 each step, and the type of the finisher, which doesn&#8217;t change from
10782 step to step.</simpara>
10783 </section>
10784 <section id="_typing_lift">
10785 <title>Typing lift</title>
10786 <simpara>The lack of <link linkend="FirstClassPolymorphism">first-class polymorphism</link> in SML
10787 causes problems if one wants to use a step in a first-class way.
10788 Consider the following <literal>double</literal> function, which takes a step, <literal>s</literal>, and
10789 produces a composite step that does <literal>s</literal> twice.</simpara>
10790 <programlisting language="sml" linenumbering="unnumbered">fun double s = fn u =&gt; Fold.fold u s s</programlisting>
10791 <simpara>The definition of <literal>double</literal> is not type correct. The problem is that
10792 the type of a step depends on the number of remaining arguments but
10793 that the parameter <literal>s</literal> is not polymorphic, and so can not be used in
10794 two different positions.</simpara>
10795 <simpara>Fortunately, we can define a function, <literal>lift0</literal>, that takes a monotyped
10796 step function and <emphasis>lifts</emphasis> it into a polymorphic step function. This
10797 is apparent in the type of <literal>lift0</literal>.</simpara>
10798 <programlisting language="sml" linenumbering="unnumbered">val lift0: ('a1, 'a2, 'a2, 'a2, 'a2) step0
10799 -&gt; ('a1, 'a2, 'b, 'c, 'd) step0
10800 fun lift0 (s: ('a1, 'a2, 'a2, 'a2, 'a2) step0)
10801 (a: 'a1, f: 'b -&gt; 'c): ('a2, 'b, 'c, 'd) t =
10802 fold (fold (a, id) s $, f)</programlisting>
10803 <simpara>The following definition of <literal>double</literal> uses <literal>lift0</literal>, appropriately eta
10804 wrapped, to fix the problem.</simpara>
10805 <programlisting language="sml" linenumbering="unnumbered">fun double s =
10806 let
10807 val s = fn z =&gt; Fold.lift0 s z
10808 in
10809 fn u =&gt; Fold.fold u s s
10810 end</programlisting>
10811 <simpara>With that definition of <literal>double</literal> in place, we can use it as in the
10812 following example.</simpara>
10813 <programlisting language="sml" linenumbering="unnumbered">val f = fn z =&gt; Fold.fold ((), fn () =&gt; ()) z
10814 val a = fn z =&gt; Fold.step0 (fn () =&gt; ()) z
10815 val a2 = fn z =&gt; double a z
10816 val () = f a a2 a a2 $</programlisting>
10817 <simpara>Of course, we must eta wrap the call <literal>double</literal> in order to use its
10818 result, which is a step function, polymorphically.</simpara>
10819 </section>
10820 <section id="_hiding_the_type_of_the_accumulator">
10821 <title>Hiding the type of the accumulator</title>
10822 <simpara>For clarity and to avoid mistakes, it can be useful to hide the type
10823 of the accumulator in a fold. Reworking the simple variable-argument
10824 example to do this leads to the following.</simpara>
10825 <programlisting language="sml" linenumbering="unnumbered">structure S:&gt;
10826 sig
10827 type ac
10828 val f: (ac, ac, unit, 'd) Fold.t
10829 val s: (ac, ac, 'b, 'c, 'd) Fold.step0
10830 end =
10831 struct
10832 type ac = unit
10833 val f = fn z =&gt; Fold.fold ((), fn () =&gt; ()) z
10834 val s = fn z =&gt; Fold.step0 (fn () =&gt; ()) z
10835 end</programlisting>
10836 <simpara>The idea is to name the accumulator type and use opaque signature
10837 matching to make it abstract. This can prevent improper manipulation
10838 of the accumulator by client code and ensure invariants that the
10839 folder and stepper would like to maintain.</simpara>
10840 <simpara>For a practical example of this technique, see <link linkend="ArrayLiteral">ArrayLiteral</link>.</simpara>
10841 </section>
10842 <section id="_also_see_3">
10843 <title>Also see</title>
10844 <simpara>Fold has a number of practical applications. Here are some of them.</simpara>
10845 <itemizedlist>
10846 <listitem>
10847 <simpara>
10848 <link linkend="ArrayLiteral">ArrayLiteral</link>
10849 </simpara>
10850 </listitem>
10851 <listitem>
10852 <simpara>
10853 <link linkend="Fold01N">Fold01N</link>
10854 </simpara>
10855 </listitem>
10856 <listitem>
10857 <simpara>
10858 <link linkend="FunctionalRecordUpdate">FunctionalRecordUpdate</link>
10859 </simpara>
10860 </listitem>
10861 <listitem>
10862 <simpara>
10863 <link linkend="NumericLiteral">NumericLiteral</link>
10864 </simpara>
10865 </listitem>
10866 <listitem>
10867 <simpara>
10868 <link linkend="OptionalArguments">OptionalArguments</link>
10869 </simpara>
10870 </listitem>
10871 <listitem>
10872 <simpara>
10873 <link linkend="Printf">Printf</link>
10874 </simpara>
10875 </listitem>
10876 <listitem>
10877 <simpara>
10878 <link linkend="VariableArityPolymorphism">VariableArityPolymorphism</link>
10879 </simpara>
10880 </listitem>
10881 </itemizedlist>
10882 <simpara>There are a number of related techniques. Here are some of them.</simpara>
10883 <itemizedlist>
10884 <listitem>
10885 <simpara>
10886 <link linkend="StaticSum">StaticSum</link>
10887 </simpara>
10888 </listitem>
10889 <listitem>
10890 <simpara>
10891 <link linkend="TypeIndexedValues">TypeIndexedValues</link>
10892 </simpara>
10893 </listitem>
10894 </itemizedlist>
10895 <simpara><?asciidoc-pagebreak?></simpara>
10896 </section>
10897 </section>
10898 <section id="Fold01N">
10899 <title>Fold01N</title>
10900 <simpara>A common use pattern of <link linkend="Fold">Fold</link> is to define a variable-arity
10901 function that combines multiple arguments together using a binary
10902 function. It is slightly tricky to do this directly using fold,
10903 because of the special treatment required for the case of zero or one
10904 argument. Here is a structure, <literal>Fold01N</literal>, that solves the problem
10905 once and for all, and eases the definition of such functions.</simpara>
10906 <programlisting language="sml" linenumbering="unnumbered">structure Fold01N =
10907 struct
10908 fun fold {finish, start, zero} =
10909 Fold.fold ((id, finish, fn () =&gt; zero, start),
10910 fn (finish, _, p, _) =&gt; finish (p ()))
10911
10912 fun step0 {combine, input} =
10913 Fold.step0 (fn (_, finish, _, f) =&gt;
10914 (finish,
10915 finish,
10916 fn () =&gt; f input,
10917 fn x' =&gt; combine (f input, x')))
10918
10919 fun step1 {combine} z input =
10920 step0 {combine = combine, input = input} z
10921 end</programlisting>
10922 <simpara>If one has a value <literal>zero</literal>, and functions <literal>start</literal>, <literal>c</literal>, and <literal>finish</literal>,
10923 then one can define a variable-arity function <literal>f</literal> and stepper
10924 <literal>&grave;</literal> as follows.</simpara>
10925 <programlisting language="sml" linenumbering="unnumbered">val f = fn z =&gt; Fold01N.fold {finish = finish, start = start, zero = zero} z
10926 val ` = fn z =&gt; Fold01N.step1 {combine = c} z</programlisting>
10927 <simpara>One can then use the fold equation to prove the following equations.</simpara>
10928 <programlisting language="sml" linenumbering="unnumbered">f $ = zero
10929 f `a1 $ = finish (start a1)
10930 f `a1 `a2 $ = finish (c (start a1, a2))
10931 f `a1 `a2 `a3 $ = finish (c (c (start a1, a2), a3))
10932 ...</programlisting>
10933 <simpara>For an example of <literal>Fold01N</literal>, see <link linkend="VariableArityPolymorphism">VariableArityPolymorphism</link>.</simpara>
10934 <section id="_typing_fold01n">
10935 <title>Typing Fold01N</title>
10936 <simpara>Here is the signature for <literal>Fold01N</literal>. We use a trick to avoid having
10937 to duplicate the definition of some rather complex types in both the
10938 signature and the structure. We first define the types in a
10939 structure. Then, we define them via type re-definitions in the
10940 signature, and via <literal>open</literal> in the full structure.</simpara>
10941 <programlisting language="sml" linenumbering="unnumbered">structure Fold01N =
10942 struct
10943 type ('input, 'accum1, 'accum2, 'answer, 'zero,
10944 'a, 'b, 'c, 'd, 'e) t =
10945 (('zero -&gt; 'zero)
10946 * ('accum2 -&gt; 'answer)
10947 * (unit -&gt; 'zero)
10948 * ('input -&gt; 'accum1),
10949 ('a -&gt; 'b) * 'c * (unit -&gt; 'a) * 'd,
10950 'b,
10951 'e) Fold.t
10952
10953 type ('input1, 'accum1, 'input2, 'accum2,
10954 'a, 'b, 'c, 'd, 'e, 'f) step0 =
10955 ('a * 'b * 'c * ('input1 -&gt; 'accum1),
10956 'b * 'b * (unit -&gt; 'accum1) * ('input2 -&gt; 'accum2),
10957 'd, 'e, 'f) Fold.step0
10958
10959 type ('accum1, 'input, 'accum2,
10960 'a, 'b, 'c, 'd, 'e, 'f, 'g) step1 =
10961 ('a,
10962 'b * 'c * 'd * ('a -&gt; 'accum1),
10963 'c * 'c * (unit -&gt; 'accum1) * ('input -&gt; 'accum2),
10964 'e, 'f, 'g) Fold.step1
10965 end
10966
10967 signature FOLD_01N =
10968 sig
10969 type ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j) t =
10970 ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j) Fold01N.t
10971 type ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j) step0 =
10972 ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j) Fold01N.step0
10973 type ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j) step1 =
10974 ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j) Fold01N.step1
10975
10976 val fold:
10977 {finish: 'accum2 -&gt; 'answer,
10978 start: 'input -&gt; 'accum1,
10979 zero: 'zero}
10980 -&gt; ('input, 'accum1, 'accum2, 'answer, 'zero,
10981 'a, 'b, 'c, 'd, 'e) t
10982
10983 val step0:
10984 {combine: 'accum1 * 'input2 -&gt; 'accum2,
10985 input: 'input1}
10986 -&gt; ('input1, 'accum1, 'input2, 'accum2,
10987 'a, 'b, 'c, 'd, 'e, 'f) step0
10988
10989 val step1:
10990 {combine: 'accum1 * 'input -&gt; 'accum2}
10991 -&gt; ('accum1, 'input, 'accum2,
10992 'a, 'b, 'c, 'd, 'e, 'f, 'g) step1
10993 end
10994
10995 structure Fold01N: FOLD_01N =
10996 struct
10997 open Fold01N
10998
10999 fun fold {finish, start, zero} =
11000 Fold.fold ((id, finish, fn () =&gt; zero, start),
11001 fn (finish, _, p, _) =&gt; finish (p ()))
11002
11003 fun step0 {combine, input} =
11004 Fold.step0 (fn (_, finish, _, f) =&gt;
11005 (finish,
11006 finish,
11007 fn () =&gt; f input,
11008 fn x' =&gt; combine (f input, x')))
11009
11010 fun step1 {combine} z input =
11011 step0 {combine = combine, input = input} z
11012 end</programlisting>
11013 <simpara><?asciidoc-pagebreak?></simpara>
11014 </section>
11015 </section>
11016 <section id="ForeignFunctionInterface">
11017 <title>ForeignFunctionInterface</title>
11018 <simpara>MLton&#8217;s foreign function interface (FFI) extends Standard ML and makes
11019 it easy to take the address of C global objects, access C global
11020 variables, call from SML to C, and call from C to SML. MLton also
11021 provides <link linkend="MLNLFFI">ML-NLFFI</link>, which is a higher-level FFI for calling
11022 C functions and manipulating C data from SML.</simpara>
11023 <section id="_overview">
11024 <title>Overview</title>
11025 <itemizedlist>
11026 <listitem>
11027 <simpara>
11028 <link linkend="ForeignFunctionInterfaceTypes">Foreign Function Interface Types</link>
11029 </simpara>
11030 </listitem>
11031 <listitem>
11032 <simpara>
11033 <link linkend="ForeignFunctionInterfaceSyntax">Foreign Function Interface Syntax</link>
11034 </simpara>
11035 </listitem>
11036 </itemizedlist>
11037 </section>
11038 <section id="_importing_code_into_sml">
11039 <title>Importing Code into SML</title>
11040 <itemizedlist>
11041 <listitem>
11042 <simpara>
11043 <link linkend="CallingFromSMLToC">Calling From SML To C</link>
11044 </simpara>
11045 </listitem>
11046 <listitem>
11047 <simpara>
11048 <link linkend="CallingFromSMLToCFunctionPointer">Calling From SML To C Function Pointer</link>
11049 </simpara>
11050 </listitem>
11051 </itemizedlist>
11052 </section>
11053 <section id="_exporting_code_from_sml">
11054 <title>Exporting Code from SML</title>
11055 <itemizedlist>
11056 <listitem>
11057 <simpara>
11058 <link linkend="CallingFromCToSML">Calling From C To SML</link>
11059 </simpara>
11060 </listitem>
11061 </itemizedlist>
11062 </section>
11063 <section id="_building_system_libraries">
11064 <title>Building System Libraries</title>
11065 <itemizedlist>
11066 <listitem>
11067 <simpara>
11068 <link linkend="LibrarySupport">Library Support</link>
11069 </simpara>
11070 </listitem>
11071 </itemizedlist>
11072 <simpara><?asciidoc-pagebreak?></simpara>
11073 </section>
11074 </section>
11075 <section id="ForeignFunctionInterfaceSyntax">
11076 <title>ForeignFunctionInterfaceSyntax</title>
11077 <simpara>MLton extends the syntax of SML with expressions that enable a
11078 <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link> to C. The following description of the
11079 syntax uses some abbreviations.</simpara>
11080 <informaltable
11081 frame="all"
11082 rowsep="1" colsep="1"
11083 >
11084 <tgroup cols="3">
11085 <colspec colname="col_1" colwidth="33*"/>
11086 <colspec colname="col_2" colwidth="33*"/>
11087 <colspec colname="col_3" colwidth="33*"/>
11088 <thead>
11089 <row>
11090 <entry align="left" valign="top"> C base type </entry>
11091 <entry align="left" valign="top"> <emphasis>cBaseTy</emphasis> </entry>
11092 <entry align="left" valign="top"> <link linkend="ForeignFunctionInterfaceTypes">Foreign Function Interface types</link></entry>
11093 </row>
11094 </thead>
11095 <tbody>
11096 <row>
11097 <entry align="left" valign="top"><simpara>C argument type</simpara></entry>
11098 <entry align="left" valign="top"><simpara><emphasis>cArgTy</emphasis></simpara></entry>
11099 <entry align="left" valign="top"><simpara><emphasis>cBaseTy</emphasis><subscript>1</subscript> <literal>*</literal> &#8230; <literal>*</literal> <emphasis>cBaseTy</emphasis><subscript>n</subscript> or <literal>unit</literal></simpara></entry>
11100 </row>
11101 <row>
11102 <entry align="left" valign="top"><simpara>C return type</simpara></entry>
11103 <entry align="left" valign="top"><simpara><emphasis>cRetTy</emphasis></simpara></entry>
11104 <entry align="left" valign="top"><simpara><emphasis>cBaseTy</emphasis> or <literal>unit</literal></simpara></entry>
11105 </row>
11106 <row>
11107 <entry align="left" valign="top"><simpara>C function type</simpara></entry>
11108 <entry align="left" valign="top"><simpara><emphasis>cFuncTy</emphasis></simpara></entry>
11109 <entry align="left" valign="top"><simpara><emphasis>cArgTy</emphasis> <literal>-&gt;</literal> <emphasis>cRetTy</emphasis></simpara></entry>
11110 </row>
11111 <row>
11112 <entry align="left" valign="top"><simpara>C pointer type</simpara></entry>
11113 <entry align="left" valign="top"><simpara><emphasis>cPtrTy</emphasis></simpara></entry>
11114 <entry align="left" valign="top"><simpara><literal>MLton.Pointer.t</literal></simpara></entry>
11115 </row>
11116 </tbody>
11117 </tgroup>
11118 </informaltable>
11119 <simpara>The type annotation and the semicolon are not optional in the syntax
11120 of <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link> expressions. However, the type is
11121 lexed, parsed, and elaborated as an SML type, so any type (including
11122 type abbreviations) may be used, so long as it elaborates to a type of
11123 the correct form.</simpara>
11124 <section id="_address">
11125 <title>Address</title>
11126 <screen>_address "CFunctionOrVariableName" attr... : cPtrTy;</screen>
11127 <simpara>Denotes the address of the C function or variable.</simpara>
11128 <simpara><literal>attr...</literal> denotes a (possibly empty) sequence of attributes. The following attributes are recognized:</simpara>
11129 <itemizedlist>
11130 <listitem>
11131 <simpara>
11132 <literal>external</literal> : import with external symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>) (default).
11133 </simpara>
11134 </listitem>
11135 <listitem>
11136 <simpara>
11137 <literal>private</literal> : import with private symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>).
11138 </simpara>
11139 </listitem>
11140 <listitem>
11141 <simpara>
11142 <literal>public</literal> : import with public symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>).
11143 </simpara>
11144 </listitem>
11145 </itemizedlist>
11146 <simpara>See <link linkend="MLtonPointer">MLtonPointer</link> for functions that manipulate C pointers.</simpara>
11147 </section>
11148 <section id="_symbol">
11149 <title>Symbol</title>
11150 <screen>_symbol "CVariableName" attr... : (unit -&gt; cBaseTy) * (cBaseTy -&gt; unit);</screen>
11151 <simpara>Denotes the <emphasis>getter</emphasis> and <emphasis>setter</emphasis> for a C variable. The <emphasis>cBaseTy</emphasis>s
11152 must be identical.</simpara>
11153 <simpara><literal>attr...</literal> denotes a (possibly empty) sequence of attributes. The following attributes are recognized:</simpara>
11154 <itemizedlist>
11155 <listitem>
11156 <simpara>
11157 <literal>alloc</literal> : allocate storage (and export a symbol) for the C variable.
11158 </simpara>
11159 </listitem>
11160 <listitem>
11161 <simpara>
11162 <literal>external</literal> : import or export with external symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>) (default if not <literal>alloc</literal>).
11163 </simpara>
11164 </listitem>
11165 <listitem>
11166 <simpara>
11167 <literal>private</literal> : import or export with private symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>).
11168 </simpara>
11169 </listitem>
11170 <listitem>
11171 <simpara>
11172 <literal>public</literal> : import or export with public symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>) (default if <literal>alloc</literal>).
11173 </simpara>
11174 </listitem>
11175 </itemizedlist>
11176 <screen>_symbol * : cPtrTy -&gt; (unit -&gt; cBaseTy) * (cBaseTy -&gt; unit);</screen>
11177 <simpara>Denotes the <emphasis>getter</emphasis> and <emphasis>setter</emphasis> for a C pointer to a variable.
11178 The <emphasis>cBaseTy</emphasis>s must be identical.</simpara>
11179 </section>
11180 <section id="_import">
11181 <title>Import</title>
11182 <screen>_import "CFunctionName" attr... : cFuncTy;</screen>
11183 <simpara>Denotes an SML function whose behavior is implemented by calling the C
11184 function. See <link linkend="CallingFromSMLToC">Calling from SML to C</link> for more
11185 details.</simpara>
11186 <simpara><literal>attr...</literal> denotes a (possibly empty) sequence of attributes. The following attributes are recognized:</simpara>
11187 <itemizedlist>
11188 <listitem>
11189 <simpara>
11190 <literal>cdecl</literal> : call with the <literal>cdecl</literal> calling convention (default).
11191 </simpara>
11192 </listitem>
11193 <listitem>
11194 <simpara>
11195 <literal>external</literal> : import with external symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>) (default).
11196 </simpara>
11197 </listitem>
11198 <listitem>
11199 <simpara>
11200 <literal>impure</literal>: assert that the function depends upon state and/or performs side effects (default).
11201 </simpara>
11202 </listitem>
11203 <listitem>
11204 <simpara>
11205 <literal>private</literal> : import with private symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>).
11206 </simpara>
11207 </listitem>
11208 <listitem>
11209 <simpara>
11210 <literal>public</literal> : import with public symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>).
11211 </simpara>
11212 </listitem>
11213 <listitem>
11214 <simpara>
11215 <literal>pure</literal>: assert that the function does not depend upon state or perform any side effects; such functions are subject to various optimizations (e.g., <link linkend="CommonSubexp">CommonSubexp</link>, <link linkend="RemoveUnused">RemoveUnused</link>)
11216 </simpara>
11217 </listitem>
11218 <listitem>
11219 <simpara>
11220 <literal>reentrant</literal>: assert that the function (directly or indirectly) calls an <literal>_export</literal>-ed SML function.
11221 </simpara>
11222 </listitem>
11223 <listitem>
11224 <simpara>
11225 <literal>stdcall</literal> : call with the <literal>stdcall</literal> calling convention (ignored except on Cygwin and MinGW).
11226 </simpara>
11227 </listitem>
11228 </itemizedlist>
11229 <screen>_import * attr... : cPtrTy -&gt; cFuncTy;</screen>
11230 <simpara>Denotes an SML function whose behavior is implemented by calling a C
11231 function through a C function pointer.</simpara>
11232 <simpara><literal>attr...</literal> denotes a (possibly empty) sequence of attributes. The following attributes are recognized:</simpara>
11233 <itemizedlist>
11234 <listitem>
11235 <simpara>
11236 <literal>cdecl</literal> : call with the <literal>cdecl</literal> calling convention (default).
11237 </simpara>
11238 </listitem>
11239 <listitem>
11240 <simpara>
11241 <literal>impure</literal>: assert that the function depends upon state and/or performs side effects (default).
11242 </simpara>
11243 </listitem>
11244 <listitem>
11245 <simpara>
11246 <literal>pure</literal>: assert that the function does not depend upon state or perform any side effects; such functions are subject to various optimizations (e.g., <link linkend="CommonSubexp">CommonSubexp</link>, <link linkend="RemoveUnused">RemoveUnused</link>)
11247 </simpara>
11248 </listitem>
11249 <listitem>
11250 <simpara>
11251 <literal>reentrant</literal>: assert that the function (directly or indirectly) calls an <literal>_export</literal>-ed SML function.
11252 </simpara>
11253 </listitem>
11254 <listitem>
11255 <simpara>
11256 <literal>stdcall</literal> : call with the <literal>stdcall</literal> calling convention (ignored except on Cygwin and MinGW).
11257 </simpara>
11258 </listitem>
11259 </itemizedlist>
11260 <simpara>See
11261 <link linkend="CallingFromSMLToCFunctionPointer">Calling from SML to C function pointer</link>
11262 for more details.</simpara>
11263 </section>
11264 <section id="_export">
11265 <title>Export</title>
11266 <screen>_export "CFunctionName" attr... : cFuncTy -&gt; unit;</screen>
11267 <simpara>Exports a C function with the name <literal>CFunctionName</literal> that can be used to
11268 call an SML function of the type <emphasis>cFuncTy</emphasis>. When the function denoted
11269 by the export expression is applied to an SML function <literal>f</literal>, subsequent
11270 C calls to <literal>CFunctionName</literal> will call <literal>f</literal>. It is an error to call
11271 <literal>CFunctionName</literal> before the export has been applied. The export may be
11272 applied more than once, with each application replacing any previous
11273 definition of <literal>CFunctionName</literal>.</simpara>
11274 <simpara><literal>attr...</literal> denotes a (possibly empty) sequence of attributes. The following attributes are recognized:</simpara>
11275 <itemizedlist>
11276 <listitem>
11277 <simpara>
11278 <literal>cdecl</literal> : call with the <literal>cdecl</literal> calling convention (default).
11279 </simpara>
11280 </listitem>
11281 <listitem>
11282 <simpara>
11283 <literal>private</literal> : export with private symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>).
11284 </simpara>
11285 </listitem>
11286 <listitem>
11287 <simpara>
11288 <literal>public</literal> : export with public symbol scope (see <link linkend="LibrarySupport">LibrarySupport</link>) (default).
11289 </simpara>
11290 </listitem>
11291 <listitem>
11292 <simpara>
11293 <literal>stdcall</literal> : call with the <literal>stdcall</literal> calling convention (ignored except on Cygwin and MinGW).
11294 </simpara>
11295 </listitem>
11296 </itemizedlist>
11297 <simpara>See <link linkend="CallingFromCToSML">Calling from C to SML</link> for more details.</simpara>
11298 <simpara><?asciidoc-pagebreak?></simpara>
11299 </section>
11300 </section>
11301 <section id="ForeignFunctionInterfaceTypes">
11302 <title>ForeignFunctionInterfaceTypes</title>
11303 <simpara>MLton&#8217;s <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link> only allows values of certain SML
11304 types to be passed between SML and C. The following types are
11305 allowed: <literal>bool</literal>, <literal>char</literal>, <literal>int</literal>, <literal>real</literal>, <literal>word</literal>. All of the different
11306 sizes of (fixed-sized) integers, reals, and words are supported as
11307 well: <literal>Int8.int</literal>, <literal>Int16.int</literal>, <literal>Int32.int</literal>, <literal>Int64.int</literal>,
11308 <literal>Real32.real</literal>, <literal>Real64.real</literal>, <literal>Word8.word</literal>, <literal>Word16.word</literal>,
11309 <literal>Word32.word</literal>, <literal>Word64.word</literal>. There is a special type,
11310 <literal>MLton.Pointer.t</literal>, for passing C pointers&#8201;&#8212;&#8201;see <link linkend="MLtonPointer">MLtonPointer</link> for
11311 details.</simpara>
11312 <simpara>Arrays, refs, and vectors of the above types are also allowed.
11313 Because in MLton monomorphic arrays and vectors are exactly the same
11314 as their polymorphic counterpart, these are also allowed. Hence,
11315 <literal>string</literal>, <literal>char vector</literal>, and <literal>CharVector.vector</literal> are also allowed.
11316 Strings are not null terminated, unless you manually do so from the
11317 SML side.</simpara>
11318 <simpara>Unfortunately, passing tuples or datatypes is not allowed because that
11319 would interfere with representation optimizations.</simpara>
11320 <simpara>The C header file that <literal>-export-header</literal> generates includes
11321 <literal>typedef</literal>s for the C types corresponding to the SML types. Here is
11322 the mapping between SML types and C types.</simpara>
11323 <informaltable
11324 frame="all"
11325 rowsep="1" colsep="1"
11326 >
11327 <tgroup cols="4">
11328 <colspec colname="col_1" colwidth="25*"/>
11329 <colspec colname="col_2" colwidth="25*"/>
11330 <colspec colname="col_3" colwidth="25*"/>
11331 <colspec colname="col_4" colwidth="25*"/>
11332 <thead>
11333 <row>
11334 <entry align="left" valign="top"> SML type </entry>
11335 <entry align="left" valign="top"> C typedef </entry>
11336 <entry align="left" valign="top"> C type </entry>
11337 <entry align="left" valign="top"> Note</entry>
11338 </row>
11339 </thead>
11340 <tbody>
11341 <row>
11342 <entry align="left" valign="top"><simpara><literal>array</literal></simpara></entry>
11343 <entry align="left" valign="top"><simpara><literal>Pointer</literal></simpara></entry>
11344 <entry align="left" valign="top"><simpara><literal>unsigned char *</literal></simpara></entry>
11345 <entry align="left" valign="top"><simpara></simpara></entry>
11346 </row>
11347 <row>
11348 <entry align="left" valign="top"><simpara><literal>bool</literal></simpara></entry>
11349 <entry align="left" valign="top"><simpara><literal>Bool</literal></simpara></entry>
11350 <entry align="left" valign="top"><simpara><literal>int32_t</literal></simpara></entry>
11351 <entry align="left" valign="top"><simpara></simpara></entry>
11352 </row>
11353 <row>
11354 <entry align="left" valign="top"><simpara><literal>char</literal></simpara></entry>
11355 <entry align="left" valign="top"><simpara><literal>Char8</literal></simpara></entry>
11356 <entry align="left" valign="top"><simpara><literal>uint8_t</literal></simpara></entry>
11357 <entry align="left" valign="top"><simpara></simpara></entry>
11358 </row>
11359 <row>
11360 <entry align="left" valign="top"><simpara><literal>Int8.int</literal></simpara></entry>
11361 <entry align="left" valign="top"><simpara><literal>Int8</literal></simpara></entry>
11362 <entry align="left" valign="top"><simpara><literal>int8_t</literal></simpara></entry>
11363 <entry align="left" valign="top"><simpara></simpara></entry>
11364 </row>
11365 <row>
11366 <entry align="left" valign="top"><simpara><literal>Int16.int</literal></simpara></entry>
11367 <entry align="left" valign="top"><simpara><literal>Int16</literal></simpara></entry>
11368 <entry align="left" valign="top"><simpara><literal>int16_t</literal></simpara></entry>
11369 <entry align="left" valign="top"><simpara></simpara></entry>
11370 </row>
11371 <row>
11372 <entry align="left" valign="top"><simpara><literal>Int32.int</literal></simpara></entry>
11373 <entry align="left" valign="top"><simpara><literal>Int32</literal></simpara></entry>
11374 <entry align="left" valign="top"><simpara><literal>int32_t</literal></simpara></entry>
11375 <entry align="left" valign="top"><simpara></simpara></entry>
11376 </row>
11377 <row>
11378 <entry align="left" valign="top"><simpara><literal>Int64.int</literal></simpara></entry>
11379 <entry align="left" valign="top"><simpara><literal>Int64</literal></simpara></entry>
11380 <entry align="left" valign="top"><simpara><literal>int64_t</literal></simpara></entry>
11381 <entry align="left" valign="top"><simpara></simpara></entry>
11382 </row>
11383 <row>
11384 <entry align="left" valign="top"><simpara><literal>int</literal></simpara></entry>
11385 <entry align="left" valign="top"><simpara><literal>Int32</literal></simpara></entry>
11386 <entry align="left" valign="top"><simpara><literal>int32_t</literal></simpara></entry>
11387 <entry align="left" valign="top"><simpara><link linkend="ForeignFunctionInterfaceTypes_Default">(default)</link></simpara></entry>
11388 </row>
11389 <row>
11390 <entry align="left" valign="top"><simpara><literal>MLton.Pointer.t</literal></simpara></entry>
11391 <entry align="left" valign="top"><simpara><literal>Pointer</literal></simpara></entry>
11392 <entry align="left" valign="top"><simpara><literal>unsigned char *</literal></simpara></entry>
11393 <entry align="left" valign="top"><simpara></simpara></entry>
11394 </row>
11395 <row>
11396 <entry align="left" valign="top"><simpara><literal>Real32.real</literal></simpara></entry>
11397 <entry align="left" valign="top"><simpara><literal>Real32</literal></simpara></entry>
11398 <entry align="left" valign="top"><simpara><literal>float</literal></simpara></entry>
11399 <entry align="left" valign="top"><simpara></simpara></entry>
11400 </row>
11401 <row>
11402 <entry align="left" valign="top"><simpara><literal>Real64.real</literal></simpara></entry>
11403 <entry align="left" valign="top"><simpara><literal>Real64</literal></simpara></entry>
11404 <entry align="left" valign="top"><simpara><literal>double</literal></simpara></entry>
11405 <entry align="left" valign="top"><simpara></simpara></entry>
11406 </row>
11407 <row>
11408 <entry align="left" valign="top"><simpara><literal>real</literal></simpara></entry>
11409 <entry align="left" valign="top"><simpara><literal>Real64</literal></simpara></entry>
11410 <entry align="left" valign="top"><simpara><literal>double</literal></simpara></entry>
11411 <entry align="left" valign="top"><simpara><link linkend="ForeignFunctionInterfaceTypes_Default">(default)</link></simpara></entry>
11412 </row>
11413 <row>
11414 <entry align="left" valign="top"><simpara><literal>ref</literal></simpara></entry>
11415 <entry align="left" valign="top"><simpara><literal>Pointer</literal></simpara></entry>
11416 <entry align="left" valign="top"><simpara><literal>unsigned char *</literal></simpara></entry>
11417 <entry align="left" valign="top"><simpara></simpara></entry>
11418 </row>
11419 <row>
11420 <entry align="left" valign="top"><simpara><literal>string</literal></simpara></entry>
11421 <entry align="left" valign="top"><simpara><literal>Pointer</literal></simpara></entry>
11422 <entry align="left" valign="top"><simpara><literal>unsigned char *</literal></simpara></entry>
11423 <entry align="left" valign="top"><simpara><link linkend="ForeignFunctionInterfaceTypes_ReadOnly">(read only)</link></simpara></entry>
11424 </row>
11425 <row>
11426 <entry align="left" valign="top"><simpara><literal>vector</literal></simpara></entry>
11427 <entry align="left" valign="top"><simpara><literal>Pointer</literal></simpara></entry>
11428 <entry align="left" valign="top"><simpara><literal>unsigned char *</literal></simpara></entry>
11429 <entry align="left" valign="top"><simpara><link linkend="ForeignFunctionInterfaceTypes_ReadOnly">(read only)</link></simpara></entry>
11430 </row>
11431 <row>
11432 <entry align="left" valign="top"><simpara><literal>Word8.word</literal></simpara></entry>
11433 <entry align="left" valign="top"><simpara><literal>Word8</literal></simpara></entry>
11434 <entry align="left" valign="top"><simpara><literal>uint8_t</literal></simpara></entry>
11435 <entry align="left" valign="top"><simpara></simpara></entry>
11436 </row>
11437 <row>
11438 <entry align="left" valign="top"><simpara><literal>Word16.word</literal></simpara></entry>
11439 <entry align="left" valign="top"><simpara><literal>Word16</literal></simpara></entry>
11440 <entry align="left" valign="top"><simpara><literal>uint16_t</literal></simpara></entry>
11441 <entry align="left" valign="top"><simpara></simpara></entry>
11442 </row>
11443 <row>
11444 <entry align="left" valign="top"><simpara><literal>Word32.word</literal></simpara></entry>
11445 <entry align="left" valign="top"><simpara><literal>Word32</literal></simpara></entry>
11446 <entry align="left" valign="top"><simpara><literal>uint32_t</literal></simpara></entry>
11447 <entry align="left" valign="top"><simpara></simpara></entry>
11448 </row>
11449 <row>
11450 <entry align="left" valign="top"><simpara><literal>Word64.word</literal></simpara></entry>
11451 <entry align="left" valign="top"><simpara><literal>Word64</literal></simpara></entry>
11452 <entry align="left" valign="top"><simpara><literal>uint64_t</literal></simpara></entry>
11453 <entry align="left" valign="top"><simpara></simpara></entry>
11454 </row>
11455 <row>
11456 <entry align="left" valign="top"><simpara><literal>word</literal></simpara></entry>
11457 <entry align="left" valign="top"><simpara><literal>Word32</literal></simpara></entry>
11458 <entry align="left" valign="top"><simpara><literal>uint32_t</literal></simpara></entry>
11459 <entry align="left" valign="top"><simpara><link linkend="ForeignFunctionInterfaceTypes_Default">(default)</link></simpara></entry>
11460 </row>
11461 </tbody>
11462 </tgroup>
11463 </informaltable>
11464 <simpara><anchor id="ForeignFunctionInterfaceTypes_Default" xreflabel="[ForeignFunctionInterfaceTypes_Default]"/>Note (default): The default <literal>int</literal>, <literal>real</literal>, and
11465 <literal>word</literal> types may be set by the <literal>-default-type <emphasis>type</emphasis></literal>
11466 <link linkend="CompileTimeOptions">compiler option</link>. The given C typedef and C
11467 types correspond to the default behavior.</simpara>
11468 <simpara><anchor id="ForeignFunctionInterfaceTypes_ReadOnly" xreflabel="[ForeignFunctionInterfaceTypes_ReadOnly]"/>Note (read only): Because MLton assumes that
11469 vectors and strings are read-only (and will perform optimizations
11470 that, for instance, cause them to share space), you must not modify
11471 the data pointed to by the <literal>unsigned char *</literal> in C code.</simpara>
11472 <simpara>Although the C type of an array, ref, or vector is always <literal>Pointer</literal>,
11473 in reality, the object has the natural C representation. Your C code
11474 should cast to the appropriate C type if you want to keep the C
11475 compiler from complaining.</simpara>
11476 <simpara>When calling an <link linkend="CallingFromSMLToC">imported C function from SML</link>
11477 that returns an array, ref, or vector result or when calling an
11478 <link linkend="CallingFromCToSML">exported SML function from C</link> that takes an
11479 array, ref, or string argument, then the object must be an ML object
11480 allocated on the ML heap. (Although an array, ref, or vector object
11481 has the natural C representation, the object also has an additional
11482 header used by the SML runtime system.)</simpara>
11483 <simpara>In addition, there is an <link linkend="MLBasis">MLBasis</link> file, <literal>$(SML_LIB)/basis/c-types.mlb</literal>,
11484 which provides structure aliases for various C types:</simpara>
11485 <informaltable
11486 frame="all"
11487 rowsep="1" colsep="1"
11488 >
11489 <tgroup cols="3">
11490 <colspec colname="col_1" colwidth="33*"/>
11491 <colspec colname="col_2" colwidth="33*"/>
11492 <colspec colname="col_3" colwidth="33*"/>
11493 <tbody>
11494 <row>
11495 <entry align="left" valign="top"><simpara>C type</simpara></entry>
11496 <entry align="left" valign="top"><simpara>Structure</simpara></entry>
11497 <entry align="left" valign="top"><simpara>Signature</simpara></entry>
11498 </row>
11499 <row>
11500 <entry align="left" valign="top"><simpara><literal>char</literal></simpara></entry>
11501 <entry align="left" valign="top"><simpara><literal>C_Char</literal></simpara></entry>
11502 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11503 </row>
11504 <row>
11505 <entry align="left" valign="top"><simpara><literal>signed char</literal></simpara></entry>
11506 <entry align="left" valign="top"><simpara><literal>C_SChar</literal></simpara></entry>
11507 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11508 </row>
11509 <row>
11510 <entry align="left" valign="top"><simpara><literal>unsigned char</literal></simpara></entry>
11511 <entry align="left" valign="top"><simpara><literal>C_UChar</literal></simpara></entry>
11512 <entry align="left" valign="top"><simpara><literal>WORD</literal></simpara></entry>
11513 </row>
11514 <row>
11515 <entry align="left" valign="top"><simpara><literal>short</literal></simpara></entry>
11516 <entry align="left" valign="top"><simpara><literal>C_Short</literal></simpara></entry>
11517 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11518 </row>
11519 <row>
11520 <entry align="left" valign="top"><simpara><literal>signed short</literal></simpara></entry>
11521 <entry align="left" valign="top"><simpara><literal>C_SShort</literal></simpara></entry>
11522 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11523 </row>
11524 <row>
11525 <entry align="left" valign="top"><simpara><literal>unsigned short</literal></simpara></entry>
11526 <entry align="left" valign="top"><simpara><literal>C_UShort</literal></simpara></entry>
11527 <entry align="left" valign="top"><simpara><literal>WORD</literal></simpara></entry>
11528 </row>
11529 <row>
11530 <entry align="left" valign="top"><simpara><literal>int</literal></simpara></entry>
11531 <entry align="left" valign="top"><simpara><literal>C_Int</literal></simpara></entry>
11532 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11533 </row>
11534 <row>
11535 <entry align="left" valign="top"><simpara><literal>signed int</literal></simpara></entry>
11536 <entry align="left" valign="top"><simpara><literal>C_SInt</literal></simpara></entry>
11537 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11538 </row>
11539 <row>
11540 <entry align="left" valign="top"><simpara><literal>unsigned int</literal></simpara></entry>
11541 <entry align="left" valign="top"><simpara><literal>C_UInt</literal></simpara></entry>
11542 <entry align="left" valign="top"><simpara><literal>WORD</literal></simpara></entry>
11543 </row>
11544 <row>
11545 <entry align="left" valign="top"><simpara><literal>long</literal></simpara></entry>
11546 <entry align="left" valign="top"><simpara><literal>C_Long</literal></simpara></entry>
11547 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11548 </row>
11549 <row>
11550 <entry align="left" valign="top"><simpara><literal>signed long</literal></simpara></entry>
11551 <entry align="left" valign="top"><simpara><literal>C_SLong</literal></simpara></entry>
11552 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11553 </row>
11554 <row>
11555 <entry align="left" valign="top"><simpara><literal>unsigned long</literal></simpara></entry>
11556 <entry align="left" valign="top"><simpara><literal>C_ULong</literal></simpara></entry>
11557 <entry align="left" valign="top"><simpara><literal>WORD</literal></simpara></entry>
11558 </row>
11559 <row>
11560 <entry align="left" valign="top"><simpara><literal>long long</literal></simpara></entry>
11561 <entry align="left" valign="top"><simpara><literal>C_LongLong</literal></simpara></entry>
11562 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11563 </row>
11564 <row>
11565 <entry align="left" valign="top"><simpara><literal>signed long long</literal></simpara></entry>
11566 <entry align="left" valign="top"><simpara><literal>C_SLongLong</literal></simpara></entry>
11567 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11568 </row>
11569 <row>
11570 <entry align="left" valign="top"><simpara><literal>unsigned long long</literal></simpara></entry>
11571 <entry align="left" valign="top"><simpara><literal>C_ULongLong</literal></simpara></entry>
11572 <entry align="left" valign="top"><simpara><literal>WORD</literal></simpara></entry>
11573 </row>
11574 <row>
11575 <entry align="left" valign="top"><simpara><literal>float</literal></simpara></entry>
11576 <entry align="left" valign="top"><simpara><literal>C_Float</literal></simpara></entry>
11577 <entry align="left" valign="top"><simpara><literal>REAL</literal></simpara></entry>
11578 </row>
11579 <row>
11580 <entry align="left" valign="top"><simpara><literal>double</literal></simpara></entry>
11581 <entry align="left" valign="top"><simpara><literal>C_Double</literal></simpara></entry>
11582 <entry align="left" valign="top"><simpara><literal>REAL</literal></simpara></entry>
11583 </row>
11584 <row>
11585 <entry align="left" valign="top"><simpara><literal>size_t</literal></simpara></entry>
11586 <entry align="left" valign="top"><simpara><literal>C_Size</literal></simpara></entry>
11587 <entry align="left" valign="top"><simpara><literal>WORD</literal></simpara></entry>
11588 </row>
11589 <row>
11590 <entry align="left" valign="top"><simpara><literal>ptrdiff_t</literal></simpara></entry>
11591 <entry align="left" valign="top"><simpara><literal>C_Ptrdiff</literal></simpara></entry>
11592 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11593 </row>
11594 <row>
11595 <entry align="left" valign="top"><simpara><literal>intmax_t</literal></simpara></entry>
11596 <entry align="left" valign="top"><simpara><literal>C_Intmax</literal></simpara></entry>
11597 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11598 </row>
11599 <row>
11600 <entry align="left" valign="top"><simpara><literal>uintmax_t</literal></simpara></entry>
11601 <entry align="left" valign="top"><simpara><literal>C_UIntmax</literal></simpara></entry>
11602 <entry align="left" valign="top"><simpara><literal>WORD</literal></simpara></entry>
11603 </row>
11604 <row>
11605 <entry align="left" valign="top"><simpara><literal>intptr_t</literal></simpara></entry>
11606 <entry align="left" valign="top"><simpara><literal>C_Intptr</literal></simpara></entry>
11607 <entry align="left" valign="top"><simpara><literal>INTEGER</literal></simpara></entry>
11608 </row>
11609 <row>
11610 <entry align="left" valign="top"><simpara><literal>uintptr_t</literal></simpara></entry>
11611 <entry align="left" valign="top"><simpara><literal>C_UIntptr</literal></simpara></entry>
11612 <entry align="left" valign="top"><simpara><literal>WORD</literal></simpara></entry>
11613 </row>
11614 <row>
11615 <entry align="left" valign="top"><simpara><literal>void *</literal></simpara></entry>
11616 <entry align="left" valign="top"><simpara><literal>C_Pointer</literal></simpara></entry>
11617 <entry align="left" valign="top"><simpara><literal>WORD</literal></simpara></entry>
11618 </row>
11619 </tbody>
11620 </tgroup>
11621 </informaltable>
11622 <simpara>These aliases depend on the configuration of the C compiler for the
11623 target architecture, and are independent of the configuration of MLton
11624 (including the <literal>-default-type <emphasis>type</emphasis></literal>
11625 <link linkend="CompileTimeOptions">compiler option</link>).</simpara>
11626 <simpara><?asciidoc-pagebreak?></simpara>
11627 </section>
11628 <section id="ForLoops">
11629 <title>ForLoops</title>
11630 <simpara>A <literal>for</literal>-loop is typically used to iterate over a range of consecutive
11631 integers that denote indices of some sort. For example, in <link linkend="OCaml">OCaml</link>
11632 a <literal>for</literal>-loop takes either the form</simpara>
11633 <screen>for &lt;name&gt; = &lt;lower&gt; to &lt;upper&gt; do &lt;body&gt; done</screen>
11634 <simpara>or the form</simpara>
11635 <screen>for &lt;name&gt; = &lt;upper&gt; downto &lt;lower&gt; do &lt;body&gt; done</screen>
11636 <simpara>Some languages provide considerably more flexible <literal>for</literal>-loop or
11637 <literal>foreach</literal>-constructs.</simpara>
11638 <simpara>A bit surprisingly, <link linkend="StandardML">Standard ML</link> provides special syntax
11639 for <literal>while</literal>-loops, but not for <literal>for</literal>-loops. Indeed, in SML, many uses
11640 of <literal>for</literal>-loops are better expressed using <literal>app</literal>, <literal>foldl</literal>/<literal>foldr</literal>,
11641 <literal>map</literal> and many other higher-order functions provided by the
11642 <link linkend="BasisLibrary">Basis Library</link> for manipulating lists, vectors and
11643 arrays. However, the Basis Library does not provide a function for
11644 iterating over a range of integer values. Fortunately, it is very
11645 easy to write one.</simpara>
11646 <section id="_a_fairly_simple_design">
11647 <title>A fairly simple design</title>
11648 <simpara>The following implementation imitates both the syntax and semantics of
11649 the OCaml <literal>for</literal>-loop.</simpara>
11650 <programlisting language="sml" linenumbering="unnumbered">datatype for = to of int * int
11651 | downto of int * int
11652
11653 infix to downto
11654
11655 val for =
11656 fn lo to up =&gt;
11657 (fn f =&gt; let fun loop lo = if lo &gt; up then ()
11658 else (f lo; loop (lo+1))
11659 in loop lo end)
11660 | up downto lo =&gt;
11661 (fn f =&gt; let fun loop up = if up &lt; lo then ()
11662 else (f up; loop (up-1))
11663 in loop up end)</programlisting>
11664 <simpara>For example,</simpara>
11665 <programlisting language="sml" linenumbering="unnumbered">for (1 to 9)
11666 (fn i =&gt; print (Int.toString i))</programlisting>
11667 <simpara>would print <literal>123456789</literal> and</simpara>
11668 <programlisting language="sml" linenumbering="unnumbered">for (9 downto 1)
11669 (fn i =&gt; print (Int.toString i))</programlisting>
11670 <simpara>would print <literal>987654321</literal>.</simpara>
11671 <simpara>Straightforward formatting of nested loops</simpara>
11672 <programlisting language="sml" linenumbering="unnumbered">for (a to b)
11673 (fn i =&gt;
11674 for (c to d)
11675 (fn j =&gt;
11676 ...))</programlisting>
11677 <simpara>is fairly readable, but tends to cause the body of the loop to be
11678 indented quite deeply.</simpara>
11679 </section>
11680 <section id="_off_by_one">
11681 <title>Off-by-one</title>
11682 <simpara>The above design has an annoying feature. In practice, the upper
11683 bound of the iterated range is almost always excluded and most loops
11684 would subtract one from the upper bound:</simpara>
11685 <programlisting language="sml" linenumbering="unnumbered">for (0 to n-1) ...
11686 for (n-1 downto 0) ...</programlisting>
11687 <simpara>It is probably better to break convention and exclude the upper bound
11688 by default, because it leads to more concise code and becomes
11689 idiomatic with very little practice. The iterator combinators
11690 described below exclude the upper bound by default.</simpara>
11691 </section>
11692 <section id="_iterator_combinators">
11693 <title>Iterator combinators</title>
11694 <simpara>While the simple <literal>for</literal>-function described in the previous section is
11695 probably good enough for many uses, it is a bit cumbersome when one
11696 needs to iterate over a Cartesian product. One might also want to
11697 iterate over more than just consecutive integers. It turns out that
11698 one can provide a library of iterator combinators that allow one to
11699 implement iterators more flexibly.</simpara>
11700 <simpara>Since the types of the combinators may be a bit difficult to infer
11701 from their implementations, let&#8217;s first take a look at a signature of
11702 the iterator combinator library:</simpara>
11703 <programlisting language="sml" linenumbering="unnumbered">signature ITER =
11704 sig
11705 type 'a t = ('a -&gt; unit) -&gt; unit
11706
11707 val return : 'a -&gt; 'a t
11708 val &gt;&gt;= : 'a t * ('a -&gt; 'b t) -&gt; 'b t
11709
11710 val none : 'a t
11711
11712 val to : int * int -&gt; int t
11713 val downto : int * int -&gt; int t
11714
11715 val inList : 'a list -&gt; 'a t
11716 val inVector : 'a vector -&gt; 'a t
11717 val inArray : 'a array -&gt; 'a t
11718
11719 val using : ('a, 'b) StringCvt.reader -&gt; 'b -&gt; 'a t
11720
11721 val when : 'a t * ('a -&gt; bool) -&gt; 'a t
11722 val by : 'a t * ('a -&gt; 'b) -&gt; 'b t
11723 val @@ : 'a t * 'a t -&gt; 'a t
11724 val ** : 'a t * 'b t -&gt; ('a, 'b) product t
11725
11726 val for : 'a -&gt; 'a
11727 end</programlisting>
11728 <simpara>Several of the above combinators are meant to be used as infix
11729 operators. Here is a set of suitable infix declarations:</simpara>
11730 <programlisting language="sml" linenumbering="unnumbered">infix 2 to downto
11731 infix 1 @@ when by
11732 infix 0 &gt;&gt;= **</programlisting>
11733 <simpara>A few notes are in order:</simpara>
11734 <itemizedlist>
11735 <listitem>
11736 <simpara>
11737 The <literal>'a t</literal> type constructor with the <literal>return</literal> and <literal>&gt;&gt;=</literal> operators forms a monad.
11738 </simpara>
11739 </listitem>
11740 <listitem>
11741 <simpara>
11742 The <literal>to</literal> and <literal>downto</literal> combinators will omit the upper bound of the range.
11743 </simpara>
11744 </listitem>
11745 <listitem>
11746 <simpara>
11747 <literal>for</literal> is the identity function. It is purely for syntactic sugar and is not strictly required.
11748 </simpara>
11749 </listitem>
11750 <listitem>
11751 <simpara>
11752 The <literal>@@</literal> combinator produces an iterator for the concatenation of the given iterators.
11753 </simpara>
11754 </listitem>
11755 <listitem>
11756 <simpara>
11757 The <literal>**</literal> combinator produces an iterator for the Cartesian product of the given iterators.
11758 </simpara>
11759 <itemizedlist>
11760 <listitem>
11761 <simpara>
11762 See <link linkend="ProductType">ProductType</link> for the type constructor <literal>('a, 'b) product</literal> used in the type of the iterator produced by <literal>**</literal>.
11763 </simpara>
11764 </listitem>
11765 </itemizedlist>
11766 </listitem>
11767 <listitem>
11768 <simpara>
11769 The <literal>using</literal> combinator allows one to iterate over slices, streams and many other kinds of sequences.
11770 </simpara>
11771 </listitem>
11772 <listitem>
11773 <simpara>
11774 <literal>when</literal> is the filtering combinator. The name <literal>when</literal> is inspired by <link linkend="OCaml">OCaml</link>'s guard clauses.
11775 </simpara>
11776 </listitem>
11777 <listitem>
11778 <simpara>
11779 <literal>by</literal> is the mapping combinator.
11780 </simpara>
11781 </listitem>
11782 </itemizedlist>
11783 <simpara>The below implementation of the <literal>ITER</literal>-signature makes use of the
11784 following basic combinators:</simpara>
11785 <programlisting language="sml" linenumbering="unnumbered">fun const x _ = x
11786 fun flip f x y = f y x
11787 fun id x = x
11788 fun opt fno fso = fn NONE =&gt; fno () | SOME ? =&gt; fso ?
11789 fun pass x f = f x</programlisting>
11790 <simpara>Here is an implementation the <literal>ITER</literal>-signature:</simpara>
11791 <programlisting language="sml" linenumbering="unnumbered">structure Iter :&gt; ITER =
11792 struct
11793 type 'a t = ('a -&gt; unit) -&gt; unit
11794
11795 val return = pass
11796 fun (iA &gt;&gt;= a2iB) f = iA (flip a2iB f)
11797
11798 val none = ignore
11799
11800 fun (l to u) f = let fun `l = if l&lt;u then (f l; `(l+1)) else () in `l end
11801 fun (u downto l) f = let fun `u = if u&gt;l then (f (u-1); `(u-1)) else () in `u end
11802
11803 fun inList ? = flip List.app ?
11804 fun inVector ? = flip Vector.app ?
11805 fun inArray ? = flip Array.app ?
11806
11807 fun using get s f = let fun `s = opt (const ()) (fn (x, s) =&gt; (f x; `s)) (get s) in `s end
11808
11809 fun (iA when p) f = iA (fn a =&gt; if p a then f a else ())
11810 fun (iA by g) f = iA (f o g)
11811 fun (iA @@ iB) f = (iA f : unit; iB f)
11812 fun (iA ** iB) f = iA (fn a =&gt; iB (fn b =&gt; f (a &amp; b)))
11813
11814 val for = id
11815 end</programlisting>
11816 <simpara>Note that some of the above combinators (e.g. <literal>**</literal>) could be expressed
11817 in terms of the other combinators, most notably <literal>return</literal> and <literal>&gt;&gt;=</literal>.
11818 Another implementation issue worth mentioning is that <literal>downto</literal> is
11819 written specifically to avoid computing <literal>l-1</literal>, which could cause an
11820 <literal>Overflow</literal>.</simpara>
11821 <simpara>To use the above combinators the <literal>Iter</literal>-structure needs to be opened</simpara>
11822 <programlisting language="sml" linenumbering="unnumbered">open Iter</programlisting>
11823 <simpara>and one usually also wants to declare the infix status of the
11824 operators as shown earlier.</simpara>
11825 <simpara>Here is an example that illustrates some of the features:</simpara>
11826 <programlisting language="sml" linenumbering="unnumbered">for (0 to 10 when (fn x =&gt; x mod 3 &lt;&gt; 0) ** inList ["a", "b"] ** 2 downto 1 by real)
11827 (fn x &amp; y &amp; z =&gt;
11828 print ("("^Int.toString x^", \""^y^"\", "^Real.toString z^")\n"))</programlisting>
11829 <simpara>Using the <literal>Iter</literal> combinators one can easily produce more complicated
11830 iterators. For example, here is an iterator over a "triangle":</simpara>
11831 <programlisting language="sml" linenumbering="unnumbered">fun triangle (l, u) = l to u &gt;&gt;= (fn i =&gt; i to u &gt;&gt;= (fn j =&gt; return (i, j)))</programlisting>
11832 <simpara><?asciidoc-pagebreak?></simpara>
11833 </section>
11834 </section>
11835 <section id="FrontEnd">
11836 <title>FrontEnd</title>
11837 <simpara><link linkend="FrontEnd">FrontEnd</link> is a translation pass from source to the <link linkend="AST">AST</link>
11838 <link linkend="IntermediateLanguage">IntermediateLanguage</link>.</simpara>
11839 <section id="_description_18">
11840 <title>Description</title>
11841 <simpara>This pass performs lexing and parsing to produce an abstract syntax
11842 tree.</simpara>
11843 </section>
11844 <section id="_implementation_20">
11845 <title>Implementation</title>
11846 <itemizedlist>
11847 <listitem>
11848 <simpara>
11849 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/front-end/front-end.sig"><literal>front-end.sig</literal></ulink>
11850 </simpara>
11851 </listitem>
11852 <listitem>
11853 <simpara>
11854 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/front-end/front-end.fun"><literal>front-end.fun</literal></ulink>
11855 </simpara>
11856 </listitem>
11857 </itemizedlist>
11858 </section>
11859 <section id="_details_and_notes_20">
11860 <title>Details and Notes</title>
11861 <simpara>The lexer is produced by <link linkend="MLLex">MLLex</link> from
11862 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/front-end/ml.lex"><literal>ml.lex</literal></ulink>.</simpara>
11863 <simpara>The parser is produced by <link linkend="MLYacc">MLYacc</link> from
11864 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/front-end/ml.grm"><literal>ml.grm</literal></ulink>.</simpara>
11865 <simpara>The specifications for the lexer and parser were originally taken from
11866 <link linkend="SMLNJ">SML/NJ</link> (version 109.32), but have been heavily modified
11867 since then.</simpara>
11868 <simpara><?asciidoc-pagebreak?></simpara>
11869 </section>
11870 </section>
11871 <section id="FSharp">
11872 <title>FSharp</title>
11873 <simpara><ulink url="http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/">F#</ulink>
11874 is a functional programming language developed at Microsoft Research.
11875 F# was partly inspired by the <link linkend="OCaml">OCaml</link> language and shares some
11876 common core constructs with it. F# is integrated with Visual Studio
11877 2010 as a first-class language.</simpara>
11878 <simpara><?asciidoc-pagebreak?></simpara>
11879 </section>
11880 <section id="FunctionalRecordUpdate">
11881 <title>FunctionalRecordUpdate</title>
11882 <simpara>Functional record update is the copying of a record while replacing
11883 the values of some of the fields. <link linkend="StandardML">Standard ML</link> does not
11884 have explicit syntax for functional record update. We will show below
11885 how to implement functional record update in SML, with a little
11886 boilerplate code.</simpara>
11887 <simpara>As an example, the functional update of the record</simpara>
11888 <programlisting language="sml" linenumbering="unnumbered">{a = 13, b = 14, c = 15}</programlisting>
11889 <simpara>with <literal>c = 16</literal> yields a new record</simpara>
11890 <programlisting language="sml" linenumbering="unnumbered">{a = 13, b = 14, c = 16}</programlisting>
11891 <simpara>Functional record update also makes sense with multiple simultaneous
11892 updates. For example, the functional update of the record above with
11893 <literal>a = 18, c = 19</literal> yields a new record</simpara>
11894 <programlisting language="sml" linenumbering="unnumbered">{a = 18, b = 14, c = 19}</programlisting>
11895 <simpara>One could easily imagine an extension of the SML that supports
11896 functional record update. For example</simpara>
11897 <programlisting language="sml" linenumbering="unnumbered">e with {a = 16, b = 17}</programlisting>
11898 <simpara>would create a copy of the record denoted by <literal>e</literal> with field <literal>a</literal>
11899 replaced with <literal>16</literal> and <literal>b</literal> replaced with <literal>17</literal>.</simpara>
11900 <simpara>Since there is no such syntax in SML, we now show how to implement
11901 functional record update directly. We first give a simple
11902 implementation that has a number of problems. We then give an
11903 advanced implementation, that, while complex underneath, is a reusable
11904 library that admits simple use.</simpara>
11905 <section id="_simple_implementation">
11906 <title>Simple implementation</title>
11907 <simpara>To support functional record update on the record type</simpara>
11908 <programlisting language="sml" linenumbering="unnumbered">{a: 'a, b: 'b, c: 'c}</programlisting>
11909 <simpara>first, define an update function for each component.</simpara>
11910 <programlisting language="sml" linenumbering="unnumbered">fun withA ({a = _, b, c}, a) = {a = a, b = b, c = c}
11911 fun withB ({a, b = _, c}, b) = {a = a, b = b, c = c}
11912 fun withC ({a, b, c = _}, c) = {a = a, b = b, c = c}</programlisting>
11913 <simpara>Then, one can express <literal>e with {a = 16, b = 17}</literal> as</simpara>
11914 <programlisting language="sml" linenumbering="unnumbered">withB (withA (e, 16), 17)</programlisting>
11915 <simpara>With infix notation</simpara>
11916 <programlisting language="sml" linenumbering="unnumbered">infix withA withB withC</programlisting>
11917 <simpara>the syntax is almost as concise as a language extension.</simpara>
11918 <programlisting language="sml" linenumbering="unnumbered">e withA 16 withB 17</programlisting>
11919 <simpara>This approach suffers from the fact that the amount of boilerplate
11920 code is quadratic in the number of record fields. Furthermore,
11921 changing, adding, or deleting a field requires time proportional to
11922 the number of fields (because each <literal>with<emphasis>&lt;L&gt;</emphasis></literal> function must be
11923 changed). It is also annoying to have to define a <literal>with<emphasis>&lt;L&gt;</emphasis></literal>
11924 function, possibly with a fixity declaration, for each field.</simpara>
11925 <simpara>Fortunately, there is a solution to these problems.</simpara>
11926 </section>
11927 <section id="_advanced_implementation">
11928 <title>Advanced implementation</title>
11929 <simpara>Using <link linkend="Fold">Fold</link> one can define a family of <literal>makeUpdate<emphasis>&lt;N&gt;</emphasis></literal>
11930 functions and single <emphasis>update</emphasis> operator <literal>U</literal> so that one can define a
11931 functional record update function for any record type simply by
11932 specifying a (trivial) isomorphism between that type and function
11933 argument list. For example, suppose that we would like to do
11934 functional record update on records with fields <literal>a</literal> and <literal>b</literal>. Then one
11935 defines a function <literal>updateAB</literal> as follows.</simpara>
11936 <programlisting language="sml" linenumbering="unnumbered">val updateAB =
11937 fn z =&gt;
11938 let
11939 fun from v1 v2 = {a = v1, b = v2}
11940 fun to f {a = v1, b = v2} = f v1 v2
11941 in
11942 makeUpdate2 (from, from, to)
11943 end
11944 z</programlisting>
11945 <simpara>The functions <literal>from</literal> (think <emphasis>from function arguments</emphasis>) and <literal>to</literal> (think
11946 <emphasis>to function arguements</emphasis>) specify an isomorphism between <literal>a</literal>,<literal>b</literal>
11947 records and function arguments. There is a second use of <literal>from</literal> to
11948 work around the lack of
11949 <link linkend="FirstClassPolymorphism">first-class polymorphism</link> in SML.</simpara>
11950 <simpara>With the definition of <literal>updateAB</literal> in place, the following expressions
11951 are valid.</simpara>
11952 <programlisting language="sml" linenumbering="unnumbered">updateAB {a = 13, b = "hello"} (set#b "goodbye") $
11953 updateAB {a = 13.5, b = true} (set#b false) (set#a 12.5) $</programlisting>
11954 <simpara>As another example, suppose that we would like to do functional record
11955 update on records with fields <literal>b</literal>, <literal>c</literal>, and <literal>d</literal>. Then one defines a
11956 function <literal>updateBCD</literal> as follows.</simpara>
11957 <programlisting language="sml" linenumbering="unnumbered">val updateBCD =
11958 fn z =&gt;
11959 let
11960 fun from v1 v2 v3 = {b = v1, c = v2, d = v3}
11961 fun to f {b = v1, c = v2, d = v3} = f v1 v2 v3
11962 in
11963 makeUpdate3 (from, from, to)
11964 end
11965 z</programlisting>
11966 <simpara>With the definition of <literal>updateBCD</literal> in place, the following expression
11967 is valid.</simpara>
11968 <programlisting language="sml" linenumbering="unnumbered">updateBCD {b = 1, c = 2, d = 3} (set#c 4) (set#c 5) $</programlisting>
11969 <simpara>Note that not all fields need be updated and that the same field may
11970 be updated multiple times. Further note that the same <literal>set</literal> operator
11971 is used for all update functions (in the above, for both <literal>updateAB</literal>
11972 and <literal>updateBCD</literal>).</simpara>
11973 <simpara>In general, to define a functional-record-update function on records
11974 with fields <literal>f1</literal>, <literal>f2</literal>, &#8230;, <literal>fN</literal>, use the following template.</simpara>
11975 <programlisting language="sml" linenumbering="unnumbered">val update =
11976 fn z =&gt;
11977 let
11978 fun from v1 v2 ... vn = {f1 = v1, f2 = v2, ..., fn = vn}
11979 fun to f {f1 = v1, f2 = v2, ..., fn = vn} = v1 v2 ... vn
11980 in
11981 makeUpdateN (from, from, to)
11982 end
11983 z</programlisting>
11984 <simpara>With this, one can update a record as follows.</simpara>
11985 <programlisting language="sml" linenumbering="unnumbered">update {f1 = v1, ..., fn = vn} (set#fi1 vi1) ... (set#fim vim) $</programlisting>
11986 </section>
11987 <section id="_the_literal_functionalrecordupdate_literal_structure">
11988 <title>The <literal>FunctionalRecordUpdate</literal> structure</title>
11989 <simpara>Here is the implementation of functional record update.</simpara>
11990 <programlisting language="sml" linenumbering="unnumbered">structure FunctionalRecordUpdate =
11991 struct
11992 local
11993 fun next g (f, z) x = g (f x, z)
11994 fun f1 (f, z) x = f (z x)
11995 fun f2 z = next f1 z
11996 fun f3 z = next f2 z
11997
11998 fun c0 from = from
11999 fun c1 from = c0 from f1
12000 fun c2 from = c1 from f2
12001 fun c3 from = c2 from f3
12002
12003 fun makeUpdate cX (from, from', to) record =
12004 let
12005 fun ops () = cX from'
12006 fun vars f = to f record
12007 in
12008 Fold.fold ((vars, ops), fn (vars, _) =&gt; vars from)
12009 end
12010 in
12011 fun makeUpdate0 z = makeUpdate c0 z
12012 fun makeUpdate1 z = makeUpdate c1 z
12013 fun makeUpdate2 z = makeUpdate c2 z
12014 fun makeUpdate3 z = makeUpdate c3 z
12015
12016 fun upd z = Fold.step2 (fn (s, f, (vars, ops)) =&gt; (fn out =&gt; vars (s (ops ()) (out, f)), ops)) z
12017 fun set z = Fold.step2 (fn (s, v, (vars, ops)) =&gt; (fn out =&gt; vars (s (ops ()) (out, fn _ =&gt; v)), ops)) z
12018 end
12019 end</programlisting>
12020 <simpara>The idea of <literal>makeUpdate</literal> is to build a record of functions which can
12021 replace the contents of one argument out of a list of arguments. The
12022 functions <literal>f<emphasis>&lt;X&gt;</emphasis></literal> replace the 0th, 1st, &#8230; argument with their
12023 argument <literal>z</literal>. The <literal>c<emphasis>&lt;X&gt;</emphasis></literal> functions pass the first <emphasis>X</emphasis> <literal>f</literal>
12024 functions to the record constructor.</simpara>
12025 <simpara>The <literal>#field</literal> notation of Standard ML allows us to select the map
12026 function which replaces the corresponding argument. By converting the
12027 record to an argument list, feeding that list through the selected map
12028 function and piping the list into the record constructor, functional
12029 record update is achieved.</simpara>
12030 </section>
12031 <section id="_efficiency">
12032 <title>Efficiency</title>
12033 <simpara>With MLton, the efficiency of this approach is as good as one would
12034 expect with the special syntax. Namely a sequence of updates will be
12035 optimized into a single record construction that copies the unchanged
12036 fields and fills in the changed fields with their new values.</simpara>
12037 <simpara>Before Sep 14, 2009, this page advocated an alternative implementation
12038 of <link linkend="FunctionalRecordUpdate">FunctionalRecordUpdate</link>. However, the old structure caused
12039 exponentially increasing compile times. We advise you to switch to
12040 the newer version.</simpara>
12041 </section>
12042 <section id="_applications">
12043 <title>Applications</title>
12044 <simpara>Functional record update can be used to implement labelled
12045 <link linkend="OptionalArguments">optional arguments</link>.</simpara>
12046 <simpara><?asciidoc-pagebreak?></simpara>
12047 </section>
12048 </section>
12049 <section id="fxp">
12050 <title>fxp</title>
12051 <simpara><ulink url="http://atseidl2.informatik.tu-muenchen.de/%7Eberlea/Fxp/">fxp</ulink> is an XML
12052 parser written in Standard ML.</simpara>
12053 <simpara>It has a
12054 <ulink url="http://atseidl2.informatik.tu-muenchen.de/%7Eberlea/Fxp/mlton.html">patch</ulink>
12055 to compile with MLton.</simpara>
12056 <simpara><?asciidoc-pagebreak?></simpara>
12057 </section>
12058 <section id="GarbageCollection">
12059 <title>GarbageCollection</title>
12060 <simpara>For a good introduction and overview to garbage collection, see
12061 <link linkend="References_Jones99">Jones99</link>.</simpara>
12062 <simpara>MLton&#8217;s garbage collector uses copying, mark-compact, and generational
12063 collection, automatically switching between them at run time based on
12064 the amount of live data relative to the amount of RAM. The runtime
12065 system tries to keep the heap within RAM if at all possible.</simpara>
12066 <simpara>MLton&#8217;s copying collector is a simple, two-space, breadth-first,
12067 Cheney-style collector. The design for the generational and
12068 mark-compact GC is based on <link linkend="References_Sansom91">Sansom91</link>.</simpara>
12069 <section id="_design_notes">
12070 <title>Design notes</title>
12071 <itemizedlist>
12072 <listitem>
12073 <simpara>
12074 <ulink url="http://www.mlton.org/pipermail/mlton/2002-May/012420.html">http://www.mlton.org/pipermail/mlton/2002-May/012420.html</ulink>
12075 </simpara>
12076 <simpara>object layout and header word design</simpara>
12077 </listitem>
12078 </itemizedlist>
12079 </section>
12080 <section id="_also_see_4">
12081 <title>Also see</title>
12082 <itemizedlist>
12083 <listitem>
12084 <simpara>
12085 <link linkend="Regions">Regions</link>
12086 </simpara>
12087 </listitem>
12088 </itemizedlist>
12089 <simpara><?asciidoc-pagebreak?></simpara>
12090 </section>
12091 </section>
12092 <section id="GenerativeDatatype">
12093 <title>GenerativeDatatype</title>
12094 <simpara>In <link linkend="StandardML">Standard ML</link>, datatype declarations are said to be
12095 <emphasis>generative</emphasis>, because each time a datatype declaration is evaluated,
12096 it yields a new type. Thus, any attempt to mix the types will lead to
12097 a type error at compile-time. The following program, which does not
12098 type check, demonstrates this.</simpara>
12099 <programlisting language="sml" linenumbering="unnumbered">functor F () =
12100 struct
12101 datatype t = T
12102 end
12103 structure S1 = F ()
12104 structure S2 = F ()
12105 val _: S1.t -&gt; S2.t = fn x =&gt; x</programlisting>
12106 <simpara>Generativity also means that two different datatype declarations
12107 define different types, even if they define identical constructors.
12108 The following program does not type check due to this.</simpara>
12109 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B
12110 val a1 = A
12111 datatype t = A | B
12112 val a2 = A
12113 val _ = if true then a1 else a2</programlisting>
12114 <section id="_also_see_5">
12115 <title>Also see</title>
12116 <itemizedlist>
12117 <listitem>
12118 <simpara>
12119 <link linkend="GenerativeException">GenerativeException</link>
12120 </simpara>
12121 </listitem>
12122 </itemizedlist>
12123 <simpara><?asciidoc-pagebreak?></simpara>
12124 </section>
12125 </section>
12126 <section id="GenerativeException">
12127 <title>GenerativeException</title>
12128 <simpara>In <link linkend="StandardML">Standard ML</link>, exception declarations are said to be
12129 <emphasis>generative</emphasis>, because each time an exception declaration is evaluated,
12130 it yields a new exception.</simpara>
12131 <simpara>The following program demonstrates the generativity of exceptions.</simpara>
12132 <programlisting language="sml" linenumbering="unnumbered">exception E
12133 val e1 = E
12134 fun isE1 (e: exn): bool =
12135 case e of
12136 E =&gt; true
12137 | _ =&gt; false
12138 exception E
12139 val e2 = E
12140 fun isE2 (e: exn): bool =
12141 case e of
12142 E =&gt; true
12143 | _ =&gt; false
12144 fun pb (b: bool): unit =
12145 print (concat [Bool.toString b, "\n"])
12146 val () = (pb (isE1 e1)
12147 ;pb (isE1 e2)
12148 ; pb (isE2 e1)
12149 ; pb (isE2 e2))</programlisting>
12150 <simpara>In the above program, two different exception declarations declare an
12151 exception <literal>E</literal> and a corresponding function that returns <literal>true</literal> only on
12152 that exception. Although declared by syntactically identical
12153 exception declarations, <literal>e1</literal> and <literal>e2</literal> are different exceptions. The
12154 program, when run, prints <literal>true</literal>, <literal>false</literal>, <literal>false</literal>, <literal>true</literal>.</simpara>
12155 <simpara>A slight modification of the above program shows that even a single
12156 exception declaration yields a new exception each time it is
12157 evaluated.</simpara>
12158 <programlisting language="sml" linenumbering="unnumbered">fun f (): exn * (exn -&gt; bool) =
12159 let
12160 exception E
12161 in
12162 (E, fn E =&gt; true | _ =&gt; false)
12163 end
12164 val (e1, isE1) = f ()
12165 val (e2, isE2) = f ()
12166 fun pb (b: bool): unit =
12167 print (concat [Bool.toString b, "\n"])
12168 val () = (pb (isE1 e1)
12169 ; pb (isE1 e2)
12170 ; pb (isE2 e1)
12171 ; pb (isE2 e2))</programlisting>
12172 <simpara>Each call to <literal>f</literal> yields a new exception and a function that returns
12173 <literal>true</literal> only on that exception. The program, when run, prints <literal>true</literal>,
12174 <literal>false</literal>, <literal>false</literal>, <literal>true</literal>.</simpara>
12175 <section id="_type_safety">
12176 <title>Type Safety</title>
12177 <simpara>Exception generativity is required for type safety. Consider the
12178 following valid SML program.</simpara>
12179 <programlisting language="sml" linenumbering="unnumbered">fun f (): ('a -&gt; exn) * (exn -&gt; 'a) =
12180 let
12181 exception E of 'a
12182 in
12183 (E, fn E x =&gt; x | _ =&gt; raise Fail "f")
12184 end
12185 fun cast (a: 'a): 'b =
12186 let
12187 val (make: 'a -&gt; exn, _) = f ()
12188 val (_, get: exn -&gt; 'b) = f ()
12189 in
12190 get (make a)
12191 end
12192 val _ = ((cast 13): int -&gt; int) 14</programlisting>
12193 <simpara>If exceptions weren&#8217;t generative, then each call <literal>f ()</literal> would yield
12194 the same exception constructor <literal>E</literal>. Then, our <literal>cast</literal> function could
12195 use <literal>make: 'a -&gt; exn</literal> to convert any value into an exception and then
12196 <literal>get: exn -&gt; 'b</literal> to convert that exception to a value of arbitrary
12197 type. If <literal>cast</literal> worked, then we could cast an integer as a function
12198 and apply. Of course, because of generative exceptions, this program
12199 raises <literal>Fail "f"</literal>.</simpara>
12200 </section>
12201 <section id="_applications_2">
12202 <title>Applications</title>
12203 <simpara>The <literal>exn</literal> type is effectively a <link linkend="UniversalType">universal type</link>.</simpara>
12204 </section>
12205 <section id="_also_see_6">
12206 <title>Also see</title>
12207 <itemizedlist>
12208 <listitem>
12209 <simpara>
12210 <link linkend="GenerativeDatatype">GenerativeDatatype</link>
12211 </simpara>
12212 </listitem>
12213 </itemizedlist>
12214 <simpara><?asciidoc-pagebreak?></simpara>
12215 </section>
12216 </section>
12217 <section id="Git">
12218 <title>Git</title>
12219 <simpara><ulink url="http://git-scm.com/">Git</ulink> is a distributed version control system. The
12220 MLton project currently uses Git to maintain its
12221 <link linkend="Sources">source code</link>.</simpara>
12222 <simpara>Here are some online Git resources.</simpara>
12223 <itemizedlist>
12224 <listitem>
12225 <simpara>
12226 <ulink url="http://git-scm.com/docs">Reference Manual</ulink>
12227 </simpara>
12228 </listitem>
12229 <listitem>
12230 <simpara>
12231 <ulink url="http://git-scm.com/book">ProGit, by Scott Chacon</ulink>
12232 </simpara>
12233 </listitem>
12234 </itemizedlist>
12235 <simpara><?asciidoc-pagebreak?></simpara>
12236 </section>
12237 <section id="Glade">
12238 <title>Glade</title>
12239 <simpara><ulink url="http://glade.gnome.org/features.html">Glade</ulink> is a tool for generating
12240 Gtk user interfaces.</simpara>
12241 <simpara><link linkend="WesleyTerpstra">WesleyTerpstra</link> is working on a Glade&#8594;mGTK converter.</simpara>
12242 <itemizedlist>
12243 <listitem>
12244 <simpara>
12245 <ulink url="http://www.mlton.org/pipermail/mlton/2004-December/016865.html">http://www.mlton.org/pipermail/mlton/2004-December/016865.html</ulink>
12246 </simpara>
12247 </listitem>
12248 </itemizedlist>
12249 <simpara><?asciidoc-pagebreak?></simpara>
12250 </section>
12251 <section id="Globalize">
12252 <title>Globalize</title>
12253 <simpara><link linkend="Globalize">Globalize</link> is an analysis pass for the <link linkend="SXML">SXML</link>
12254 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="ClosureConvert">ClosureConvert</link>.</simpara>
12255 <section id="_description_19">
12256 <title>Description</title>
12257 <simpara>This pass marks values that are constant, allowing <link linkend="ClosureConvert">ClosureConvert</link>
12258 to move them out to the top level so they are only evaluated once and
12259 do not appear in closures.</simpara>
12260 </section>
12261 <section id="_implementation_21">
12262 <title>Implementation</title>
12263 <itemizedlist>
12264 <listitem>
12265 <simpara>
12266 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/globalize.sig"><literal>globalize.sig</literal></ulink>
12267 </simpara>
12268 </listitem>
12269 <listitem>
12270 <simpara>
12271 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/globalize.fun"><literal>globalize.fun</literal></ulink>
12272 </simpara>
12273 </listitem>
12274 </itemizedlist>
12275 </section>
12276 <section id="_details_and_notes_21">
12277 <title>Details and Notes</title>
12278 <simpara></simpara>
12279 <simpara><?asciidoc-pagebreak?></simpara>
12280 </section>
12281 </section>
12282 <section id="GnuMP">
12283 <title>GnuMP</title>
12284 <simpara>The <ulink url="http://gmplib.org">GnuMP</ulink> library (GNU Multiple Precision
12285 arithmetic library) is a library for arbitrary precision integer
12286 arithmetic. MLton uses the GnuMP library to implement the
12287 <link linkend="BasisLibrary">Basis Library</link> <literal>IntInf</literal> module.</simpara>
12288 <section id="_known_issues">
12289 <title>Known issues</title>
12290 <itemizedlist>
12291 <listitem>
12292 <simpara>
12293 There is a known problem with the GnuMP library (prior to version
12294 4.2.x), where it requires a lot of stack space for some computations,
12295 e.g. <literal>IntInf.toString</literal> of a million digit number. If you run with
12296 stack size limited, you may see a segfault in such programs. This
12297 problem is mentioned in the <ulink url="http://gmplib.org/#FAQ">GnuMP FAQ</ulink>, where
12298 they describe two solutions.
12299 </simpara>
12300 <itemizedlist>
12301 <listitem>
12302 <simpara>
12303 Increase (or unlimit) your stack space. From your program, use
12304 <literal>setrlimit</literal>, or from the shell, use <literal>ulimit</literal>.
12305 </simpara>
12306 </listitem>
12307 <listitem>
12308 <simpara>
12309 Configure and rebuild <literal>libgmp</literal> with <literal>--disable-alloca</literal>, which will
12310 cause it to allocate temporaries using <literal>malloc</literal> instead of on the
12311 stack.
12312 </simpara>
12313 </listitem>
12314 </itemizedlist>
12315 </listitem>
12316 <listitem>
12317 <simpara>
12318 On some platforms, the GnuMP library may be configured to use one of
12319 multiple ABIs (Application Binary Interfaces). For example, on some
12320 32-bit architectures, GnuMP may be configured to represent a limb as
12321 either a 32-bit <literal>long</literal> or as a 64-bit <literal>long long</literal>. Similarly, GnuMP
12322 may be configured to use specific CPU features.
12323 </simpara>
12324 <simpara>In order to efficiently use the GnuMP library, MLton represents an
12325 <literal>IntInf.int</literal> value in a manner compatible with the GnuMP library&#8217;s
12326 representation of a limb. Hence, it is important that MLton and the
12327 GnuMP library agree upon the representation of a limb.</simpara>
12328 <itemizedlist>
12329 <listitem>
12330 <simpara>
12331 When using a source package of MLton, building will detect the
12332 GnuMP library&#8217;s representation of a limb.
12333 </simpara>
12334 </listitem>
12335 <listitem>
12336 <simpara>
12337 When using a binary package of MLton that is dynamically linked
12338 against the GnuMP library, the build machine and the install machine
12339 must have the GnuMP library configured with the same representation of
12340 a limb. (On the other hand, the build machine need not have the GnuMP
12341 library configured with CPU features compatible with the install
12342 machine.)
12343 </simpara>
12344 </listitem>
12345 <listitem>
12346 <simpara>
12347 When using a binary package of MLton that is statically linked
12348 against the GnuMP library, the build machine and the install machine
12349 need not have the GnuMP library configured with the same
12350 representation of a limb. (On the other hand, the build machine must
12351 have the GnuMP library configured with CPU features compatible with
12352 the install machine.)
12353 </simpara>
12354 <simpara>However, MLton will be configured with the representation of a limb
12355 from the GnuMP library of the build machine. Executables produced by
12356 MLton will be incompatible with the GnuMP library of the install
12357 machine. To <emphasis>reconfigure</emphasis> MLton with the representation of a limb
12358 from the GnuMP library of the install machine, one must edit:</simpara>
12359 <screen>/usr/lib/mlton/self/sizes</screen>
12360 <simpara>changing the</simpara>
12361 <screen>mplimb = ??</screen>
12362 <simpara>entry so that <literal>??</literal> corresponds to the bytes in a limb; and, one must edit:</simpara>
12363 <screen>/usr/lib/mlton/sml/basis/config/c/arch-os/c-types.sml</screen>
12364 <simpara>changing the</simpara>
12365 <screen>(* from "gmp.h" *)
12366 structure C_MPLimb = struct open Word?? type t = word end
12367 functor C_MPLimb_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word?? (A)</screen>
12368 <simpara>entries so that <literal>??</literal> corresponds to the bits in a limb.</simpara>
12369 </listitem>
12370 </itemizedlist>
12371 </listitem>
12372 </itemizedlist>
12373 <simpara><?asciidoc-pagebreak?></simpara>
12374 </section>
12375 </section>
12376 <section id="GoogleSummerOfCode2013">
12377 <title>Google Summer of Code (2013)</title>
12378 <section id="_mentors">
12379 <title>Mentors</title>
12380 <simpara>The following developers have agreed to serve as mentors for the 2013 Google Summer of Code:</simpara>
12381 <itemizedlist>
12382 <listitem>
12383 <simpara>
12384 <ulink url="http://www.cs.rit.edu/%7Emtf">Matthew Fluet</ulink>
12385 </simpara>
12386 </listitem>
12387 <listitem>
12388 <simpara>
12389 <ulink url="http://www.cse.buffalo.edu/%7Elziarek/">Lukasz (Luke) Ziarek</ulink>
12390 </simpara>
12391 </listitem>
12392 <listitem>
12393 <simpara>
12394 <ulink url="http://www.cs.purdue.edu/homes/suresh/">Suresh Jagannathan</ulink>
12395 </simpara>
12396 </listitem>
12397 </itemizedlist>
12398 </section>
12399 <section id="_ideas_list">
12400 <title>Ideas List</title>
12401 <section id="_implement_a_partial_redundancy_elimination_pre_optimization">
12402 <title>Implement a Partial Redundancy Elimination (PRE) Optimization</title>
12403 <simpara>Partial redundancy elimination (PRE) is a program transformation that
12404 removes operations that are redundant on some, but not necessarily all
12405 paths, through the program. PRE can subsume both common subexpression
12406 elimination and loop-invariant code motion, and is therefore a
12407 potentially powerful optimization. However, a na&iuml;ve
12408 implementation of PRE on a program in static single assignment (SSA)
12409 form is unlikely to be effective. This project aims to adapt and
12410 implement the SSAPRE algorithm(s) of Thomas VanDrunen in MLton&#8217;s SSA
12411 intermediate language.</simpara>
12412 <simpara>Background:</simpara>
12413 <itemizedlist>
12414 <listitem>
12415 <simpara>
12416 <ulink url="http://onlinelibrary.wiley.com/doi/10.1002/spe.618/abstract">Anticipation-based partial redundancy elimination for static single assignment form</ulink>; Thomas VanDrunen and Antony L. Hosking
12417 </simpara>
12418 </listitem>
12419 <listitem>
12420 <simpara>
12421 <ulink url="http://cs.wheaton.edu/%7Etvandrun/writings/thesis.pdf">Partial Redundancy Elimination for Global Value Numbering</ulink>; Thomas VanDrunen
12422 </simpara>
12423 </listitem>
12424 <listitem>
12425 <simpara>
12426 <ulink url="http://www.springerlink.com/content/w06m3cw453nphm1u/">Value-Based Partial Redundancy Elimination</ulink>; Thomas VanDrunen and Antony L. Hosking
12427 </simpara>
12428 </listitem>
12429 <listitem>
12430 <simpara>
12431 <ulink url="http://portal.acm.org/citation.cfm?doid=319301.319348">Partial redundancy elimination in SSA form</ulink>; Robert Kennedy, Sun Chan, Shin-Ming Liu, Raymond Lo, Peng Tu, and Fred Chow
12432 </simpara>
12433 </listitem>
12434 </itemizedlist>
12435 <simpara>Recommended Skills: SML programming experience; some middle-end compiler experience</simpara>
12436 </section>
12437 <section id="_design_and_implement_a_heap_profiler">
12438 <title>Design and Implement a Heap Profiler</title>
12439 <simpara>A heap profile is a description of the space usage of a program. A
12440 heap profile is concerned with the allocation, retention, and
12441 deallocation (via garbage collection) of heap data during the
12442 execution of a program. A heap profile can be used to diagnose
12443 performance problems in a functional program that arise from space
12444 leaks. This project aims to design and implement a heap profiler for
12445 MLton compiled programs.</simpara>
12446 <simpara>Background:</simpara>
12447 <itemizedlist>
12448 <listitem>
12449 <simpara>
12450 <ulink url="http://portal.acm.org/citation.cfm?doid=583854.582451">GCspy: an adaptable heap visualisation framework</ulink>; Tony Printezis and Richard Jones
12451 </simpara>
12452 </listitem>
12453 <listitem>
12454 <simpara>
12455 <ulink url="http://journals.cambridge.org/action/displayAbstract?aid=1349892">New dimensions in heap profiling</ulink>; Colin Runciman and Niklas R&ouml;jemo
12456 </simpara>
12457 </listitem>
12458 <listitem>
12459 <simpara>
12460 <ulink url="http://www.springerlink.com/content/710501660722gw37/">Heap profiling for space efficiency</ulink>; Colin Runciman and Niklas R&ouml;jemo
12461 </simpara>
12462 </listitem>
12463 <listitem>
12464 <simpara>
12465 <ulink url="http://journals.cambridge.org/action/displayAbstract?aid=1323096">Heap profiling of lazy functional programs</ulink>; Colin Runciman and David Wakeling
12466 </simpara>
12467 </listitem>
12468 </itemizedlist>
12469 <simpara>Recommended Skills: C and SML programming experience; some experience with UI and visualization</simpara>
12470 </section>
12471 <section id="_garbage_collector_improvements">
12472 <title>Garbage Collector Improvements</title>
12473 <simpara>The garbage collector plays a significant role in the performance of
12474 functional languages. Garbage collect too often, and program
12475 performance suffers due to the excessive time spent in the garbage
12476 collector. Garbage collect not often enough, and program performance
12477 suffers due to the excessive space used by the uncollected garbage.
12478 One particular issue is ensuring that a program utilizing a garbage
12479 collector "plays nice" with other processes on the system, by not
12480 using too much or too little physical memory. While there are some
12481 reasonable theoretical results about garbage collections with heaps of
12482 fixed size, there seems to be insufficient work that really looks
12483 carefully at the question of dynamically resizing the heap in response
12484 to the live data demands of the application and, similarly, in
12485 response to the behavior of the operating system and other processes.
12486 This project aims to investigate improvements to the memory behavior of
12487 MLton compiled programs through better tuning of the garbage
12488 collector.</simpara>
12489 <simpara>Background:</simpara>
12490 <itemizedlist>
12491 <listitem>
12492 <simpara>
12493 <ulink url="http://www.dcs.gla.ac.uk/%7Ewhited/papers/automated_heap_sizing.pdf">Automated Heap Sizing in the Poly/ML Runtime (Position Paper)</ulink>; David White, Jeremy Singer, Jonathan Aitken, and David Matthews
12494 </simpara>
12495 </listitem>
12496 <listitem>
12497 <simpara>
12498 <ulink url="http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=4145125">Isla Vista Heap Sizing: Using Feedback to Avoid Paging</ulink>; Chris Grzegorczyk, Sunil Soman, Chandra Krintz, and Rich Wolski
12499 </simpara>
12500 </listitem>
12501 <listitem>
12502 <simpara>
12503 <ulink url="http://portal.acm.org/citation.cfm?doid=1152649.1152652">Controlling garbage collection and heap growth to reduce the execution time of Java applications</ulink>; Tim Brecht, Eshrat Arjomandi, Chang Li, and Hang Pham
12504 </simpara>
12505 </listitem>
12506 <listitem>
12507 <simpara>
12508 <ulink url="http://portal.acm.org/citation.cfm?doid=1065010.1065028">Garbage collection without paging</ulink>; Matthew Hertz, Yi Feng, and Emery D. Berger
12509 </simpara>
12510 </listitem>
12511 <listitem>
12512 <simpara>
12513 <ulink url="http://portal.acm.org/citation.cfm?doid=1029873.1029881">Automatic heap sizing: taking real memory into account</ulink>; Ting Yang, Matthew Hertz, Emery D. Berger, Scott F. Kaplan, and J. Eliot B. Moss
12514 </simpara>
12515 </listitem>
12516 </itemizedlist>
12517 <simpara>Recommended Skills: C programming experience; some operating systems and/or systems programming experience; some compiler and garbage collector experience</simpara>
12518 </section>
12519 <section id="_implement_successor_160_ml_language_features">
12520 <title>Implement Successor&#160;ML Language Features</title>
12521 <simpara>Any programming language, including Standard&#160;ML, can be improved.
12522 The community has identified a number of modest extensions and
12523 revisions to the Standard&#160;ML programming language that would
12524 likely prove useful in practice. This project aims to implement these
12525 language features in the MLton compiler.</simpara>
12526 <simpara>Background:</simpara>
12527 <itemizedlist>
12528 <listitem>
12529 <simpara>
12530 <ulink url="http://successor-ml.org/index.php?title=Main_Page">Successor&#160;ML</ulink>
12531 </simpara>
12532 </listitem>
12533 <listitem>
12534 <simpara>
12535 <ulink url="http://www.mpi-sws.org/%7Erossberg/hamlet/index.html#successor-ml">HaMLet (Successor&#160;ML)</ulink>
12536 </simpara>
12537 </listitem>
12538 <listitem>
12539 <simpara>
12540 <ulink url="http://journals.cambridge.org/action/displayAbstract?aid=1322628">A critique of Standard&#160;ML</ulink>; Andrew W. Appel
12541 </simpara>
12542 </listitem>
12543 </itemizedlist>
12544 <simpara>Recommended Skills: SML programming experience; some front-end compiler experience (i.e., scanners and parsers)</simpara>
12545 </section>
12546 <section id="_implement_source_level_debugging">
12547 <title>Implement Source-level Debugging</title>
12548 <simpara>Debugging is a fact of programming life. Unfortunately, most SML
12549 implementations (including MLton) provide little to no source-level
12550 debugging support. This project aims to add basic to intermediate
12551 source-level debugging support to the MLton compiler. MLton already
12552 supports source-level profiling, which can be used to attribute bytes
12553 allocated or time spent in source functions. It should be relatively
12554 straightforward to leverage this source-level information into basic
12555 source-level debugging support, with the ability to set/unset
12556 breakpoints and step through declarations and functions. It may be
12557 possible to also provide intermediate source-level debugging support,
12558 with the ability to inspect in-scope variables of basic types (e.g.,
12559 types compatible with MLton&#8217;s foreign function interface).</simpara>
12560 <simpara>Background:</simpara>
12561 <itemizedlist>
12562 <listitem>
12563 <simpara>
12564 <ulink url="http://mlton.org/HowProfilingWorks">MLton&#8201;&#8212;&#8201;How Profiling Works</ulink>
12565 </simpara>
12566 </listitem>
12567 <listitem>
12568 <simpara>
12569 <ulink url="http://mlton.org/ForeignFunctionInterfaceTypes">MLton&#8201;&#8212;&#8201;Foreign Function Interface Types</ulink>
12570 </simpara>
12571 </listitem>
12572 <listitem>
12573 <simpara>
12574 <ulink url="http://dwarfstd.org/">DWARF Debugging Standard</ulink>
12575 </simpara>
12576 </listitem>
12577 <listitem>
12578 <simpara>
12579 <ulink url="http://sourceware.org/gdb/current/onlinedocs/stabs/index.html">STABS Debugging Format</ulink>
12580 </simpara>
12581 </listitem>
12582 </itemizedlist>
12583 <simpara>Recommended Skills: SML programming experience; some compiler experience</simpara>
12584 </section>
12585 <section id="_simd_primitives">
12586 <title>SIMD Primitives</title>
12587 <simpara>Most modern processors offer some direct support for SIMD (Single
12588 Instruction, Multiple Data) operations, such as Intel&#8217;s MMX/SSE
12589 instructions, AMD&#8217;s 3DNow! instructions, and IBM&#8217;s AltiVec. Such
12590 instructions are particularly useful for multimedia, scientific, and
12591 cryptographic applications. This project aims to add preliminary
12592 support for vector data and vector operations to the MLton compiler.
12593 Ideally, after surveying SIMD instruction sets and SIMD support in
12594 other compilers, a core set of SIMD primitives with broad architecture
12595 and compiler support can be identified. After adding SIMD primitives
12596 to the core compiler and carrying them through to the various
12597 backends, there will be opportunities to design and implement an SML
12598 library that exposes the primitives to the SML programmer as well as
12599 opportunities to design and implement auto-vectorization
12600 optimizations.</simpara>
12601 <simpara>Background:</simpara>
12602 <itemizedlist>
12603 <listitem>
12604 <simpara>
12605 <ulink url="http://en.wikipedia.org/wiki/SIMD">SIMD</ulink>
12606 </simpara>
12607 </listitem>
12608 <listitem>
12609 <simpara>
12610 <ulink url="http://gcc.gnu.org/projects/tree-ssa/vectorization.html">Auto-vectorization in GCC</ulink>
12611 </simpara>
12612 </listitem>
12613 <listitem>
12614 <simpara>
12615 <ulink url="http://llvm.org/docs/Vectorizers.html">Auto-vectorization in LLVM</ulink>
12616 </simpara>
12617 </listitem>
12618 </itemizedlist>
12619 <simpara>Recommended Skills: SML programming experience; some compiler experience; some computer architecture experience</simpara>
12620 </section>
12621 <section id="_rtos_support">
12622 <title>RTOS Support</title>
12623 <simpara>This project entails porting the MLton compiler to RTOSs such as:
12624 RTEMS, RT Linux, and FreeRTOS. The project will include modifications
12625 to the MLton build and configuration process. Students will need to
12626 extend the MLton configuration process for each of the RTOSs. The
12627 MLton compilation process will need to be extended to invoke the C
12628 cross compilers the RTOSs provide for embedded support. Test scripts
12629 for validation will be necessary and these will need to be run in
12630 emulators for supported architectures.</simpara>
12631 <simpara>Recommended Skills: C programming experience; some scripting experience</simpara>
12632 </section>
12633 <section id="_region_based_memory_management">
12634 <title>Region Based Memory Management</title>
12635 <simpara>Region based memory management is an alternative automatic memory
12636 management scheme to garbage collection. Regions can be inferred by
12637 the compiler (e.g., Cyclone and MLKit) or provided to the programmer
12638 through a library. Since many students do not have extensive
12639 experience with compilers we plan on adopting the later approach.
12640 Creating a viable region based memory solution requires the removal of
12641 the GC and changes to the allocator. Additionally, write barriers
12642 will be necessary to ensure references between two ML objects is never
12643 established if the left hand side of the assignment has a longer
12644 lifetime than the right hand side. Students will need to come up with
12645 an appropriate interface for creating, entering, and exiting regions
12646 (examples include RTSJ scoped memory and SCJ scoped memory).</simpara>
12647 <simpara>Background:</simpara>
12648 <itemizedlist>
12649 <listitem>
12650 <simpara>
12651 Cyclone
12652 </simpara>
12653 </listitem>
12654 <listitem>
12655 <simpara>
12656 MLKit
12657 </simpara>
12658 </listitem>
12659 <listitem>
12660 <simpara>
12661 RTSJ + SCJ scopes
12662 </simpara>
12663 </listitem>
12664 </itemizedlist>
12665 <simpara>Recommended Skills: SML programming experience; C programming experience; some compiler and garbage collector experience</simpara>
12666 </section>
12667 <section id="_integration_of_multi_mlton">
12668 <title>Integration of Multi-MLton</title>
12669 <simpara><ulink url="http://multimlton.cs.purdue.edu">MultiMLton</ulink> is a compiler and runtime
12670 environment that targets scalable multicore platforms. It is an
12671 extension of MLton. It combines new language abstractions and
12672 associated compiler analyses for expressing and implementing various
12673 kinds of fine-grained parallelism (safe futures, speculation,
12674 transactions, etc.), along with a sophisticated runtime system tuned
12675 to efficiently handle large numbers of lightweight threads. The core
12676 stable features of MultiMLton will need to be integrated with the
12677 latest MLton public release. Certain experimental features, such as
12678 support for the Intel SCC and distributed runtime will be omitted.
12679 This project requires students to understand the delta between the
12680 MultiMLton code base and the MLton code base. Students will need to
12681 create build and configuration scripts for MLton to enable MultiMLton
12682 features.</simpara>
12683 <simpara>Background</simpara>
12684 <itemizedlist>
12685 <listitem>
12686 <simpara>
12687 <ulink url="http://multimlton.cs.purdue.edu/mML/Publications.html">MultiMLton&#8201;&#8212;&#8201;Publications</ulink>
12688 </simpara>
12689 </listitem>
12690 </itemizedlist>
12691 <simpara>Recommended Skills: SML programming experience; C programming experience; some compiler experience</simpara>
12692 <simpara><?asciidoc-pagebreak?></simpara>
12693 </section>
12694 </section>
12695 </section>
12696 <section id="GoogleSummerOfCode2014">
12697 <title>Google Summer of Code (2014)</title>
12698 <section id="_mentors_2">
12699 <title>Mentors</title>
12700 <simpara>The following developers have agreed to serve as mentors for the 2014 Google Summer of Code:</simpara>
12701 <itemizedlist>
12702 <listitem>
12703 <simpara>
12704 <ulink url="http://www.cs.rit.edu/%7Emtf">Matthew Fluet</ulink>
12705 </simpara>
12706 </listitem>
12707 <listitem>
12708 <simpara>
12709 <ulink url="http://www.cse.buffalo.edu/%7Elziarek/">Lukasz (Luke) Ziarek</ulink>
12710 </simpara>
12711 </listitem>
12712 <listitem>
12713 <simpara>
12714 <ulink url="http://people.cs.uchicago.edu/~jhr/">John Reppy</ulink>
12715 </simpara>
12716 </listitem>
12717 <listitem>
12718 <simpara>
12719 <ulink url="http://www.cs.purdue.edu/homes/chandras">KC Sivaramakrishnan</ulink>
12720 </simpara>
12721 </listitem>
12722 </itemizedlist>
12723 </section>
12724 <section id="_ideas_list_2">
12725 <title>Ideas List</title>
12726 <section id="_implement_a_partial_redundancy_elimination_pre_optimization_2">
12727 <title>Implement a Partial Redundancy Elimination (PRE) Optimization</title>
12728 <simpara>Partial redundancy elimination (PRE) is a program transformation that
12729 removes operations that are redundant on some, but not necessarily all
12730 paths, through the program. PRE can subsume both common subexpression
12731 elimination and loop-invariant code motion, and is therefore a
12732 potentially powerful optimization. However, a na&iuml;ve
12733 implementation of PRE on a program in static single assignment (SSA)
12734 form is unlikely to be effective. This project aims to adapt and
12735 implement the SSAPRE algorithm(s) of Thomas VanDrunen in MLton&#8217;s SSA
12736 intermediate language.</simpara>
12737 <simpara>Background:</simpara>
12738 <itemizedlist>
12739 <listitem>
12740 <simpara>
12741 <ulink url="http://onlinelibrary.wiley.com/doi/10.1002/spe.618/abstract">Anticipation-based partial redundancy elimination for static single assignment form</ulink>; Thomas VanDrunen and Antony L. Hosking
12742 </simpara>
12743 </listitem>
12744 <listitem>
12745 <simpara>
12746 <ulink url="http://cs.wheaton.edu/%7Etvandrun/writings/thesis.pdf">Partial Redundancy Elimination for Global Value Numbering</ulink>; Thomas VanDrunen
12747 </simpara>
12748 </listitem>
12749 <listitem>
12750 <simpara>
12751 <ulink url="http://www.springerlink.com/content/w06m3cw453nphm1u/">Value-Based Partial Redundancy Elimination</ulink>; Thomas VanDrunen and Antony L. Hosking
12752 </simpara>
12753 </listitem>
12754 <listitem>
12755 <simpara>
12756 <ulink url="http://portal.acm.org/citation.cfm?doid=319301.319348">Partial redundancy elimination in SSA form</ulink>; Robert Kennedy, Sun Chan, Shin-Ming Liu, Raymond Lo, Peng Tu, and Fred Chow
12757 </simpara>
12758 </listitem>
12759 </itemizedlist>
12760 <simpara>Recommended Skills: SML programming experience; some middle-end compiler experience</simpara>
12761 </section>
12762 <section id="_design_and_implement_a_heap_profiler_2">
12763 <title>Design and Implement a Heap Profiler</title>
12764 <simpara>A heap profile is a description of the space usage of a program. A
12765 heap profile is concerned with the allocation, retention, and
12766 deallocation (via garbage collection) of heap data during the
12767 execution of a program. A heap profile can be used to diagnose
12768 performance problems in a functional program that arise from space
12769 leaks. This project aims to design and implement a heap profiler for
12770 MLton compiled programs.</simpara>
12771 <simpara>Background:</simpara>
12772 <itemizedlist>
12773 <listitem>
12774 <simpara>
12775 <ulink url="http://portal.acm.org/citation.cfm?doid=583854.582451">GCspy: an adaptable heap visualisation framework</ulink>; Tony Printezis and Richard Jones
12776 </simpara>
12777 </listitem>
12778 <listitem>
12779 <simpara>
12780 <ulink url="http://journals.cambridge.org/action/displayAbstract?aid=1349892">New dimensions in heap profiling</ulink>; Colin Runciman and Niklas R&ouml;jemo
12781 </simpara>
12782 </listitem>
12783 <listitem>
12784 <simpara>
12785 <ulink url="http://www.springerlink.com/content/710501660722gw37/">Heap profiling for space efficiency</ulink>; Colin Runciman and Niklas R&ouml;jemo
12786 </simpara>
12787 </listitem>
12788 <listitem>
12789 <simpara>
12790 <ulink url="http://journals.cambridge.org/action/displayAbstract?aid=1323096">Heap profiling of lazy functional programs</ulink>; Colin Runciman and David Wakeling
12791 </simpara>
12792 </listitem>
12793 </itemizedlist>
12794 <simpara>Recommended Skills: C and SML programming experience; some experience with UI and visualization</simpara>
12795 </section>
12796 <section id="_garbage_collector_improvements_2">
12797 <title>Garbage Collector Improvements</title>
12798 <simpara>The garbage collector plays a significant role in the performance of
12799 functional languages. Garbage collect too often, and program
12800 performance suffers due to the excessive time spent in the garbage
12801 collector. Garbage collect not often enough, and program performance
12802 suffers due to the excessive space used by the uncollected garbage.
12803 One particular issue is ensuring that a program utilizing a garbage
12804 collector "plays nice" with other processes on the system, by not
12805 using too much or too little physical memory. While there are some
12806 reasonable theoretical results about garbage collections with heaps of
12807 fixed size, there seems to be insufficient work that really looks
12808 carefully at the question of dynamically resizing the heap in response
12809 to the live data demands of the application and, similarly, in
12810 response to the behavior of the operating system and other processes.
12811 This project aims to investigate improvements to the memory behavior of
12812 MLton compiled programs through better tuning of the garbage
12813 collector.</simpara>
12814 <simpara>Background:</simpara>
12815 <itemizedlist>
12816 <listitem>
12817 <simpara>
12818 <ulink url="http://www.dcs.gla.ac.uk/%7Ewhited/papers/automated_heap_sizing.pdf">Automated Heap Sizing in the Poly/ML Runtime (Position Paper)</ulink>; David White, Jeremy Singer, Jonathan Aitken, and David Matthews
12819 </simpara>
12820 </listitem>
12821 <listitem>
12822 <simpara>
12823 <ulink url="http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=4145125">Isla Vista Heap Sizing: Using Feedback to Avoid Paging</ulink>; Chris Grzegorczyk, Sunil Soman, Chandra Krintz, and Rich Wolski
12824 </simpara>
12825 </listitem>
12826 <listitem>
12827 <simpara>
12828 <ulink url="http://portal.acm.org/citation.cfm?doid=1152649.1152652">Controlling garbage collection and heap growth to reduce the execution time of Java applications</ulink>; Tim Brecht, Eshrat Arjomandi, Chang Li, and Hang Pham
12829 </simpara>
12830 </listitem>
12831 <listitem>
12832 <simpara>
12833 <ulink url="http://portal.acm.org/citation.cfm?doid=1065010.1065028">Garbage collection without paging</ulink>; Matthew Hertz, Yi Feng, and Emery D. Berger
12834 </simpara>
12835 </listitem>
12836 <listitem>
12837 <simpara>
12838 <ulink url="http://portal.acm.org/citation.cfm?doid=1029873.1029881">Automatic heap sizing: taking real memory into account</ulink>; Ting Yang, Matthew Hertz, Emery D. Berger, Scott F. Kaplan, and J. Eliot B. Moss
12839 </simpara>
12840 </listitem>
12841 </itemizedlist>
12842 <simpara>Recommended Skills: C programming experience; some operating systems and/or systems programming experience; some compiler and garbage collector experience</simpara>
12843 </section>
12844 <section id="_implement_successor_160_ml_language_features_2">
12845 <title>Implement Successor&#160;ML Language Features</title>
12846 <simpara>Any programming language, including Standard&#160;ML, can be improved.
12847 The community has identified a number of modest extensions and
12848 revisions to the Standard&#160;ML programming language that would
12849 likely prove useful in practice. This project aims to implement these
12850 language features in the MLton compiler.</simpara>
12851 <simpara>Background:</simpara>
12852 <itemizedlist>
12853 <listitem>
12854 <simpara>
12855 <ulink url="http://successor-ml.org/index.php?title=Main_Page">Successor&#160;ML</ulink>
12856 </simpara>
12857 </listitem>
12858 <listitem>
12859 <simpara>
12860 <ulink url="http://www.mpi-sws.org/%7Erossberg/hamlet/index.html#successor-ml">HaMLet (Successor&#160;ML)</ulink>
12861 </simpara>
12862 </listitem>
12863 <listitem>
12864 <simpara>
12865 <ulink url="http://journals.cambridge.org/action/displayAbstract?aid=1322628">A critique of Standard&#160;ML</ulink>; Andrew W. Appel
12866 </simpara>
12867 </listitem>
12868 </itemizedlist>
12869 <simpara>Recommended Skills: SML programming experience; some front-end compiler experience (i.e., scanners and parsers)</simpara>
12870 </section>
12871 <section id="_implement_source_level_debugging_2">
12872 <title>Implement Source-level Debugging</title>
12873 <simpara>Debugging is a fact of programming life. Unfortunately, most SML
12874 implementations (including MLton) provide little to no source-level
12875 debugging support. This project aims to add basic to intermediate
12876 source-level debugging support to the MLton compiler. MLton already
12877 supports source-level profiling, which can be used to attribute bytes
12878 allocated or time spent in source functions. It should be relatively
12879 straightforward to leverage this source-level information into basic
12880 source-level debugging support, with the ability to set/unset
12881 breakpoints and step through declarations and functions. It may be
12882 possible to also provide intermediate source-level debugging support,
12883 with the ability to inspect in-scope variables of basic types (e.g.,
12884 types compatible with MLton&#8217;s foreign function interface).</simpara>
12885 <simpara>Background:</simpara>
12886 <itemizedlist>
12887 <listitem>
12888 <simpara>
12889 <ulink url="http://mlton.org/HowProfilingWorks">MLton&#8201;&#8212;&#8201;How Profiling Works</ulink>
12890 </simpara>
12891 </listitem>
12892 <listitem>
12893 <simpara>
12894 <ulink url="http://mlton.org/ForeignFunctionInterfaceTypes">MLton&#8201;&#8212;&#8201;Foreign Function Interface Types</ulink>
12895 </simpara>
12896 </listitem>
12897 <listitem>
12898 <simpara>
12899 <ulink url="http://dwarfstd.org/">DWARF Debugging Standard</ulink>
12900 </simpara>
12901 </listitem>
12902 <listitem>
12903 <simpara>
12904 <ulink url="http://sourceware.org/gdb/current/onlinedocs/stabs/index.html">STABS Debugging Format</ulink>
12905 </simpara>
12906 </listitem>
12907 </itemizedlist>
12908 <simpara>Recommended Skills: SML programming experience; some compiler experience</simpara>
12909 </section>
12910 <section id="_region_based_memory_management_2">
12911 <title>Region Based Memory Management</title>
12912 <simpara>Region based memory management is an alternative automatic memory
12913 management scheme to garbage collection. Regions can be inferred by
12914 the compiler (e.g., Cyclone and MLKit) or provided to the programmer
12915 through a library. Since many students do not have extensive
12916 experience with compilers we plan on adopting the later approach.
12917 Creating a viable region based memory solution requires the removal of
12918 the GC and changes to the allocator. Additionally, write barriers
12919 will be necessary to ensure references between two ML objects is never
12920 established if the left hand side of the assignment has a longer
12921 lifetime than the right hand side. Students will need to come up with
12922 an appropriate interface for creating, entering, and exiting regions
12923 (examples include RTSJ scoped memory and SCJ scoped memory).</simpara>
12924 <simpara>Background:</simpara>
12925 <itemizedlist>
12926 <listitem>
12927 <simpara>
12928 Cyclone
12929 </simpara>
12930 </listitem>
12931 <listitem>
12932 <simpara>
12933 MLKit
12934 </simpara>
12935 </listitem>
12936 <listitem>
12937 <simpara>
12938 RTSJ + SCJ scopes
12939 </simpara>
12940 </listitem>
12941 </itemizedlist>
12942 <simpara>Recommended Skills: SML programming experience; C programming experience; some compiler and garbage collector experience</simpara>
12943 </section>
12944 <section id="_integration_of_multi_mlton_2">
12945 <title>Integration of Multi-MLton</title>
12946 <simpara><ulink url="http://multimlton.cs.purdue.edu">MultiMLton</ulink> is a compiler and runtime
12947 environment that targets scalable multicore platforms. It is an
12948 extension of MLton. It combines new language abstractions and
12949 associated compiler analyses for expressing and implementing various
12950 kinds of fine-grained parallelism (safe futures, speculation,
12951 transactions, etc.), along with a sophisticated runtime system tuned
12952 to efficiently handle large numbers of lightweight threads. The core
12953 stable features of MultiMLton will need to be integrated with the
12954 latest MLton public release. Certain experimental features, such as
12955 support for the Intel SCC and distributed runtime will be omitted.
12956 This project requires students to understand the delta between the
12957 MultiMLton code base and the MLton code base. Students will need to
12958 create build and configuration scripts for MLton to enable MultiMLton
12959 features.</simpara>
12960 <simpara>Background</simpara>
12961 <itemizedlist>
12962 <listitem>
12963 <simpara>
12964 <ulink url="http://multimlton.cs.purdue.edu/mML/Publications.html">MultiMLton&#8201;&#8212;&#8201;Publications</ulink>
12965 </simpara>
12966 </listitem>
12967 </itemizedlist>
12968 <simpara>Recommended Skills: SML programming experience; C programming experience; some compiler experience</simpara>
12969 </section>
12970 <section id="_concurrent_160_ml_improvements">
12971 <title>Concurrent&#160;ML Improvements</title>
12972 <simpara><ulink url="http://cml.cs.uchicago.edu/">Concurrent ML</ulink> is an SML concurrency
12973 library based on synchronous message passing. MLton has a partial
12974 implementation of the CML message-passing primitives, but its use in
12975 real-world applications has been stymied by the lack of completeness
12976 and thread-safe I/O libraries. This project would aim to flesh out
12977 the CML implementation in MLton to be fully compatible with the
12978 "official" version distributed as part of SML/NJ. Furthermore, time
12979 permitting, runtime system support could be added to allow use of
12980 modern OS features, such as asynchronous I/O, in the implementation of
12981 CML&#8217;s system interfaces.</simpara>
12982 <simpara>Background</simpara>
12983 <itemizedlist>
12984 <listitem>
12985 <simpara>
12986 <ulink url="http://cml.cs.uchicago.edu/">http://cml.cs.uchicago.edu/</ulink>
12987 </simpara>
12988 </listitem>
12989 <listitem>
12990 <simpara>
12991 <ulink url="http://mlton.org/ConcurrentML">http://mlton.org/ConcurrentML</ulink>
12992 </simpara>
12993 </listitem>
12994 <listitem>
12995 <simpara>
12996 <ulink url="http://mlton.org/ConcurrentMLImplementation">http://mlton.org/ConcurrentMLImplementation</ulink>
12997 </simpara>
12998 </listitem>
12999 </itemizedlist>
13000 <simpara>Recommended Skills: SML programming experience; knowledge of concurrent programming; some operating systems and/or systems programming experience</simpara>
13001 <simpara><?asciidoc-pagebreak?></simpara>
13002 </section>
13003 </section>
13004 </section>
13005 <section id="GoogleSummerOfCode2015">
13006 <title>Google Summer of Code (2015)</title>
13007 <section id="_mentors_3">
13008 <title>Mentors</title>
13009 <simpara>The following developers have agreed to serve as mentors for the 2015 Google Summer of Code:</simpara>
13010 <itemizedlist>
13011 <listitem>
13012 <simpara>
13013 <ulink url="http://www.cs.rit.edu/%7Emtf">Matthew Fluet</ulink>
13014 </simpara>
13015 </listitem>
13016 <listitem>
13017 <simpara>
13018 <ulink url="http://www.cse.buffalo.edu/%7Elziarek/">Lukasz (Luke) Ziarek</ulink>
13019 </simpara>
13020 </listitem>
13021 </itemizedlist>
13022 </section>
13023 <section id="_ideas_list_3">
13024 <title>Ideas List</title>
13025 <section id="_design_and_implement_a_heap_profiler_3">
13026 <title>Design and Implement a Heap Profiler</title>
13027 <simpara>A heap profile is a description of the space usage of a program. A
13028 heap profile is concerned with the allocation, retention, and
13029 deallocation (via garbage collection) of heap data during the
13030 execution of a program. A heap profile can be used to diagnose
13031 performance problems in a functional program that arise from space
13032 leaks. This project aims to design and implement a heap profiler for
13033 MLton compiled programs.</simpara>
13034 <simpara>Background:</simpara>
13035 <itemizedlist>
13036 <listitem>
13037 <simpara>
13038 <ulink url="http://portal.acm.org/citation.cfm?doid=583854.582451">GCspy: an adaptable heap visualisation framework</ulink>; Tony Printezis and Richard Jones
13039 </simpara>
13040 </listitem>
13041 <listitem>
13042 <simpara>
13043 <ulink url="http://journals.cambridge.org/action/displayAbstract?aid=1349892">New dimensions in heap profiling</ulink>; Colin Runciman and Niklas R&ouml;jemo
13044 </simpara>
13045 </listitem>
13046 <listitem>
13047 <simpara>
13048 <ulink url="http://www.springerlink.com/content/710501660722gw37/">Heap profiling for space efficiency</ulink>; Colin Runciman and Niklas R&ouml;jemo
13049 </simpara>
13050 </listitem>
13051 <listitem>
13052 <simpara>
13053 <ulink url="http://journals.cambridge.org/action/displayAbstract?aid=1323096">Heap profiling of lazy functional programs</ulink>; Colin Runciman and David Wakeling
13054 </simpara>
13055 </listitem>
13056 </itemizedlist>
13057 <simpara>Recommended Skills: C and SML programming experience; some experience with UI and visualization</simpara>
13058 </section>
13059 <section id="_garbage_collector_improvements_3">
13060 <title>Garbage Collector Improvements</title>
13061 <simpara>The garbage collector plays a significant role in the performance of
13062 functional languages. Garbage collect too often, and program
13063 performance suffers due to the excessive time spent in the garbage
13064 collector. Garbage collect not often enough, and program performance
13065 suffers due to the excessive space used by the uncollected
13066 garbage. One particular issue is ensuring that a program utilizing a
13067 garbage collector "plays nice" with other processes on the system, by
13068 not using too much or too little physical memory. While there are some
13069 reasonable theoretical results about garbage collections with heaps of
13070 fixed size, there seems to be insufficient work that really looks
13071 carefully at the question of dynamically resizing the heap in response
13072 to the live data demands of the application and, similarly, in
13073 response to the behavior of the operating system and other
13074 processes. This project aims to investigate improvements to the memory
13075 behavior of MLton compiled programs through better tuning of the
13076 garbage collector.</simpara>
13077 <simpara>Background:</simpara>
13078 <itemizedlist>
13079 <listitem>
13080 <simpara>
13081 <ulink url="http://gchandbook.org/">The Garbage Collection Handbook: The Art of Automatic Memory Management</ulink>; Richard Jones, Antony Hosking, Eliot Moss
13082 </simpara>
13083 </listitem>
13084 <listitem>
13085 <simpara>
13086 <ulink url="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.24.1020">Dual-Mode Garbage Collection</ulink>; Patrick Sansom
13087 </simpara>
13088 </listitem>
13089 <listitem>
13090 <simpara>
13091 <ulink url="http://portal.acm.org/citation.cfm?doid=1029873.1029881">Automatic Heap Sizing: Taking Real Memory into Account</ulink>; Ting Yang, Matthew Hertz, Emery D. Berger, Scott F. Kaplan, and J. Eliot B. Moss
13092 </simpara>
13093 </listitem>
13094 <listitem>
13095 <simpara>
13096 <ulink url="http://portal.acm.org/citation.cfm?doid=1152649.1152652">Controlling Garbage Collection and Heap Growth to Reduce the Execution Time of Java Applications</ulink>; Tim Brecht, Eshrat Arjomandi, Chang Li, and Hang Pham
13097 </simpara>
13098 </listitem>
13099 <listitem>
13100 <simpara>
13101 <ulink url="http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=4145125">Isla Vista Heap Sizing: Using Feedback to Avoid Paging</ulink>; Chris Grzegorczyk, Sunil Soman, Chandra Krintz, and Rich Wolski
13102 </simpara>
13103 </listitem>
13104 <listitem>
13105 <simpara>
13106 <ulink url="http://portal.acm.org/citation.cfm?doid=1806651.1806669">The Economics of Garbage Collection</ulink>; Jeremy Singer, Richard E. Jones, Gavin Brown, and Mikel Luján
13107 </simpara>
13108 </listitem>
13109 <listitem>
13110 <simpara>
13111 <ulink url="http://www.dcs.gla.ac.uk/%7Ejsinger/pdfs/tfp12.pdf">Automated Heap Sizing in the Poly/ML Runtime (Position Paper)</ulink>; David White, Jeremy Singer, Jonathan Aitken, and David Matthews
13112 </simpara>
13113 </listitem>
13114 <listitem>
13115 <simpara>
13116 <ulink url="http://portal.acm.org/citation.cfm?doid=2555670.2466481">Control Theory for Principled Heap Sizing</ulink>; David R. White, Jeremy Singer, Jonathan M. Aitken, and Richard E. Jones
13117 </simpara>
13118 </listitem>
13119 </itemizedlist>
13120 <simpara>Recommended Skills: C programming experience; some operating systems and/or systems programming experience; some compiler and garbage collector experience</simpara>
13121 </section>
13122 <section id="_heap_allocated_activation_records">
13123 <title>Heap-allocated Activation Records</title>
13124 <simpara>Activation records (a.k.a., stack frames) are traditionally allocated
13125 on a stack. This naturally corresponds to the call-return pattern of
13126 function invocation. However, there are some disadvantages to
13127 stack-allocated activation records. In a functional programming
13128 language, functions may be deeply recursive, resulting in call stacks
13129 that are much larger than typically supported by the operating system;
13130 hence, a functional programming language implementation will typically
13131 store its stack in its heap. Furthermore, a functional programming
13132 language implementation must handle and recover from stack overflow,
13133 by allocating a larger stack (again, in its heap) and copying
13134 activation records from the old stack to the new stack. In the
13135 presence of threads, stacks must be allocated in a heap and, in the
13136 presence of a garbage collector, should be garbage collected when
13137 unreachable. While heap-allocated activation records avoid many of
13138 these disadvantages, they have not been widely implemented. This
13139 project aims to implement and evaluate heap-allocated activation
13140 records in the MLton compiler.</simpara>
13141 <simpara>Background:</simpara>
13142 <itemizedlist>
13143 <listitem>
13144 <simpara>
13145 <ulink url="http://journals.cambridge.org/action/displayAbstract?aid=1295104">Empirical and Analytic Study of Stack Versus Heap Cost for Languages with Closures</ulink>; Andrew W. Appel and Zhong Shao
13146 </simpara>
13147 </listitem>
13148 <listitem>
13149 <simpara>
13150 <ulink url="http://portal.acm.org/citation.cfm?doid=182590.156783">Space-efficient closure representations</ulink>; Zhong Shao and Andrew W. Appel
13151 </simpara>
13152 </listitem>
13153 <listitem>
13154 <simpara>
13155 <ulink url="http://portal.acm.org/citation.cfm?doid=93548.93554">Representing control in the presence of first-class continuations</ulink>; R. Hieb, R. Kent Dybvig, and Carl Bruggeman
13156 </simpara>
13157 </listitem>
13158 </itemizedlist>
13159 <simpara>Recommended Skills: SML programming experience; some middle- and back-end compiler experience</simpara>
13160 </section>
13161 <section id="_correctly_rounded_floating_point_binary_to_decimal_and_decimal_to_binary_conversion_routines_in_standard_ml">
13162 <title>Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML</title>
13163 <simpara>The
13164 <ulink url="http://en.wikipedia.org/wiki/IEEE_754-2008">IEEE Standard for Floating-Point Arithmetic (IEEE 754)</ulink>
13165 is the de facto representation for floating-point computation.
13166 However, it is a <emphasis>binary</emphasis> (base 2) representation of floating-point
13167 values, while many applications call for input and output of
13168 floating-point values in <emphasis>decimal</emphasis> (base 10) representation. The
13169 <emphasis>decimal-to-binary</emphasis> conversion problem takes a decimal floating-point
13170 representation (e.g., a string like <literal>"0.1"</literal>) and returns the best
13171 binary floating-point representation of that number. The
13172 <emphasis>binary-to-decimal</emphasis> conversion problem takes a binary floating-point
13173 representation and returns a decimal floating-point representation
13174 using the smallest number of digits that allow the decimal
13175 floating-point representation to be converted to the original binary
13176 floating-point representation. For both conversion routines, "best"
13177 is dependent upon the current floating-point rounding mode.</simpara>
13178 <simpara>MLton uses David Gay&#8217;s
13179 <ulink url="http://www.netlib.org/fp/gdtoa.tgz">gdtoa library</ulink> for floating-point
13180 conversions. While this is an exellent library, it generalizes the
13181 decimal-to-binary and binary-to-decimal conversion routines beyond
13182 what is required by the
13183 <ulink url="http://standardml.org/Basis/">Standard ML Basis Library</ulink> and induces an
13184 external dependency on the compiler. Native implementations of these
13185 conversion routines in Standard ML would obviate the dependency on the
13186 <literal>gdtoa</literal> library, while also being able to take advantage of Standard
13187 ML features in the implementation (e.g., the published algorithms
13188 often require use of infinite precision arithmetic, which is provided
13189 by the <literal>IntInf</literal> structure in Standard ML, but is provided in an ad hoc
13190 fasion in the <literal>gdtoa</literal> library).</simpara>
13191 <simpara>This project aims to develop a native implementation of the conversion
13192 routines in Standard ML.</simpara>
13193 <simpara>Background:</simpara>
13194 <itemizedlist>
13195 <listitem>
13196 <simpara>
13197 <ulink url="http://dl.acm.org/citation.cfm?doid=103162.103163">What every computer scientist should know about floating-point arithmetic</ulink>; David Goldberg
13198 </simpara>
13199 </listitem>
13200 <listitem>
13201 <simpara>
13202 <ulink url="http://dl.acm.org/citation.cfm?doid=93542.93559">How to print floating-point numbers accurately</ulink>; Guy L. Steele, Jr. and Jon L. White
13203 </simpara>
13204 </listitem>
13205 <listitem>
13206 <simpara>
13207 <ulink url="http://dl.acm.org/citation.cfm?doid=93542.93557">How to read floating point numbers accurately</ulink>; William D. Clinger
13208 </simpara>
13209 </listitem>
13210 <listitem>
13211 <simpara>
13212 <ulink url="http://cm.bell-labs.com/cm/cs/doc/90/4-10.ps.gz">Correctly Rounded Binary-Decimal and Decimal-Binary Conversions</ulink>; David Gay
13213 </simpara>
13214 </listitem>
13215 <listitem>
13216 <simpara>
13217 <ulink url="http://dl.acm.org/citation.cfm?doid=249069.231397">Printing floating-point numbers quickly and accurately</ulink>; Robert G. Burger and R. Kent Dybvig
13218 </simpara>
13219 </listitem>
13220 <listitem>
13221 <simpara>
13222 <ulink url="http://dl.acm.org/citation.cfm?doid=1806596.1806623">Printing floating-point numbers quickly and accurately with integers</ulink>; Florian Loitsch
13223 </simpara>
13224 </listitem>
13225 </itemizedlist>
13226 <simpara>Recommended Skills: SML programming experience; algorithm design and implementation</simpara>
13227 </section>
13228 <section id="_implement_source_level_debugging_3">
13229 <title>Implement Source-level Debugging</title>
13230 <simpara>Debugging is a fact of programming life. Unfortunately, most SML
13231 implementations (including MLton) provide little to no source-level
13232 debugging support. This project aims to add basic to intermediate
13233 source-level debugging support to the MLton compiler. MLton already
13234 supports source-level profiling, which can be used to attribute bytes
13235 allocated or time spent in source functions. It should be relatively
13236 straightforward to leverage this source-level information into basic
13237 source-level debugging support, with the ability to set/unset
13238 breakpoints and step through declarations and functions. It may be
13239 possible to also provide intermediate source-level debugging support,
13240 with the ability to inspect in-scope variables of basic types (e.g.,
13241 types compatible with MLton&#8217;s foreign function interface).</simpara>
13242 <simpara>Background:</simpara>
13243 <itemizedlist>
13244 <listitem>
13245 <simpara>
13246 <ulink url="http://mlton.org/HowProfilingWorks">MLton&#8201;&#8212;&#8201;How Profiling Works</ulink>
13247 </simpara>
13248 </listitem>
13249 <listitem>
13250 <simpara>
13251 <ulink url="http://mlton.org/ForeignFunctionInterfaceTypes">MLton&#8201;&#8212;&#8201;Foreign Function Interface Types</ulink>
13252 </simpara>
13253 </listitem>
13254 <listitem>
13255 <simpara>
13256 <ulink url="http://dwarfstd.org/">DWARF Debugging Standard</ulink>
13257 </simpara>
13258 </listitem>
13259 <listitem>
13260 <simpara>
13261 <ulink url="http://sourceware.org/gdb/current/onlinedocs/stabs/index.html">STABS Debugging Format</ulink>
13262 </simpara>
13263 </listitem>
13264 </itemizedlist>
13265 <simpara>Recommended Skills: SML programming experience; some compiler experience</simpara>
13266 </section>
13267 <section id="_region_based_memory_management_3">
13268 <title>Region Based Memory Management</title>
13269 <simpara>Region based memory management is an alternative automatic memory
13270 management scheme to garbage collection. Regions can be inferred by
13271 the compiler (e.g., Cyclone and MLKit) or provided to the programmer
13272 through a library. Since many students do not have extensive
13273 experience with compilers we plan on adopting the later approach.
13274 Creating a viable region based memory solution requires the removal of
13275 the GC and changes to the allocator. Additionally, write barriers
13276 will be necessary to ensure references between two ML objects is never
13277 established if the left hand side of the assignment has a longer
13278 lifetime than the right hand side. Students will need to come up with
13279 an appropriate interface for creating, entering, and exiting regions
13280 (examples include RTSJ scoped memory and SCJ scoped memory).</simpara>
13281 <simpara>Background:</simpara>
13282 <itemizedlist>
13283 <listitem>
13284 <simpara>
13285 Cyclone
13286 </simpara>
13287 </listitem>
13288 <listitem>
13289 <simpara>
13290 MLKit
13291 </simpara>
13292 </listitem>
13293 <listitem>
13294 <simpara>
13295 RTSJ + SCJ scopes
13296 </simpara>
13297 </listitem>
13298 </itemizedlist>
13299 <simpara>Recommended Skills: SML programming experience; C programming experience; some compiler and garbage collector experience</simpara>
13300 </section>
13301 <section id="_adding_real_time_capabilities">
13302 <title>Adding Real-Time Capabilities</title>
13303 <simpara>This project focuses on exposing real-time APIs from a real-time OS
13304 kernel at the SML level. This will require mapping the current MLton
13305 (or <ulink url="http://multimlton.cs.purdue.edu">MultiMLton</ulink>) threading framework
13306 to real-time threads that the RTOS provides. This will include
13307 associating priorities with MLton threads and building priority based
13308 scheduling algorithms. Additionally, support for perdioc, aperiodic,
13309 and sporadic tasks should be supported. A real-time SML library will
13310 need to be created to provide a forward facing interface for
13311 programmers. Stretch goals include reworking the MLton <literal>atomic</literal>
13312 statement and associated synchronization primitives built on top of
13313 the MLton <literal>atomic</literal> statement.</simpara>
13314 <simpara>Recommended Skills: SML programming experience; C programming experience; real-time experience a plus but not required</simpara>
13315 </section>
13316 <section id="_real_time_garbage_collection">
13317 <title>Real-Time Garbage Collection</title>
13318 <simpara>This project focuses on modifications to the MLton GC to support
13319 real-time garbage collection. We will model the real-time GC on the
13320 Schism RTGC. The first task will be to create a fixed size runtime
13321 object representation. Large structures will need to be represented
13322 as a linked lists of fixed sized objects. Arrays and vectors will be
13323 transferred into dense trees. Compaction and copying can therefore be
13324 removed from the GC algorithms that MLton currently supports. Lastly,
13325 the GC will be made concurrent, allowing for the execution of the GC
13326 threads as the lowest priority task in the system. Stretch goals
13327 include a priority aware mechanism for the GC to signal to real-time
13328 ML threads that it needs to scan their stack and identification of
13329 places where the stack is shallow to bound priority inversion during
13330 this procedure.</simpara>
13331 <simpara>Recommended Skills: C programming experience; garbage collector experience a plus but not required</simpara>
13332 <simpara><?asciidoc-pagebreak?></simpara>
13333 </section>
13334 </section>
13335 </section>
13336 <section id="HaMLet">
13337 <title>HaMLet</title>
13338 <simpara><ulink url="http://www.mpi-sws.org/~rossberg/hamlet/">HaMLet</ulink> is a
13339 <link linkend="StandardMLImplementations">Standard ML implementation</link>. It is
13340 intended as reference implementation of
13341 <link linkend="DefinitionOfStandardML">The Definition of Standard ML (Revised)</link> and
13342 not for serious practical work.</simpara>
13343 <simpara><?asciidoc-pagebreak?></simpara>
13344 </section>
13345 <section id="HenryCejtin">
13346 <title>HenryCejtin</title>
13347 <simpara>I was one of the original developers of Mathematica (actually employee #1).
13348 My background is a combination of mathematics and computer science.
13349 Currently I am doing various things in Chicago.</simpara>
13350 <simpara><?asciidoc-pagebreak?></simpara>
13351 </section>
13352 <section id="History">
13353 <title>History</title>
13354 <simpara>In April 1997, Stephen Weeks wrote a defunctorizer for Standard ML and
13355 integrated it with SML/NJ. The defunctorizer used SML/NJ&#8217;s visible
13356 compiler and operated on the <literal>Ast</literal> intermediate representation
13357 produced by the SML/NJ front end. Experiments showed that
13358 defunctorization gave a speedup of up to six times over separate
13359 compilation and up to two times over batch compilation without functor
13360 expansion.</simpara>
13361 <simpara>In August 1997, we began development of an independent compiler for
13362 SML. At the time the compiler was called <literal>smlc</literal>. By October, we had
13363 a working monomorphiser. By November, we added a polyvariant
13364 higher-order control-flow analysis. At that point, MLton was about
13365 10,000 lines of code.</simpara>
13366 <simpara>Over the next year and half, <literal>smlc</literal> morphed into a full-fledged
13367 compiler for SML. It was renamed MLton, and first released in March
13368 1999.</simpara>
13369 <simpara>From the start, MLton has been driven by whole-program optimization
13370 and an emphasis on performance. Also from the start, MLton has had a
13371 fast C FFI and <literal>IntInf</literal> based on the GNU multiprecision library. At
13372 its first release, MLton was 48,006 lines.</simpara>
13373 <simpara>Between the March 1999 and January 2002, MLton grew to 102,541 lines,
13374 as we added a native code generator, mllex, mlyacc, a profiler, many
13375 optimizations, and many libraries including threads and signal
13376 handling.</simpara>
13377 <simpara>During 2002, MLton grew to 112,204 lines and we had releases in April
13378 and September. We added support for cross compilation and used this
13379 to enable MLton to run on Cygwin/Windows and FreeBSD. We also made
13380 improvements to the garbage collector, so that it now works with large
13381 arrays and up to 4G of memory and so that it automatically uses
13382 copying, mark-compact, or generational collection depending on heap
13383 usage and RAM size. We also continued improvements to the optimizer
13384 and libraries.</simpara>
13385 <simpara>During 2003, MLton grew to 122,299 lines and we had releases in March
13386 and July. We extended the profiler to support source-level profiling
13387 of time and allocation and to display call graphs. We completed the
13388 Basis Library implementation, and added new MLton-specific libraries
13389 for weak pointers and finalization. We extended the FFI to allow
13390 callbacks from C to SML. We added support for the Sparc/Solaris
13391 platform, and made many improvements to the C code generator.</simpara>
13392 <simpara><?asciidoc-pagebreak?></simpara>
13393 </section>
13394 <section id="HowProfilingWorks">
13395 <title>HowProfilingWorks</title>
13396 <simpara>Here&#8217;s how <link linkend="Profiling">Profiling</link> works. If profiling is on, the front end
13397 (elaborator) inserts <literal>Enter</literal> and <literal>Leave</literal> statements into the source
13398 program for function entry and exit. For example,</simpara>
13399 <programlisting language="sml" linenumbering="unnumbered">fun f n = if n = 0 then 0 else 1 + f (n - 1)</programlisting>
13400 <simpara>becomes</simpara>
13401 <programlisting language="sml" linenumbering="unnumbered">fun f n =
13402 let
13403 val () = Enter "f"
13404 val res = (if n = 0 then 0 else 1 + f (n - 1))
13405 handle e =&gt; (Leave "f"; raise e)
13406 val () = Leave "f"
13407 in
13408 res
13409 end</programlisting>
13410 <simpara>Actually there is a bit more information than just the source function
13411 name; there is also lexical nesting and file position.</simpara>
13412 <simpara>Most of the middle of the compiler ignores, but preserves, <literal>Enter</literal> and
13413 <literal>Leave</literal>. However, so that profiling preserves tail calls, the
13414 <link linkend="Shrink">SSA shrinker</link> has an optimization that notices when the only
13415 operations that cause a call to be a nontail call are profiling
13416 operations, and if so, moves them before the call, turning it into a
13417 tail call. If you observe a program that has a tail call that appears
13418 to be turned into a nontail when compiled with profiling, please
13419 <link linkend="Bug">report a bug</link>.</simpara>
13420 <simpara>There is the <literal>checkProf</literal> function in
13421 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/type-check.fun"><literal>type-check.fun</literal></ulink>, which checks that
13422 the <literal>Enter</literal>/<literal>Leave</literal> statements match up.</simpara>
13423 <simpara>In the backend, just before translating to the <link linkend="Machine">Machine IL</link>,
13424 the profiler uses the <literal>Enter</literal>/<literal>Leave</literal> statements to infer the "local"
13425 portion of the control stack at each program point. The profiler then
13426 removes the <literal>Enter</literal>s/<literal>Leave</literal>s and inserts different information
13427 depending on which kind of profiling is happening. For time profiling
13428 (with the <link linkend="AMD64Codegen">AMD64Codegen</link> and <link linkend="X86Codegen">X86Codegen</link>), the profiler inserts labels that cover the
13429 code (i.e. each statement has a unique label in its basic block that
13430 prefixes it) and associates each label with the local control stack.
13431 For time profiling (with the <link linkend="CCodegen">CCodegen</link> and <link linkend="LLVMCodegen">LLVMCodegen</link>), the profiler
13432 inserts code that sets a global field that records the local control
13433 stack. For allocation profiling, the profiler inserts calls to a C
13434 function that will maintain byte counts. With stack profiling, the
13435 profiler also inserts a call to a C function at each nontail call in
13436 order to maintain information at runtime about what SML functions are
13437 on the stack.</simpara>
13438 <simpara>At run time, the profiler associates counters (either clock ticks or
13439 byte counts) with source functions. When the program finishes, the
13440 profiler writes the counts out to the <literal>mlmon.out</literal> file. Then,
13441 <literal>mlprof</literal> uses source information stored in the executable to
13442 associate the counts in the <literal>mlmon.out</literal> file with source
13443 functions.</simpara>
13444 <simpara>For time profiling, the profiler catches the <literal>SIGPROF</literal> signal 100
13445 times per second and increments the appropriate counter, determined by
13446 looking at the label prefixing the current program counter and mapping
13447 that to the current source function.</simpara>
13448 <section id="_caveats_2">
13449 <title>Caveats</title>
13450 <simpara>There may be a few missed clock ticks or bytes allocated at the very
13451 end of the program after the data is written.</simpara>
13452 <simpara>Profiling has not been tested with signals or threads. In particular,
13453 stack profiling may behave strangely.</simpara>
13454 <simpara><?asciidoc-pagebreak?></simpara>
13455 </section>
13456 </section>
13457 <section id="Identifier">
13458 <title>Identifier</title>
13459 <simpara>In <link linkend="StandardML">Standard ML</link>, there are syntactically two kinds of
13460 identifiers.</simpara>
13461 <itemizedlist>
13462 <listitem>
13463 <simpara>
13464 Alphanumeric: starts with a letter or prime (<literal>'</literal>) and is followed by letters, digits, primes and underbars (<literal>_</literal>).
13465 </simpara>
13466 <simpara>Examples: <literal>abc</literal>, <literal>ABC123</literal>, <literal>Abc_123</literal>, <literal>'a</literal>.</simpara>
13467 </listitem>
13468 <listitem>
13469 <simpara>
13470 Symbolic: a sequence of the following
13471 </simpara>
13472 <screen> ! % &amp; $ # + - / : &lt; = &gt; ? @ | ~ ` ^ | *</screen>
13473 <simpara>Examples: <literal>+=</literal>, <literal>&lt;=</literal>, <literal>&gt;&gt;</literal>, <literal>$</literal>.</simpara>
13474 </listitem>
13475 </itemizedlist>
13476 <simpara>With the exception of <literal>=</literal>, reserved words can not be identifiers.</simpara>
13477 <simpara>There are a number of different classes of identifiers, some of which
13478 have additional syntactic rules.</simpara>
13479 <itemizedlist>
13480 <listitem>
13481 <simpara>
13482 Identifiers not starting with a prime.
13483 </simpara>
13484 <itemizedlist>
13485 <listitem>
13486 <simpara>
13487 value identifier (includes variables and constructors)
13488 </simpara>
13489 </listitem>
13490 <listitem>
13491 <simpara>
13492 type constructor
13493 </simpara>
13494 </listitem>
13495 <listitem>
13496 <simpara>
13497 structure identifier
13498 </simpara>
13499 </listitem>
13500 <listitem>
13501 <simpara>
13502 signature identifier
13503 </simpara>
13504 </listitem>
13505 <listitem>
13506 <simpara>
13507 functor identifier
13508 </simpara>
13509 </listitem>
13510 </itemizedlist>
13511 </listitem>
13512 <listitem>
13513 <simpara>
13514 Identifiers starting with a prime.
13515 </simpara>
13516 <itemizedlist>
13517 <listitem>
13518 <simpara>
13519 type variable
13520 </simpara>
13521 </listitem>
13522 </itemizedlist>
13523 </listitem>
13524 <listitem>
13525 <simpara>
13526 Identifiers not starting with a prime and numeric labels (<literal>1</literal>, <literal>2</literal>, &#8230;).
13527 </simpara>
13528 <itemizedlist>
13529 <listitem>
13530 <simpara>
13531 record label
13532 </simpara>
13533 </listitem>
13534 </itemizedlist>
13535 </listitem>
13536 </itemizedlist>
13537 <simpara><?asciidoc-pagebreak?></simpara>
13538 </section>
13539 <section id="Immutable">
13540 <title>Immutable</title>
13541 <simpara>Immutable means not <link linkend="Mutable">mutable</link> and is an adjective meaning
13542 "can not be modified". Most values in <link linkend="StandardML">Standard ML</link> are
13543 immutable. For example, constants, tuples, records, lists, and
13544 vectors are all immutable.</simpara>
13545 <simpara><?asciidoc-pagebreak?></simpara>
13546 </section>
13547 <section id="ImperativeTypeVariable">
13548 <title>ImperativeTypeVariable</title>
13549 <simpara>In <link linkend="StandardML">Standard ML</link>, an imperative type variable is a type
13550 variable whose second character is a digit, as in <literal>'1a</literal> or
13551 <literal>'2b</literal>. Imperative type variables were used as an alternative to
13552 the <link linkend="ValueRestriction">ValueRestriction</link> in an earlier version of SML, but no longer play
13553 a role. They are treated exactly as other type variables.</simpara>
13554 <simpara><?asciidoc-pagebreak?></simpara>
13555 </section>
13556 <section id="ImplementExceptions">
13557 <title>ImplementExceptions</title>
13558 <simpara><link linkend="ImplementExceptions">ImplementExceptions</link> is a pass for the <link linkend="SXML">SXML</link>
13559 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SXMLSimplify">SXMLSimplify</link>.</simpara>
13560 <section id="_description_20">
13561 <title>Description</title>
13562 <simpara>This pass implements exceptions.</simpara>
13563 </section>
13564 <section id="_implementation_22">
13565 <title>Implementation</title>
13566 <itemizedlist>
13567 <listitem>
13568 <simpara>
13569 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/implement-exceptions.fun"><literal>implement-exceptions.fun</literal></ulink>
13570 </simpara>
13571 </listitem>
13572 </itemizedlist>
13573 </section>
13574 <section id="_details_and_notes_22">
13575 <title>Details and Notes</title>
13576 <simpara></simpara>
13577 <simpara><?asciidoc-pagebreak?></simpara>
13578 </section>
13579 </section>
13580 <section id="ImplementHandlers">
13581 <title>ImplementHandlers</title>
13582 <simpara><link linkend="ImplementHandlers">ImplementHandlers</link> is a pass for the <link linkend="RSSA">RSSA</link>
13583 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="RSSASimplify">RSSASimplify</link>.</simpara>
13584 <section id="_description_21">
13585 <title>Description</title>
13586 <simpara>This pass implements the (threaded) exception handler stack.</simpara>
13587 </section>
13588 <section id="_implementation_23">
13589 <title>Implementation</title>
13590 <itemizedlist>
13591 <listitem>
13592 <simpara>
13593 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/implement-handlers.fun"><literal>implement-handlers.fun</literal></ulink>
13594 </simpara>
13595 </listitem>
13596 </itemizedlist>
13597 </section>
13598 <section id="_details_and_notes_23">
13599 <title>Details and Notes</title>
13600 <simpara></simpara>
13601 <simpara><?asciidoc-pagebreak?></simpara>
13602 </section>
13603 </section>
13604 <section id="ImplementProfiling">
13605 <title>ImplementProfiling</title>
13606 <simpara><link linkend="ImplementProfiling">ImplementProfiling</link> is a pass for the <link linkend="RSSA">RSSA</link>
13607 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="RSSASimplify">RSSASimplify</link>.</simpara>
13608 <section id="_description_22">
13609 <title>Description</title>
13610 <simpara>This pass implements profiling.</simpara>
13611 </section>
13612 <section id="_implementation_24">
13613 <title>Implementation</title>
13614 <itemizedlist>
13615 <listitem>
13616 <simpara>
13617 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/implement-profiling.fun"><literal>implement-profiling.fun</literal></ulink>
13618 </simpara>
13619 </listitem>
13620 </itemizedlist>
13621 </section>
13622 <section id="_details_and_notes_24">
13623 <title>Details and Notes</title>
13624 <simpara>See <link linkend="HowProfilingWorks">HowProfilingWorks</link>.</simpara>
13625 <simpara><?asciidoc-pagebreak?></simpara>
13626 </section>
13627 </section>
13628 <section id="ImplementSuffix">
13629 <title>ImplementSuffix</title>
13630 <simpara><link linkend="ImplementSuffix">ImplementSuffix</link> is a pass for the <link linkend="SXML">SXML</link>
13631 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SXMLSimplify">SXMLSimplify</link>.</simpara>
13632 <section id="_description_23">
13633 <title>Description</title>
13634 <simpara>This pass implements the <literal>TopLevel_setSuffix</literal> primitive, which
13635 installs a function to exit the program.</simpara>
13636 </section>
13637 <section id="_implementation_25">
13638 <title>Implementation</title>
13639 <itemizedlist>
13640 <listitem>
13641 <simpara>
13642 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/implement-suffix.fun"><literal>implement-suffix.fun</literal></ulink>
13643 </simpara>
13644 </listitem>
13645 </itemizedlist>
13646 </section>
13647 <section id="_details_and_notes_25">
13648 <title>Details and Notes</title>
13649 <simpara><link linkend="ImplementSuffix">ImplementSuffix</link> works by introducing a new <literal>ref</literal> cell to contain
13650 the function of type <literal>unit -&gt; unit</literal> that should be called on program
13651 exit.</simpara>
13652 <itemizedlist>
13653 <listitem>
13654 <simpara>
13655 The following code (appropriately alpha-converted) is appended to the beginning of the <link linkend="SXML">SXML</link> program:
13656 </simpara>
13657 <programlisting language="sml" linenumbering="unnumbered">val z_0 =
13658 fn a_0 =&gt;
13659 let
13660 val x_0 =
13661 "toplevel suffix not installed"
13662 val x_1 =
13663 MLton_bug (x_0)
13664 in
13665 x_1
13666 end
13667 val topLevelSuffixCell =
13668 Ref_ref (z_0)</programlisting>
13669 </listitem>
13670 <listitem>
13671 <simpara>
13672 Any occurrence of
13673 </simpara>
13674 <programlisting language="sml" linenumbering="unnumbered">val x_0 =
13675 TopLevel_setSuffix (f_0)</programlisting>
13676 <simpara>is rewritten to</simpara>
13677 <programlisting language="sml" linenumbering="unnumbered">val x_0 =
13678 Ref_assign (topLevelSuffixCell, f_0)</programlisting>
13679 </listitem>
13680 <listitem>
13681 <simpara>
13682 The following code (appropriately alpha-converted) is appended to the end of the <link linkend="SXML">SXML</link> program:
13683 </simpara>
13684 <programlisting language="sml" linenumbering="unnumbered">val f_0 =
13685 Ref_deref (topLevelSuffixCell)
13686 val z_0 =
13687 ()
13688 val x_0 =
13689 f_0 z_0</programlisting>
13690 </listitem>
13691 </itemizedlist>
13692 <simpara><?asciidoc-pagebreak?></simpara>
13693 </section>
13694 </section>
13695 <section id="InfixingOperators">
13696 <title>InfixingOperators</title>
13697 <simpara>Fixity specifications are not part of signatures in
13698 <link linkend="StandardML">Standard ML</link>. When one wants to use a module that
13699 provides functions designed to be used as infix operators there are
13700 several obvious alternatives:</simpara>
13701 <itemizedlist>
13702 <listitem>
13703 <simpara>
13704 Use only prefix applications. Unfortunately there are situations
13705 where infix applications lead to considerably more readable code.
13706 </simpara>
13707 </listitem>
13708 <listitem>
13709 <simpara>
13710 Make the fixity declarations at the top-level. This may lead to
13711 collisions and may be unsustainable in a large project. Pollution of
13712 the top-level should be avoided.
13713 </simpara>
13714 </listitem>
13715 <listitem>
13716 <simpara>
13717 Make the fixity declarations at each scope where you want to use
13718 infix applications. The duplication becomes inconvenient if the
13719 operators are widely used. Duplication of code should be avoided.
13720 </simpara>
13721 </listitem>
13722 <listitem>
13723 <simpara>
13724 Use non-standard extensions, such as the <link linkend="MLBasis">ML Basis system</link>
13725 to control the scope of fixity declarations. This has the obvious
13726 drawback of reduced portability.
13727 </simpara>
13728 </listitem>
13729 <listitem>
13730 <simpara>
13731 Reuse existing infix operator symbols (<literal>^</literal>, <literal>+</literal>, <literal>-</literal>, &#8230;). This
13732 can be convenient when the standard operators aren&#8217;t needed in the
13733 same scope with the new operators. On the other hand, one is limited
13734 to the standard operator symbols and the code may appear confusing.
13735 </simpara>
13736 </listitem>
13737 </itemizedlist>
13738 <simpara>None of the obvious alternatives is best in every case. The following
13739 describes a slightly less obvious alternative that can sometimes be
13740 useful. The idea is to approximate Haskell&#8217;s special syntax for
13741 treating any identifier enclosed in grave accents (backquotes) as an
13742 infix operator. In Haskell, instead of writing the prefix application
13743 <literal>f x y</literal> one can write the infix application <literal>x &grave;f&grave; y</literal>.</simpara>
13744 <section id="_infixing_operators">
13745 <title>Infixing operators</title>
13746 <simpara>Let&#8217;s first take a look at the definitions of the operators:</simpara>
13747 <programlisting language="sml" linenumbering="unnumbered">infix 3 &lt;\ fun x &lt;\ f = fn y =&gt; f (x, y) (* Left section *)
13748 infix 3 \&gt; fun f \&gt; y = f y (* Left application *)
13749 infixr 3 /&gt; fun f /&gt; y = fn x =&gt; f (x, y) (* Right section *)
13750 infixr 3 &lt;/ fun x &lt;/ f = f x (* Right application *)
13751
13752 infix 2 o (* See motivation below *)
13753 infix 0 :=</programlisting>
13754 <simpara>The left and right sectioning operators, <literal>&lt;\</literal> and <literal>/&gt;</literal>, are useful in
13755 SML for partial application of infix operators.
13756 <link linkend="References_Paulson96">ML For the Working Programmer</link> describes curried
13757 functions <literal>secl</literal> and <literal>secr</literal> for the same purpose on pages 179-181.
13758 For example,</simpara>
13759 <programlisting language="sml" linenumbering="unnumbered">List.map (op- /&gt; y)</programlisting>
13760 <simpara>is a function for subtracting <literal>y</literal> from a list of integers and</simpara>
13761 <programlisting language="sml" linenumbering="unnumbered">List.exists (x &lt;\ op=)</programlisting>
13762 <simpara>is a function for testing whether a list contains an <literal>x</literal>.</simpara>
13763 <simpara>Together with the left and right application operators, <literal>\&gt;</literal> and <literal>&lt;/</literal>,
13764 the sectioning operators provide a way to treat any binary function
13765 (i.e. a function whose domain is a pair) as an infix operator. In
13766 general,</simpara>
13767 <screen>x0 &lt;\f1\&gt; x1 &lt;\f2\&gt; x2 ... &lt;\fN\&gt; xN = fN (... f2 (f1 (x0, x1), x2) ..., xN)</screen>
13768 <simpara>and</simpara>
13769 <screen>xN &lt;/fN/&gt; ... x2 &lt;/f2/&gt; x1 &lt;/f1/&gt; x0 = fN (xN, ... f2 (x2, f1 (x1, x0)) ...)</screen>
13770 <section id="_examples_2">
13771 <title>Examples</title>
13772 <simpara>As a fairly realistic example, consider providing a function for sequencing
13773 comparisons:</simpara>
13774 <programlisting language="sml" linenumbering="unnumbered">structure Order (* ... *) =
13775 struct
13776 (* ... *)
13777 val orWhenEq = fn (EQUAL, th) =&gt; th ()
13778 | (other, _) =&gt; other
13779 (* ... *)
13780 end</programlisting>
13781 <simpara>Using <literal>orWhenEq</literal> and the infixing operators, one can write a
13782 <literal>compare</literal> function for triples as</simpara>
13783 <programlisting language="sml" linenumbering="unnumbered">fun compare (fad, fbe, fcf) ((a, b, c), (d, e, f)) =
13784 fad (a, d) &lt;\Order.orWhenEq\&gt; `fbe (b, e) &lt;\Order.orWhenEq\&gt; `fcf (c, f)</programlisting>
13785 <simpara>where <literal>&grave;</literal> is defined as</simpara>
13786 <programlisting language="sml" linenumbering="unnumbered">fun `f x = fn () =&gt; f x</programlisting>
13787 <simpara>Although <literal>orWhenEq</literal> can be convenient (try rewriting the above without
13788 it), it is probably not useful enough to be defined at the top level
13789 as an infix operator. Fortunately we can use the infixing operators
13790 and don&#8217;t have to.</simpara>
13791 <simpara>Another fairly realistic example would be to use the infixing operators with
13792 the technique described on the <link linkend="Printf">Printf</link> page. Assuming that you would have
13793 a <literal>Printf</literal> module binding <literal>printf</literal>, <literal>&grave;</literal>, and formatting combinators
13794 named <literal>int</literal> and <literal>string</literal>, you could write</simpara>
13795 <programlisting language="sml" linenumbering="unnumbered">let open Printf in
13796 printf (`"Here's an int "&lt;\int\&gt;" and a string "&lt;\string\&gt;".") 13 "foo" end</programlisting>
13797 <simpara>without having to duplicate the fixity declarations. Alternatively, you could
13798 write</simpara>
13799 <programlisting language="sml" linenumbering="unnumbered">P.printf (P.`"Here's an int "&lt;\P.int\&gt;" and a string "&lt;\P.string\&gt;".") 13 "foo"</programlisting>
13800 <simpara>assuming you have the made the binding</simpara>
13801 <programlisting language="sml" linenumbering="unnumbered">structure P = Printf</programlisting>
13802 </section>
13803 </section>
13804 <section id="_application_and_piping_operators">
13805 <title>Application and piping operators</title>
13806 <simpara>The left and right application operators may also provide some notational
13807 convenience on their own. In general,</simpara>
13808 <screen>f \&gt; x1 \&gt; ... \&gt; xN = f x1 ... xN</screen>
13809 <simpara>and</simpara>
13810 <screen>xN &lt;/ ... &lt;/ x1 &lt;/ f = f x1 ... xN</screen>
13811 <simpara>If nothing else, both of them can eliminate parentheses. For example,</simpara>
13812 <programlisting language="sml" linenumbering="unnumbered">foo (1 + 2) = foo \&gt; 1 + 2</programlisting>
13813 <simpara>The left and right application operators are related to operators
13814 that could be described as the right and left piping operators:</simpara>
13815 <programlisting language="sml" linenumbering="unnumbered">infix 1 &gt;| val op&gt;| = op&lt;/ (* Left pipe *)
13816 infixr 1 |&lt; val op|&lt; = op\&gt; (* Right pipe *)</programlisting>
13817 <simpara>As you can see, the left and right piping operators, <literal>&gt;|</literal> and <literal>|&lt;</literal>,
13818 are the same as the right and left application operators,
13819 respectively, except the associativities are reversed and the binding
13820 strength is lower. They are useful for piping data through a sequence
13821 of operations. In general,</simpara>
13822 <screen>x &gt;| f1 &gt;| ... &gt;| fN = fN (... (f1 x) ...) = (fN o ... o f1) x</screen>
13823 <simpara>and</simpara>
13824 <screen>fN |&lt; ... |&lt; f1 |&lt; x = fN (... (f1 x) ...) = (fN o ... o f1) x</screen>
13825 <simpara>The right piping operator, <literal>|&lt;</literal>, is provided by the Haskell prelude as
13826 <literal>$</literal>. It can be convenient in CPS or continuation passing style.</simpara>
13827 <simpara>A use for the left piping operator is with parsing combinators. In a
13828 strict language, like SML, eta-reduction is generally unsafe. Using
13829 the left piping operator, parsing functions can be formatted
13830 conveniently as</simpara>
13831 <programlisting language="sml" linenumbering="unnumbered">fun parsingFunc input =
13832 input &gt;| (* ... *)
13833 || (* ... *)
13834 || (* ... *)</programlisting>
13835 <simpara>where <literal>||</literal> is supposed to be a combinator provided by the parsing combinator
13836 library.</simpara>
13837 </section>
13838 <section id="_about_precedences">
13839 <title>About precedences</title>
13840 <simpara>You probably noticed that we redefined the
13841 <link linkend="OperatorPrecedence">precedences</link> of the function composition operator
13842 <literal>o</literal> and the assignment operator <literal>:=</literal>. Doing so is not strictly
13843 necessary, but can be convenient and should be relatively
13844 safe. Consider the following motivating examples from
13845 <link linkend="WesleyTerpstra">Wesley W. Terpstra</link> relying on the redefined
13846 precedences:</simpara>
13847 <programlisting language="sml" linenumbering="unnumbered">Word8.fromInt o Char.ord o s &lt;\String.sub
13848 (* Combining sectioning and composition *)
13849
13850 x := s &lt;\String.sub\&gt; i
13851 (* Assigning the result of an infixed application *)</programlisting>
13852 <simpara>In imperative languages, assignment usually has the lowest precedence
13853 (ignoring statement separators). The precedence of <literal>:=</literal> in the
13854 <link linkend="BasisLibrary">Basis Library</link> is perhaps unnecessarily high, because
13855 an expression of the form <literal>r := x</literal> always returns a unit, which makes
13856 little sense to combine with anything. Dropping <literal>:=</literal> to the lowest
13857 precedence level makes it behave more like in other imperative
13858 languages.</simpara>
13859 <simpara>The case for <literal>o</literal> is different. With the exception of <literal>before</literal> and
13860 <literal>:=</literal>, it doesn&#8217;t seem to make much sense to use <literal>o</literal> with any of the
13861 operators defined by the <link linkend="BasisLibrary">Basis Library</link> in an
13862 unparenthesized expression. This is simply because none of the other
13863 operators deal with functions. It would seem that the precedence of
13864 <literal>o</literal> could be chosen completely arbitrarily from the set <literal>{1, ..., 9}</literal>
13865 without having any adverse effects with respect to other infix
13866 operators defined by the <link linkend="BasisLibrary">Basis Library</link>.</simpara>
13867 </section>
13868 <section id="_design_of_the_symbols">
13869 <title>Design of the symbols</title>
13870 <simpara>The closest approximation of Haskell&#8217;s <literal>x &grave;f&grave; y</literal> syntax
13871 achievable in Standard ML would probably be something like
13872 <literal>x &grave;f^ y</literal>, but <literal>^</literal> is already used for string
13873 concatenation by the <link linkend="BasisLibrary">Basis Library</link>. Other
13874 combinations of the characters <literal>&grave;</literal> and <literal>^</literal> would be
13875 possible, but none seems clearly the best visually. The symbols <literal>&lt;\</literal>,
13876 <literal>\&gt;</literal>, <literal>&lt;/</literal>, and <literal>/&gt;</literal> are reasonably concise and have a certain
13877 self-documenting appearance and symmetry, which can help to remember
13878 them. As the names suggest, the symbols of the piping operators <literal>&gt;|</literal>
13879 and <literal>|&lt;</literal> are inspired by Unix shell pipelines.</simpara>
13880 </section>
13881 <section id="_also_see_7">
13882 <title>Also see</title>
13883 <itemizedlist>
13884 <listitem>
13885 <simpara>
13886 <link linkend="Utilities">Utilities</link>
13887 </simpara>
13888 </listitem>
13889 </itemizedlist>
13890 <simpara><?asciidoc-pagebreak?></simpara>
13891 </section>
13892 </section>
13893 <section id="Inline">
13894 <title>Inline</title>
13895 <simpara><link linkend="Inline">Inline</link> is an optimization pass for the <link linkend="SSA">SSA</link>
13896 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
13897 <section id="_description_24">
13898 <title>Description</title>
13899 <simpara>This pass inlines <link linkend="SSA">SSA</link> functions using a size-based metric.</simpara>
13900 </section>
13901 <section id="_implementation_26">
13902 <title>Implementation</title>
13903 <itemizedlist>
13904 <listitem>
13905 <simpara>
13906 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/inline.sig"><literal>inline.sig</literal></ulink>
13907 </simpara>
13908 </listitem>
13909 <listitem>
13910 <simpara>
13911 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/inline.fun"><literal>inline.fun</literal></ulink>
13912 </simpara>
13913 </listitem>
13914 </itemizedlist>
13915 </section>
13916 <section id="_details_and_notes_26">
13917 <title>Details and Notes</title>
13918 <simpara>The <link linkend="Inline">Inline</link> pass can be invoked to use one of three metrics:</simpara>
13919 <itemizedlist>
13920 <listitem>
13921 <simpara>
13922 <literal>NonRecursive(product, small)</literal>&#8201;&#8212;&#8201;inline any function satisfying <literal>(numCalls - 1) * (size - small) &lt;= product</literal>, where <literal>numCalls</literal> is the static number of calls to the function and <literal>size</literal> is the size of the function.
13923 </simpara>
13924 </listitem>
13925 <listitem>
13926 <simpara>
13927 <literal>Leaf(size)</literal>&#8201;&#8212;&#8201;inline any leaf function smaller than <literal>size</literal>
13928 </simpara>
13929 </listitem>
13930 <listitem>
13931 <simpara>
13932 <literal>LeafNoLoop(size)</literal>&#8201;&#8212;&#8201;inline any leaf function without loops smaller than <literal>size</literal>
13933 </simpara>
13934 </listitem>
13935 </itemizedlist>
13936 <simpara><?asciidoc-pagebreak?></simpara>
13937 </section>
13938 </section>
13939 <section id="InsertLimitChecks">
13940 <title>InsertLimitChecks</title>
13941 <simpara><link linkend="InsertLimitChecks">InsertLimitChecks</link> is a pass for the <link linkend="RSSA">RSSA</link>
13942 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="RSSASimplify">RSSASimplify</link>.</simpara>
13943 <section id="_description_25">
13944 <title>Description</title>
13945 <simpara>This pass inserts limit checks.</simpara>
13946 </section>
13947 <section id="_implementation_27">
13948 <title>Implementation</title>
13949 <itemizedlist>
13950 <listitem>
13951 <simpara>
13952 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/limit-check.fun"><literal>limit-check.fun</literal></ulink>
13953 </simpara>
13954 </listitem>
13955 </itemizedlist>
13956 </section>
13957 <section id="_details_and_notes_27">
13958 <title>Details and Notes</title>
13959 <simpara></simpara>
13960 <simpara><?asciidoc-pagebreak?></simpara>
13961 </section>
13962 </section>
13963 <section id="InsertSignalChecks">
13964 <title>InsertSignalChecks</title>
13965 <simpara><link linkend="InsertSignalChecks">InsertSignalChecks</link> is a pass for the <link linkend="RSSA">RSSA</link>
13966 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="RSSASimplify">RSSASimplify</link>.</simpara>
13967 <section id="_description_26">
13968 <title>Description</title>
13969 <simpara>This pass inserts signal checks.</simpara>
13970 </section>
13971 <section id="_implementation_28">
13972 <title>Implementation</title>
13973 <itemizedlist>
13974 <listitem>
13975 <simpara>
13976 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/limit-check.fun"><literal>limit-check.fun</literal></ulink>
13977 </simpara>
13978 </listitem>
13979 </itemizedlist>
13980 </section>
13981 <section id="_details_and_notes_28">
13982 <title>Details and Notes</title>
13983 <simpara></simpara>
13984 <simpara><?asciidoc-pagebreak?></simpara>
13985 </section>
13986 </section>
13987 <section id="Installation">
13988 <title>Installation</title>
13989 <simpara>MLton runs on a variety of platforms and is distributed in both source and
13990 binary form.</simpara>
13991 <simpara>A <literal>.tgz</literal> or <literal>.tbz</literal> binary package can be extracted at any location, yielding
13992 <literal>README.adoc</literal> (this file), <literal>CHANGELOG.adoc</literal>, <literal>LICENSE</literal>, <literal>Makefile</literal>, <literal>bin/</literal>,
13993 <literal>lib/</literal>, and <literal>share/</literal>. The compiler and tools can be executed in-place (e.g.,
13994 <literal>./bin/mlton</literal>).</simpara>
13995 <simpara>A small set of <literal>Makefile</literal> variables can be used to customize the binary package
13996 via <literal>make update</literal>:</simpara>
13997 <itemizedlist>
13998 <listitem>
13999 <simpara>
14000 <literal>CC</literal>: Specify C compiler. Can be used for alternative tools (e.g.,
14001 <literal>CC=clang</literal> or <literal>CC=gcc-7</literal>).
14002 </simpara>
14003 </listitem>
14004 <listitem>
14005 <simpara>
14006 <literal>WITH_GMP_DIR</literal>, <literal>WITH_GMP_INC_DIR</literal>, <literal>WITH_GMP_LIB_DIR</literal>: Specify GMP include
14007 and library paths, if not on default search paths. (If <literal>WITH_GMP_DIR</literal> is
14008 set, then <literal>WITH_GMP_INC_DIR</literal> defaults to <literal>$(WITH_GMP_DIR)/include</literal> and
14009 <literal>WITH_GMP_LIB_DIR</literal> defaults to <literal>$(WITH_GMP_DIR)/lib</literal>.)
14010 </simpara>
14011 </listitem>
14012 </itemizedlist>
14013 <simpara>For example:</simpara>
14014 <programlisting language="sml" linenumbering="unnumbered">$ make CC=clang WITH_GMP_DIR=/opt/gmp update</programlisting>
14015 <simpara>On typical platforms, installing MLton (after optionally performing
14016 <literal>make update</literal>) to <literal>/usr/local</literal> can be accomplished via:</simpara>
14017 <programlisting language="sml" linenumbering="unnumbered">$ make install</programlisting>
14018 <simpara>A small set of <literal>Makefile</literal> variables can be used to customize the installation:</simpara>
14019 <itemizedlist>
14020 <listitem>
14021 <simpara>
14022 <literal>PREFIX</literal>: Specify the installation prefix.
14023 </simpara>
14024 </listitem>
14025 <listitem>
14026 <simpara>
14027 <literal>CC</literal>: Specify C compiler. Can be used for alternative tools (e.g.,
14028 <literal>CC=clang</literal> or <literal>CC=gcc-7</literal>).
14029 </simpara>
14030 </listitem>
14031 <listitem>
14032 <simpara>
14033 <literal>WITH_GMP_DIR</literal>, <literal>WITH_GMP_INC_DIR</literal>, <literal>WITH_GMP_LIB_DIR</literal>: Specify GMP include
14034 and library paths, if not on default search paths. (If <literal>WITH_GMP_DIR</literal> is
14035 set, then <literal>WITH_GMP_INC_DIR</literal> defaults to <literal>$(WITH_GMP_DIR)/include</literal> and
14036 <literal>WITH_GMP_LIB_DIR</literal> defaults to <literal>$(WITH_GMP_DIR)/lib</literal>.)
14037 </simpara>
14038 </listitem>
14039 </itemizedlist>
14040 <simpara>For example:</simpara>
14041 <programlisting language="sml" linenumbering="unnumbered">$ make PREFIX=/opt/mlton install</programlisting>
14042 <simpara>Installation of MLton creates the following files and directories.</simpara>
14043 <itemizedlist>
14044 <listitem>
14045 <simpara>
14046 <literal><emphasis>prefix</emphasis>/bin/mllex</literal>
14047 </simpara>
14048 <simpara>The <link linkend="MLLex">MLLex</link> lexer generator.</simpara>
14049 </listitem>
14050 <listitem>
14051 <simpara>
14052 <literal><emphasis>prefix</emphasis>/bin/mlnlffigen</literal>
14053 </simpara>
14054 <simpara>The <link linkend="MLNLFFI">ML-NLFFI</link> tool.</simpara>
14055 </listitem>
14056 <listitem>
14057 <simpara>
14058 <literal><emphasis>prefix</emphasis>/bin/mlprof</literal>
14059 </simpara>
14060 <simpara>A <link linkend="Profiling">Profiling</link> tool.</simpara>
14061 </listitem>
14062 <listitem>
14063 <simpara>
14064 <literal><emphasis>prefix</emphasis>/bin/mlton</literal>
14065 </simpara>
14066 <simpara>A script to call the compiler. This script may be moved anywhere,
14067 however, it makes use of files in <literal><emphasis>prefix</emphasis>/lib/mlton</literal>.</simpara>
14068 </listitem>
14069 <listitem>
14070 <simpara>
14071 <literal><emphasis>prefix</emphasis>/bin/mlyacc</literal>
14072 </simpara>
14073 <simpara>The <link linkend="MLYacc">MLYacc</link> parser generator.</simpara>
14074 </listitem>
14075 <listitem>
14076 <simpara>
14077 <literal><emphasis>prefix</emphasis>/lib/mlton</literal>
14078 </simpara>
14079 <simpara>Directory containing libraries and include files needed during compilation.</simpara>
14080 </listitem>
14081 <listitem>
14082 <simpara>
14083 <literal><emphasis>prefix</emphasis>/share/man/man1/{mllex,mlnlffigen,mlprof,mlton,mlyacc}.1</literal>
14084 </simpara>
14085 <simpara>Man pages.</simpara>
14086 </listitem>
14087 <listitem>
14088 <simpara>
14089 <literal><emphasis>prefix</emphasis>/share/doc/mlton</literal>
14090 </simpara>
14091 <simpara>Directory containing the user guide for MLton, mllex, and mlyacc, as
14092 well as example SML programs (in the <literal>examples</literal> directory), and license
14093 information.</simpara>
14094 </listitem>
14095 </itemizedlist>
14096 <section id="_hello_world">
14097 <title>Hello, World!</title>
14098 <simpara>Once you have installed MLton, create a file called <literal>hello-world.sml</literal>
14099 with the following contents.</simpara>
14100 <screen>print "Hello, world!\n";</screen>
14101 <simpara>Now create an executable, <literal>hello-world</literal>, with the following command.</simpara>
14102 <screen>mlton hello-world.sml</screen>
14103 <simpara>You can now run <literal>hello-world</literal> to verify that it works. There are more
14104 small examples in <literal><emphasis>prefix</emphasis>/share/doc/mlton/examples</literal>.</simpara>
14105 </section>
14106 <section id="_installation_on_cygwin">
14107 <title>Installation on Cygwin</title>
14108 <simpara>When installing the Cygwin <literal>tgz</literal>, you should use Cygwin&#8217;s <literal>bash</literal> and
14109 <literal>tar</literal>. The use of an archiving tool that is not aware of Cygwin&#8217;s
14110 mounts will put the files in the wrong place.</simpara>
14111 <simpara><?asciidoc-pagebreak?></simpara>
14112 </section>
14113 </section>
14114 <section id="IntermediateLanguage">
14115 <title>IntermediateLanguage</title>
14116 <simpara>MLton uses a number of intermediate languages in translating from the input source program to low-level code. Here is a list in the order which they are translated to.</simpara>
14117 <itemizedlist>
14118 <listitem>
14119 <simpara>
14120 <link linkend="AST">AST</link>. Pretty close to the source.
14121 </simpara>
14122 </listitem>
14123 <listitem>
14124 <simpara>
14125 <link linkend="CoreML">CoreML</link>. Explicitly typed, no module constructs.
14126 </simpara>
14127 </listitem>
14128 <listitem>
14129 <simpara>
14130 <link linkend="XML">XML</link>. Polymorphic, <link linkend="HigherOrder">HigherOrder</link>.
14131 </simpara>
14132 </listitem>
14133 <listitem>
14134 <simpara>
14135 <link linkend="SXML">SXML</link>. SimplyTyped, <link linkend="HigherOrder">HigherOrder</link>.
14136 </simpara>
14137 </listitem>
14138 <listitem>
14139 <simpara>
14140 <link linkend="SSA">SSA</link>. SimplyTyped, <link linkend="FirstOrder">FirstOrder</link>.
14141 </simpara>
14142 </listitem>
14143 <listitem>
14144 <simpara>
14145 <link linkend="SSA2">SSA2</link>. SimplyTyped, <link linkend="FirstOrder">FirstOrder</link>.
14146 </simpara>
14147 </listitem>
14148 <listitem>
14149 <simpara>
14150 <link linkend="RSSA">RSSA</link>. Explicit data representations.
14151 </simpara>
14152 </listitem>
14153 <listitem>
14154 <simpara>
14155 <link linkend="Machine">Machine</link>. Untyped register transfer language.
14156 </simpara>
14157 </listitem>
14158 </itemizedlist>
14159 <simpara><?asciidoc-pagebreak?></simpara>
14160 </section>
14161 <section id="IntroduceLoops">
14162 <title>IntroduceLoops</title>
14163 <simpara><link linkend="IntroduceLoops">IntroduceLoops</link> is an optimization pass for the <link linkend="SSA">SSA</link>
14164 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
14165 <section id="_description_27">
14166 <title>Description</title>
14167 <simpara>This pass rewrites any <link linkend="SSA">SSA</link> function that calls itself in tail
14168 position into one with a local loop and no self tail calls.</simpara>
14169 <simpara>A <link linkend="SSA">SSA</link> function like</simpara>
14170 <screen>fun F (arg_0, arg_1) = L_0 ()
14171 ...
14172 L_16 (x_0)
14173 ...
14174 F (z_0, z_1) Tail
14175 ...</screen>
14176 <simpara>becomes</simpara>
14177 <screen>fun F (arg_0', arg_1') = loopS_0 ()
14178 loopS_0 ()
14179 loop_0 (arg_0', arg_1')
14180 loop_0 (arg_0, arg_1)
14181 L_0 ()
14182 ...
14183 L_16 (x_0)
14184 ...
14185 loop_0 (z_0, z_1)
14186 ...</screen>
14187 </section>
14188 <section id="_implementation_29">
14189 <title>Implementation</title>
14190 <itemizedlist>
14191 <listitem>
14192 <simpara>
14193 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/introduce-loops.fun"><literal>introduce-loops.fun</literal></ulink>
14194 </simpara>
14195 </listitem>
14196 </itemizedlist>
14197 </section>
14198 <section id="_details_and_notes_29">
14199 <title>Details and Notes</title>
14200 <simpara></simpara>
14201 <simpara><?asciidoc-pagebreak?></simpara>
14202 </section>
14203 </section>
14204 <section id="JesperLouisAndersen">
14205 <title>JesperLouisAndersen</title>
14206 <simpara>Jesper Louis Andersen is an undergraduate student at DIKU, the department of computer science, Copenhagen university. His contributions to MLton are few, though he has made the port of MLton to the NetBSD and OpenBSD platforms.</simpara>
14207 <simpara>His general interests in computer science are compiler theory, language theory, algorithms and datastructures and programming. His assets are his general knowledge of UNIX systems, knowledge of system administration, knowledge of operating system kernels; NetBSD in particular.</simpara>
14208 <simpara>He was employed by the university as a system administrator for 2 years, which has set him back somewhat in his studies. Currently he is trying to learn mathematics (real analysis, general topology, complex functional analysis and algebra).</simpara>
14209 <section id="_projects_using_mlton">
14210 <title>Projects using MLton</title>
14211 <section id="_a_register_allocator">
14212 <title>A register allocator</title>
14213 <simpara>For internal use at a compiler course at DIKU. It is written in the literate programming style and implements the <emphasis>Iterated Register Coalescing</emphasis> algorithm by Lal George and Andrew Appel <ulink url="http://citeseer.ist.psu.edu/george96iterated.html">http://citeseer.ist.psu.edu/george96iterated.html</ulink>. The status of the project is that it is unfinished. Most of the basic parts of the algorithm is done, but the interface to the students (simple) datatype takes some conversion.</simpara>
14214 </section>
14215 <section id="_a_configuration_management_system_in_sml">
14216 <title>A configuration management system in SML</title>
14217 <simpara>At this time, only loose plans exists for this. The plan is to build a Configuration Management system on the principles of the OpenCM system, see <ulink url="http://www.opencm.org/docs.html">http://www.opencm.org/docs.html</ulink>. The basic idea is to unify "naming" and "identity" into one by uniquely identifying all objects managed in the repository by the use of cryptographic checksums. This mantra guides the rest of the system, providing integrity, accessibility and confidentiality.</simpara>
14218 <simpara><?asciidoc-pagebreak?></simpara>
14219 </section>
14220 </section>
14221 </section>
14222 <section id="JohnnyAndersen">
14223 <title>JohnnyAndersen</title>
14224 <simpara>Johnny Andersen (aka Anoq of the Sun)</simpara>
14225 <simpara>Here is a picture in front of the academy building
14226 at the University of Athens, Greece, taken in September 2003.</simpara>
14227 <informalfigure>
14228 <mediaobject>
14229 <imageobject>
14230 <imagedata fileref="JohnnyAndersen.attachments/anoq.jpg" align="center"/>
14231 </imageobject>
14232 <textobject><phrase>JohnnyAndersen.attachments/anoq.jpg</phrase></textobject>
14233 </mediaobject>
14234 </informalfigure>
14235 <simpara><?asciidoc-pagebreak?></simpara>
14236 </section>
14237 <section id="KnownCase">
14238 <title>KnownCase</title>
14239 <simpara><link linkend="KnownCase">KnownCase</link> is an optimization pass for the <link linkend="SSA">SSA</link>
14240 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
14241 <section id="_description_28">
14242 <title>Description</title>
14243 <simpara>This pass duplicates and simplifies <literal>Case</literal> transfers when the
14244 constructor of the scrutinee is known.</simpara>
14245 <simpara>Uses <link linkend="Restore">Restore</link>.</simpara>
14246 <simpara>For example, the program</simpara>
14247 <programlisting language="sml" linenumbering="unnumbered">val rec last =
14248 fn [] =&gt; 0
14249 | [x] =&gt; x
14250 | _ :: l =&gt; last l
14251
14252 val _ = 1 + last [2, 3, 4, 5, 6, 7]</programlisting>
14253 <simpara>gives rise to the <link linkend="SSA">SSA</link> function</simpara>
14254 <screen>fun last_0 (x_142) = loopS_1 ()
14255 loopS_1 ()
14256 loop_11 (x_142)
14257 loop_11 (x_143)
14258 case x_143 of
14259 nil_1 =&gt; L_73 | ::_0 =&gt; L_74
14260 L_73 ()
14261 return global_5
14262 L_74 (x_145, x_144)
14263 case x_145 of
14264 nil_1 =&gt; L_75 | _ =&gt; L_76
14265 L_75 ()
14266 return x_144
14267 L_76 ()
14268 loop_11 (x_145)</screen>
14269 <simpara>which is simplified to</simpara>
14270 <screen>fun last_0 (x_142) = loopS_1 ()
14271 loopS_1 ()
14272 case x_142 of
14273 nil_1 =&gt; L_73 | ::_0 =&gt; L_118
14274 L_73 ()
14275 return global_5
14276 L_118 (x_230, x_229)
14277 L_74 (x_230, x_229, x_142)
14278 L_74 (x_145, x_144, x_232)
14279 case x_145 of
14280 nil_1 =&gt; L_75 | ::_0 =&gt; L_114
14281 L_75 ()
14282 return x_144
14283 L_114 (x_227, x_226)
14284 L_74 (x_227, x_226, x_145)</screen>
14285 </section>
14286 <section id="_implementation_30">
14287 <title>Implementation</title>
14288 <itemizedlist>
14289 <listitem>
14290 <simpara>
14291 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/known-case.fun"><literal>known-case.fun</literal></ulink>
14292 </simpara>
14293 </listitem>
14294 </itemizedlist>
14295 </section>
14296 <section id="_details_and_notes_30">
14297 <title>Details and Notes</title>
14298 <simpara>One interesting aspect of <link linkend="KnownCase">KnownCase</link>, is that it often has the
14299 effect of unrolling list traversals by one iteration, moving the
14300 <literal>nil</literal>/<literal>::</literal> check to the end of the loop, rather than the beginning.</simpara>
14301 <simpara><?asciidoc-pagebreak?></simpara>
14302 </section>
14303 </section>
14304 <section id="LambdaCalculus">
14305 <title>LambdaCalculus</title>
14306 <simpara>The <ulink url="http://en.wikipedia.org/wiki/Lambda_calculus">lambda calculus</ulink> is
14307 the formal system underlying <link linkend="StandardML">Standard ML</link>.</simpara>
14308 <simpara><?asciidoc-pagebreak?></simpara>
14309 </section>
14310 <section id="LambdaFree">
14311 <title>LambdaFree</title>
14312 <simpara><link linkend="LambdaFree">LambdaFree</link> is an analysis pass for the <link linkend="SXML">SXML</link>
14313 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="ClosureConvert">ClosureConvert</link>.</simpara>
14314 <section id="_description_29">
14315 <title>Description</title>
14316 <simpara>This pass descends the entire <link linkend="SXML">SXML</link> program and attaches a property
14317 to each <literal>Lambda</literal> <literal>PrimExp.t</literal> in the program. Then, you can use
14318 <literal>lambdaFree</literal> and <literal>lambdaRec</literal> to get free variables of that <literal>Lambda</literal>.</simpara>
14319 </section>
14320 <section id="_implementation_31">
14321 <title>Implementation</title>
14322 <itemizedlist>
14323 <listitem>
14324 <simpara>
14325 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.sig"><literal>lambda-free.sig</literal></ulink>
14326 </simpara>
14327 </listitem>
14328 <listitem>
14329 <simpara>
14330 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/closure-convert/lambda-free.fun"><literal>lambda-free.fun</literal></ulink>
14331 </simpara>
14332 </listitem>
14333 </itemizedlist>
14334 </section>
14335 <section id="_details_and_notes_31">
14336 <title>Details and Notes</title>
14337 <simpara>For <literal>Lambda</literal>-s bound in a <literal>Fun</literal> dec, <literal>lambdaFree</literal> gives the union of
14338 the frees of the entire group of mutually recursive functions. Hence,
14339 <literal>lambdaFree</literal> for every <literal>Lambda</literal> in a single <literal>Fun</literal> dec is the same.
14340 Furthermore, for a <literal>Lambda</literal> bound in a <literal>Fun</literal> dec, <literal>lambdaRec</literal> gives
14341 the list of other functions bound in the same dec defining that
14342 <literal>Lambda</literal>.</simpara>
14343 <simpara>For example:</simpara>
14344 <screen>val rec f = fn x =&gt; ... y ... g ... f ...
14345 and g = fn z =&gt; ... f ... w ...</screen>
14346 <screen>lambdaFree(fn x =&gt;) = [y, w]
14347 lambdaFree(fn z =&gt;) = [y, w]
14348 lambdaRec(fn x =&gt;) = [g, f]
14349 lambdaRec(fn z =&gt;) = [f]</screen>
14350 <simpara><?asciidoc-pagebreak?></simpara>
14351 </section>
14352 </section>
14353 <section id="LanguageChanges">
14354 <title>LanguageChanges</title>
14355 <simpara>We are sometimes asked to modify MLton to change the language it
14356 compiles. In short, we are conservative about making such changes.
14357 There are a number of reasons for this.</simpara>
14358 <itemizedlist>
14359 <listitem>
14360 <simpara>
14361 <link linkend="DefinitionOfStandardML">The Definition of Standard ML</link> is an
14362 extremely high standard of specification. The value of the Definition
14363 would be significantly diluted by changes that are not specified at an
14364 equally high level, and the dilution increases with the complexity of
14365 the language change and its interaction with other language features.
14366 </simpara>
14367 </listitem>
14368 <listitem>
14369 <simpara>
14370 The SML community is small and there are a number of
14371 <link linkend="StandardMLImplementations">SML implementations</link>. Without an
14372 agreed-upon standard, it becomes very difficult to port programs
14373 between compilers, and the community would be balkanized.
14374 </simpara>
14375 </listitem>
14376 <listitem>
14377 <simpara>
14378 Our main goal is to enable programmers to be as effective as
14379 possible with MLton/SML. There are a number of improvements other
14380 than language changes that we could spend our time on that would
14381 provide more benefit to programmers.
14382 </simpara>
14383 </listitem>
14384 <listitem>
14385 <simpara>
14386 The more the language that MLton compiles changes over time, the
14387 more difficult it is to use MLton as a stable platform for serious
14388 program development.
14389 </simpara>
14390 </listitem>
14391 </itemizedlist>
14392 <simpara>Despite these drawbacks, we have extended SML in a couple of cases.</simpara>
14393 <itemizedlist>
14394 <listitem>
14395 <simpara>
14396 <link linkend="ForeignFunctionInterface">Foreign function interface</link>
14397 </simpara>
14398 </listitem>
14399 <listitem>
14400 <simpara>
14401 <link linkend="MLBasis">ML Basis system</link>
14402 </simpara>
14403 </listitem>
14404 <listitem>
14405 <simpara>
14406 <link linkend="SuccessorML">Successor ML features</link>
14407 </simpara>
14408 </listitem>
14409 </itemizedlist>
14410 <simpara>We allow these language extensions because they provide functionality
14411 that is impossible to achieve without them or have non-trivial
14412 community support. The Definition does not define a foreign function
14413 interface. So, we must either extend the language or greatly restrict
14414 the class of programs that can be written. Similarly, the Definition
14415 does not provide a mechanism for namespace control at the module
14416 level, making it impossible to deliver packaged libraries and have a
14417 hope of users using them without name clashes. The ML Basis system
14418 addresses this problem. We have also provided a formal specification
14419 of the ML Basis system at the level of the Definition.</simpara>
14420 <section id="_also_see_8">
14421 <title>Also see</title>
14422 <itemizedlist>
14423 <listitem>
14424 <simpara>
14425 <ulink url="http://www.mlton.org/pipermail/mlton/2004-August/016165.html">http://www.mlton.org/pipermail/mlton/2004-August/016165.html</ulink>
14426 </simpara>
14427 </listitem>
14428 <listitem>
14429 <simpara>
14430 <ulink url="http://www.mlton.org/pipermail/mlton-user/2004-December/000320.html">http://www.mlton.org/pipermail/mlton-user/2004-December/000320.html</ulink>
14431 </simpara>
14432 </listitem>
14433 </itemizedlist>
14434 <simpara><?asciidoc-pagebreak?></simpara>
14435 </section>
14436 </section>
14437 <section id="Lazy">
14438 <title>Lazy</title>
14439 <simpara>In a lazy (or non-strict) language, the arguments to a function are
14440 not evaluated before calling the function. Instead, the arguments are
14441 suspended and only evaluated by the function if needed.</simpara>
14442 <simpara><link linkend="StandardML">Standard ML</link> is an eager (or strict) language, not a lazy
14443 language. However, it is easy to delay evaluation of an expression in
14444 SML by creating a <emphasis>thunk</emphasis>, which is a nullary function. In SML, a
14445 thunk is written <literal>fn () =&gt; e</literal>. Another essential feature of laziness
14446 is <emphasis>memoization</emphasis>, meaning that once a suspended argument is evaluated,
14447 subsequent references look up the value. We can express this in SML
14448 with a function that maps a thunk to a memoized thunk.</simpara>
14449 <programlisting language="sml" linenumbering="unnumbered">signature LAZY =
14450 sig
14451 val lazy: (unit -&gt; 'a) -&gt; unit -&gt; 'a
14452 end</programlisting>
14453 <simpara>This is easy to implement in SML.</simpara>
14454 <programlisting language="sml" linenumbering="unnumbered">structure Lazy: LAZY =
14455 struct
14456 fun lazy (th: unit -&gt; 'a): unit -&gt; 'a =
14457 let
14458 datatype 'a lazy_result = Unevaluated of (unit -&gt; 'a)
14459 | Evaluated of 'a
14460 | Failed of exn
14461
14462 val r = ref (Unevaluated th)
14463 in
14464 fn () =&gt;
14465 case !r of
14466 Unevaluated th =&gt; let
14467 val a = th ()
14468 handle x =&gt; (r := Failed x; raise x)
14469 val () = r := Evaluated a
14470 in
14471 a
14472 end
14473 | Evaluated a =&gt; a
14474 | Failed x =&gt; raise x
14475 end
14476 end</programlisting>
14477 <simpara><?asciidoc-pagebreak?></simpara>
14478 </section>
14479 <section id="Libraries">
14480 <title>Libraries</title>
14481 <simpara>In theory every strictly conforming Standard ML program should run on
14482 MLton. However, often large SML projects use implementation specific
14483 features so some "porting" is required. Here is a partial list of
14484 software that is known to run on MLton.</simpara>
14485 <itemizedlist>
14486 <listitem>
14487 <simpara>
14488 Utility libraries:
14489 </simpara>
14490 <itemizedlist>
14491 <listitem>
14492 <simpara>
14493 <link linkend="SMLNJLibrary">SMLNJLibrary</link> - distributed with MLton
14494 </simpara>
14495 </listitem>
14496 <listitem>
14497 <simpara>
14498 <link linkend="MLtonLibraryProject">MLtonLibraryProject</link> - various libraries located on the MLton subversion repository
14499 </simpara>
14500 </listitem>
14501 <listitem>
14502 <simpara>
14503 <ulink url="https://github.com/MLton/mlton/tree/master/lib/mlton"><literal>mlton</literal></ulink> - the internal MLton utility library, which we hope to cleanup and make more accessible someday
14504 </simpara>
14505 </listitem>
14506 <listitem>
14507 <simpara>
14508 <ulink url="http://github.com/seanmcl/sml-ext">sml-ext</ulink>, a grab bag of libraries for MLton and other SML implementations (by Sean McLaughlin)
14509 </simpara>
14510 </listitem>
14511 <listitem>
14512 <simpara>
14513 <ulink url="http://tom7misc.cvs.sourceforge.net/tom7misc/sml-lib/">sml-lib</ulink>, a grab bag of libraries for MLton and other SML implementations (by <link linkend="TomMurphy">TomMurphy</link>)
14514 </simpara>
14515 </listitem>
14516 </itemizedlist>
14517 </listitem>
14518 <listitem>
14519 <simpara>
14520 Scanner generators:
14521 </simpara>
14522 <itemizedlist>
14523 <listitem>
14524 <simpara>
14525 <link linkend="MLLPTLibrary">MLLPTLibrary</link> - distributed with MLton
14526 </simpara>
14527 </listitem>
14528 <listitem>
14529 <simpara>
14530 <link linkend="MLLex">MLLex</link> - distributed with MLton
14531 </simpara>
14532 </listitem>
14533 <listitem>
14534 <simpara>
14535 <link linkend="MLULex">MLULex</link> -
14536 </simpara>
14537 </listitem>
14538 </itemizedlist>
14539 </listitem>
14540 <listitem>
14541 <simpara>
14542 Parser generators:
14543 </simpara>
14544 <itemizedlist>
14545 <listitem>
14546 <simpara>
14547 <link linkend="MLAntlr">MLAntlr</link> -
14548 </simpara>
14549 </listitem>
14550 <listitem>
14551 <simpara>
14552 <link linkend="MLLPTLibrary">MLLPTLibrary</link> - distributed with MLton
14553 </simpara>
14554 </listitem>
14555 <listitem>
14556 <simpara>
14557 <link linkend="MLYacc">MLYacc</link> - distributed with MLton
14558 </simpara>
14559 </listitem>
14560 </itemizedlist>
14561 </listitem>
14562 <listitem>
14563 <simpara>
14564 Concurrency: <link linkend="ConcurrentML">ConcurrentML</link> - distributed with MLton
14565 </simpara>
14566 </listitem>
14567 <listitem>
14568 <simpara>
14569 Graphics
14570 </simpara>
14571 <itemizedlist>
14572 <listitem>
14573 <simpara>
14574 <link linkend="SML3d">SML3d</link>
14575 </simpara>
14576 </listitem>
14577 <listitem>
14578 <simpara>
14579 <link linkend="mGTK">mGTK</link>
14580 </simpara>
14581 </listitem>
14582 </itemizedlist>
14583 </listitem>
14584 <listitem>
14585 <simpara>
14586 Misc. libraries:
14587 </simpara>
14588 <itemizedlist>
14589 <listitem>
14590 <simpara>
14591 <link linkend="CKitLibrary">CKitLibrary</link> - distributed with MLton
14592 </simpara>
14593 </listitem>
14594 <listitem>
14595 <simpara>
14596 <link linkend="MLRISCLibrary">MLRISCLibrary</link> - distributed with MLton
14597 </simpara>
14598 </listitem>
14599 <listitem>
14600 <simpara>
14601 <link linkend="MLNLFFI">ML-NLFFI</link> - distributed with MLton
14602 </simpara>
14603 </listitem>
14604 <listitem>
14605 <simpara>
14606 <link linkend="Swerve">Swerve</link>, an HTTP server
14607 </simpara>
14608 </listitem>
14609 <listitem>
14610 <simpara>
14611 <link linkend="fxp">fxp</link>, an XML parser
14612 </simpara>
14613 </listitem>
14614 </itemizedlist>
14615 </listitem>
14616 </itemizedlist>
14617 <section id="_ports_in_progress">
14618 <title>Ports in progress</title>
14619 <simpara><link linkend="Contact">Contact</link> us for details on any of these.</simpara>
14620 <itemizedlist>
14621 <listitem>
14622 <simpara>
14623 <link linkend="MLDoc">MLDoc</link> <ulink url="http://people.cs.uchicago.edu/%7Ejhr/tools/ml-doc.html">http://people.cs.uchicago.edu/%7Ejhr/tools/ml-doc.html</ulink>
14624 </simpara>
14625 </listitem>
14626 <listitem>
14627 <simpara>
14628 <link linkend="Unicode">Unicode</link>
14629 </simpara>
14630 </listitem>
14631 </itemizedlist>
14632 </section>
14633 <section id="_more">
14634 <title>More</title>
14635 <simpara>More projects using MLton can be seen on the <link linkend="Users">Users</link> page.</simpara>
14636 </section>
14637 <section id="_software_for_sml_implementations_other_than_mlton">
14638 <title>Software for SML implementations other than MLton</title>
14639 <itemizedlist>
14640 <listitem>
14641 <simpara>
14642 PostgreSQL
14643 </simpara>
14644 <itemizedlist>
14645 <listitem>
14646 <simpara>
14647 Moscow ML: <ulink url="http://www.dina.kvl.dk/%7Esestoft/mosmllib/Postgres.html">http://www.dina.kvl.dk/%7Esestoft/mosmllib/Postgres.html</ulink>
14648 </simpara>
14649 </listitem>
14650 <listitem>
14651 <simpara>
14652 SML/NJ NLFFI: <ulink url="http://smlweb.sourceforge.net/smlsql/">http://smlweb.sourceforge.net/smlsql/</ulink>
14653 </simpara>
14654 </listitem>
14655 </itemizedlist>
14656 </listitem>
14657 <listitem>
14658 <simpara>
14659 Web:
14660 </simpara>
14661 <itemizedlist>
14662 <listitem>
14663 <simpara>
14664 ML Kit: <ulink url="http://www.smlserver.org">SMLserver</ulink> (a plugin for AOLserver)
14665 </simpara>
14666 </listitem>
14667 <listitem>
14668 <simpara>
14669 Moscow ML: <ulink url="http://ellemose.dina.kvl.dk/%7Esestoft/msp/index.msp">ML Server Pages</ulink> (support for PHP-style CGI scripting)
14670 </simpara>
14671 </listitem>
14672 <listitem>
14673 <simpara>
14674 SML/NJ: <ulink url="http://smlweb.sourceforge.net/">smlweb</ulink>
14675 </simpara>
14676 </listitem>
14677 </itemizedlist>
14678 </listitem>
14679 </itemizedlist>
14680 <simpara><?asciidoc-pagebreak?></simpara>
14681 </section>
14682 </section>
14683 <section id="LibrarySupport">
14684 <title>LibrarySupport</title>
14685 <simpara>MLton supports both linking to and creating system-level libraries.
14686 While Standard ML libraries should be designed with the <link linkend="MLBasis">MLBasis</link> system to work with other Standard ML programs,
14687 system-level library support allows MLton to create libraries for use by other programming languages.
14688 Even more importantly, system-level library support allows MLton to access libraries from other languages.
14689 This article will explain how to use libraries portably with MLton.</simpara>
14690 <section id="_the_basics">
14691 <title>The Basics</title>
14692 <simpara>A Dynamic Shared Object (DSO) is a piece of executable code written in a format understood by the operating system.
14693 Executable programs and dynamic libraries are the two most common examples of a DSO.
14694 They are called shared because if they are used more than once, they are only loaded once into main memory.
14695 For example, if you start two instances of your web browser (an executable), there may be two processes running, but the program code of the executable is only loaded once.
14696 A dynamic library, for example a graphical toolkit, might be used by several different executable programs, each possibly running multiple times.
14697 Nevertheless, the dynamic library is only loaded once and it&#8217;s program code is shared between all of the processes.</simpara>
14698 <simpara>In addition to program code, DSOs contain a table of textual strings called symbols.
14699 These are used in order to make the DSO do something useful, like execute.
14700 For example, on linux the symbol <literal>_start</literal> refers to the point in the program code where the operating system should start executing the program.
14701 Dynamic libraries generally provide many symbols, corresponding to functions which can be called and variables which can be read or written.
14702 Symbols can be used by the DSO itself, or by other DSOs which require services.</simpara>
14703 <simpara>When a DSO creates a symbol, this is called <emphasis>exporting</emphasis>.
14704 If a DSO needs to use a symbol, this is called <emphasis>importing</emphasis>.
14705 A DSO might need to use symbols defined within itself or perhaps from another DSO.
14706 In both cases, it is importing that symbol, but the scope of the import differs.
14707 Similarly, a DSO might export a symbol for use only within itself, or it might export a symbol for use by other DSOs.
14708 Some symbols are resolved at compile time by the linker (those used within the DSO) and some are resolved at runtime by the dynamic link loader (symbols accessed between DSOs).</simpara>
14709 </section>
14710 <section id="_symbols_in_mlton">
14711 <title>Symbols in MLton</title>
14712 <simpara>Symbols in MLton are both imported and exported via the <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link>.
14713 The notation <literal>_import "symbolname"</literal> imports functions, <literal>_symbol "symbolname"</literal> imports variables, and <literal>_address "symbolname"</literal> imports an address.
14714 To create and export a symbol, <literal>_export "symbolname"</literal> creates a function symbol and <literal>_symbol "symbolname" 'alloc'</literal> creates and exports a variable.
14715 For details of the syntax and restrictions on the supported FFI types, read the <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link> page.
14716 In this discussion it only matters that every FFI use is either an import or an export.</simpara>
14717 <simpara>When exporting a symbol, MLton supports controlling the export scope.
14718 If the symbol should only be used within the same DSO, that symbol has <emphasis><literal>private</literal></emphasis> scope.
14719 Conversely, if the symbol should also be available to other DSOs the symbol has <emphasis><literal>public</literal></emphasis> scope.
14720 Generally, one should have as few public exports as possible.
14721 Since they are public, other DSOs will come to depend on them, limiting your ability to change them.
14722 You specify the export scope in MLton by putting <literal>private</literal> or <literal>public</literal> after the symbol&#8217;s name in an FFI directive.
14723 eg: <literal>_export "foo" private: int-&gt;int;</literal> or <literal>_export "bar" public: int-&gt;int;</literal> .</simpara>
14724 <simpara>For technical reasons, the linker and loader on various platforms need to know the scope of a symbol being imported.
14725 If the symbol is exported by the same DSO, use <literal>public</literal> or <literal>private</literal> as appropriate.
14726 If the symbol is exported by a different DSO, then the scope <emphasis><literal>external</literal></emphasis> should be used to import it.
14727 Within a DSO, all references to a symbol must use the same scope.
14728 MLton will check this at compile time, reporting: <literal>symbol "foo" redeclared as public (previously external)</literal>. This may cause linker errors.
14729 However, MLton can only check usage within Standard ML.
14730 All objects being linked into a resulting DSO must agree, and it is the programmer&#8217;s responsibility to ensure this.</simpara>
14731 <simpara>Summary of symbol scopes:</simpara>
14732 <itemizedlist>
14733 <listitem>
14734 <simpara>
14735 <literal>private</literal>: used for symbols exported within a DSO only for use within that DSO
14736 </simpara>
14737 </listitem>
14738 <listitem>
14739 <simpara>
14740 <literal>public</literal>: used for symbols exported within a DSO that may also be used outside that DSO
14741 </simpara>
14742 </listitem>
14743 <listitem>
14744 <simpara>
14745 <literal>external</literal>: used for importing symbols from another DSO
14746 </simpara>
14747 </listitem>
14748 <listitem>
14749 <simpara>
14750 All uses of a symbol within a DSO (both imports and exports) must agree on the symbol scope
14751 </simpara>
14752 </listitem>
14753 </itemizedlist>
14754 </section>
14755 <section id="_output_formats">
14756 <title>Output Formats</title>
14757 <simpara>MLton can create executables (<literal>-format executable</literal>) and dynamic shared libraries (<literal>-format library</literal>).
14758 To link a shared library, use <literal>-link-opt -l&lt;dso_name&gt;</literal>.
14759 The default output format is executable.</simpara>
14760 <simpara>MLton can also create archives.
14761 An archive is not a DSO, but it does have a collection of symbols.
14762 When an archive is linked into a DSO, it is completely absorbed.
14763 Other objects being compiled into the DSO should refer to the public symbols in the archive as public, since they are still in the same DSO.
14764 However, in the interest of modular programming, private symbols in an archive cannot be used outside of that archive, even within the same DSO.</simpara>
14765 <simpara>Although both executables and libraries are DSOs, some implementation details differ on some platforms.
14766 For this reason, MLton can create two types or archives.
14767 A normal archive (<literal>-format archive</literal>) is appropriate for linking into an executable.
14768 Conversely, a libarchive (<literal>-format libarchive</literal>) should be used if it will be linked into a dynamic library.</simpara>
14769 <simpara>When MLton does not create an executable, it creates two special symbols.
14770 The symbol <literal>libname_open</literal> is a function which must be called before any other symbols are accessed.
14771 The <literal>libname</literal> is controlled by the <literal>-libname</literal> compile option and defaults to the name of the output, with any prefixing lib stripped (eg: <literal>foo</literal> &#8594; <literal>foo</literal>, <literal>libfoo</literal> &#8594; <literal>foo</literal>).
14772 The symbol <literal>libname_close</literal> is a function which should be called to clean up memory once done.</simpara>
14773 <simpara>Summary of <literal>-format</literal> options:</simpara>
14774 <itemizedlist>
14775 <listitem>
14776 <simpara>
14777 <literal>executable</literal>: create an executable (a DSO)
14778 </simpara>
14779 </listitem>
14780 <listitem>
14781 <simpara>
14782 <literal>library</literal>: create a dynamic shared library (a DSO)
14783 </simpara>
14784 </listitem>
14785 <listitem>
14786 <simpara>
14787 <literal>archive</literal>: create an archive of symbols (not a DSO) that can be linked into an executable
14788 </simpara>
14789 </listitem>
14790 <listitem>
14791 <simpara>
14792 <literal>libarchive</literal>: create an archive of symbols (not a DSO) that can be linked into a library
14793 </simpara>
14794 </listitem>
14795 </itemizedlist>
14796 <simpara>Related options:</simpara>
14797 <itemizedlist>
14798 <listitem>
14799 <simpara>
14800 <literal>-libname x</literal>: controls the name of the special <literal>_open</literal> and <literal>_close</literal> functions.
14801 </simpara>
14802 </listitem>
14803 </itemizedlist>
14804 </section>
14805 <section id="_interfacing_with_c">
14806 <title>Interfacing with C</title>
14807 <simpara>MLton can generate a C header file.
14808 When the output format is not an executable, it creates one by default named <literal>libname.h</literal>.
14809 This can be overridden with <literal>-export-header foo.h</literal>.
14810 This header file should be included by any C files using the exported Standard ML symbols.</simpara>
14811 <simpara>If C is being linked with Standard ML into the same output archive or DSO,
14812 then the C code should <literal>#define PART_OF_LIBNAME</literal> before it includes the header file.
14813 This ensures that the C code is using the symbols with correct scope.
14814 Any symbols exported from C should also be marked using the <literal>PRIVATE</literal>/<literal>PUBLIC</literal>/<literal>EXTERNAL</literal> macros defined in the Standard ML export header.
14815 The declared C scope on exported C symbols should match the import scope used in Standard ML.</simpara>
14816 <simpara>An example:</simpara>
14817 <programlisting language="c" linenumbering="unnumbered">#define PART_OF_FOO
14818 #include "foo.h"
14819
14820 PUBLIC int cFoo() {
14821 return smlFoo();
14822 }</programlisting>
14823 <programlisting language="sml" linenumbering="unnumbered">val () = _export "smlFoo" private: unit -&gt; int; (fn () =&gt; 5)
14824 val cFoo = _import "cFoo" public: unit -&gt; int;</programlisting>
14825 </section>
14826 <section id="_operating_system_specific_details">
14827 <title>Operating-system specific details</title>
14828 <simpara>On Windows, <literal>libarchive</literal> and <literal>archive</literal> are the same.
14829 However, depending on this will lead to portability problems.
14830 Windows is also especially sensitive to mixups of <emphasis><literal>public</literal></emphasis> and <emphasis><literal>external</literal></emphasis>.
14831 If an archive is linked, make sure it&#8217;s symbols are imported as <literal>public</literal>.
14832 If a DLL is linked, make sure it&#8217;s symbols are imported as <literal>external</literal>.
14833 Using <literal>external</literal> instead of <literal>public</literal> will result in link errors that <literal>__imp__foo is undefined</literal>.
14834 Using <literal>public</literal> instead of <literal>external</literal> will result in inconsistent function pointer addresses and failure to update the imported variables.</simpara>
14835 <simpara>On Linux, <literal>libarchive</literal> and <literal>archive</literal> are different.
14836 Libarchives are quite rare, but necessary if creating a library from an archive.
14837 It is common for a library to provide both an archive and a dynamic library on this platform.
14838 The linker will pick one or the other, usually preferring the dynamic library.
14839 While a quirk of the operating system allows external import to work for both archives and libraries,
14840 portable projects should not depend on this behaviour.
14841 On other systems it can matter how the library is linked (static or dynamic).</simpara>
14842 <simpara><?asciidoc-pagebreak?></simpara>
14843 </section>
14844 </section>
14845 <section id="License">
14846 <title>License</title>
14847 <section id="_web_site">
14848 <title>Web Site</title>
14849 <simpara>In order to allow the maximum freedom for the future use of the
14850 content in this web site, we require that contributions to the web
14851 site be dedicated to the public domain. That means that you can only
14852 add works that are already in the public domain, or that you must hold
14853 the copyright on the work that you agree to dedicate the work to the
14854 public domain.</simpara>
14855 <simpara>By contributing to this web site, you agree to dedicate your
14856 contribution to the public domain.</simpara>
14857 </section>
14858 <section id="_software">
14859 <title>Software</title>
14860 <simpara>As of 20050812, MLton software is licensed under the BSD-style license
14861 below. By contributing code to the project, you agree to release the
14862 code under this license. Contributors can retain copyright to their
14863 contributions by asserting copyright in their code. Contributors may
14864 also add to the list of copyright holders in
14865 <literal>doc/license/MLton-LICENSE</literal>, which appears below.</simpara>
14866 <programlisting language="text" linenumbering="unnumbered">../../LICENSE</programlisting>
14867 <simpara><?asciidoc-pagebreak?></simpara>
14868 </section>
14869 </section>
14870 <section id="LineDirective">
14871 <title>LineDirective</title>
14872 <simpara>To aid in the debugging of code produced by program generators such
14873 as <ulink url="http://www.eecs.harvard.edu/%7Enr/noweb/">Noweb</ulink>, MLton supports
14874 comments with line directives of the form</simpara>
14875 <programlisting language="sml" linenumbering="unnumbered">(*#line l.c "f"*)</programlisting>
14876 <simpara>Here, <emphasis>l</emphasis> and <emphasis>c</emphasis> are sequences of decimal digits and <emphasis>f</emphasis> is the
14877 source file. The first character of a source file has the position
14878 1.1. A line directive causes the front end to believe that the
14879 character following the right parenthesis is at the line and column of
14880 the specified file. A line directive only affects the reporting of
14881 error messages and does not affect program semantics (except for
14882 functions like <literal>MLton.Exn.history</literal> that report source file positions).
14883 Syntactically invalid line directives are ignored. To prevent
14884 incompatibilities with SML, the file name may not contain the
14885 character sequence <literal>*)</literal>.</simpara>
14886 <simpara><?asciidoc-pagebreak?></simpara>
14887 </section>
14888 <section id="LLVM">
14889 <title>LLVM</title>
14890 <simpara>The <ulink url="http://www.llvm.org/">LLVM Project</ulink> is a collection of modular and
14891 reusable compiler and toolchain technologies.</simpara>
14892 <simpara>MLton supports code generation via LLVM (<literal>-codegen llvm</literal>); see
14893 <link linkend="LLVMCodegen">LLVMCodegen</link>.</simpara>
14894 <section id="_also_see_9">
14895 <title>Also see</title>
14896 <itemizedlist>
14897 <listitem>
14898 <simpara>
14899 <link linkend="CMinusMinus">CMinusMinus</link>
14900 </simpara>
14901 </listitem>
14902 </itemizedlist>
14903 <simpara><?asciidoc-pagebreak?></simpara>
14904 </section>
14905 </section>
14906 <section id="LLVMCodegen">
14907 <title>LLVMCodegen</title>
14908 <simpara>The <link linkend="LLVMCodegen">LLVMCodegen</link> is a <link linkend="Codegen">code generator</link> that translates the
14909 <link linkend="Machine">Machine</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> to <link linkend="LLVM">LLVM</link> assembly, which is
14910 further optimized and compiled to native object code by the <link linkend="LLVM">LLVM</link>
14911 toolchain.</simpara>
14912 <simpara>It requires <link linkend="LLVM">LLVM</link> version 3.7 or greater to be installed.</simpara>
14913 <simpara>In benchmarks performed on the <link linkend="RunningOnAMD64">AMD64</link> architecture,
14914 code size with this generator is usually slightly smaller than either
14915 the <link linkend="AMD64Codegen">native</link> or the <link linkend="CCodegen">C</link> code generators. Compile
14916 time is worse than <link linkend="AMD64Codegen">native</link>, but slightly better than
14917 <link linkend="CCodegen">C</link>. Run time is often better than either <link linkend="AMD64Codegen">native</link>
14918 or <link linkend="CCodegen">C</link>.</simpara>
14919 <section id="_implementation_32">
14920 <title>Implementation</title>
14921 <itemizedlist>
14922 <listitem>
14923 <simpara>
14924 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/codegen/llvm-codegen/llvm-codegen.sig"><literal>llvm-codegen.sig</literal></ulink>
14925 </simpara>
14926 </listitem>
14927 <listitem>
14928 <simpara>
14929 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/codegen/llvm-codegen/llvm-codegen.fun"><literal>llvm-codegen.fun</literal></ulink>
14930 </simpara>
14931 </listitem>
14932 </itemizedlist>
14933 </section>
14934 <section id="_details_and_notes_32">
14935 <title>Details and Notes</title>
14936 <simpara>The <link linkend="LLVMCodegen">LLVMCodegen</link> was initially developed by Brian Leibig (see
14937 <link linkend="References_Leibig13">An LLVM Back-end for MLton</link>).</simpara>
14938 <simpara><?asciidoc-pagebreak?></simpara>
14939 </section>
14940 </section>
14941 <section id="LocalFlatten">
14942 <title>LocalFlatten</title>
14943 <simpara><link linkend="LocalFlatten">LocalFlatten</link> is an optimization pass for the <link linkend="SSA">SSA</link>
14944 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
14945 <section id="_description_30">
14946 <title>Description</title>
14947 <simpara>This pass flattens arguments to <link linkend="SSA">SSA</link> blocks.</simpara>
14948 <simpara>A block argument is flattened as long as it only flows to selects and
14949 there is some tuple constructed in this function that flows to it.</simpara>
14950 </section>
14951 <section id="_implementation_33">
14952 <title>Implementation</title>
14953 <itemizedlist>
14954 <listitem>
14955 <simpara>
14956 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/local-flatten.fun"><literal>local-flatten.fun</literal></ulink>
14957 </simpara>
14958 </listitem>
14959 </itemizedlist>
14960 </section>
14961 <section id="_details_and_notes_33">
14962 <title>Details and Notes</title>
14963 <simpara></simpara>
14964 <simpara><?asciidoc-pagebreak?></simpara>
14965 </section>
14966 </section>
14967 <section id="LocalRef">
14968 <title>LocalRef</title>
14969 <simpara><link linkend="LocalRef">LocalRef</link> is an optimization pass for the <link linkend="SSA">SSA</link>
14970 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
14971 <section id="_description_31">
14972 <title>Description</title>
14973 <simpara>This pass optimizes <literal>ref</literal> cells local to a <link linkend="SSA">SSA</link> function:</simpara>
14974 <itemizedlist>
14975 <listitem>
14976 <simpara>
14977 global <literal>ref</literal>-s only used in one function are moved to the function
14978 </simpara>
14979 </listitem>
14980 <listitem>
14981 <simpara>
14982 <literal>ref</literal>-s only created, read from, and written to (i.e., don&#8217;t escape)
14983 are converted into function local variables
14984 </simpara>
14985 </listitem>
14986 </itemizedlist>
14987 <simpara>Uses <link linkend="Multi">Multi</link> and <link linkend="Restore">Restore</link>.</simpara>
14988 </section>
14989 <section id="_implementation_34">
14990 <title>Implementation</title>
14991 <itemizedlist>
14992 <listitem>
14993 <simpara>
14994 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/local-ref.fun"><literal>local-ref.fun</literal></ulink>
14995 </simpara>
14996 </listitem>
14997 </itemizedlist>
14998 </section>
14999 <section id="_details_and_notes_34">
15000 <title>Details and Notes</title>
15001 <simpara>Moving a global <literal>ref</literal> requires the <link linkend="Multi">Multi</link> analysis, because a
15002 global <literal>ref</literal> can only be moved into a function that is executed at
15003 most once.</simpara>
15004 <simpara>Conversion of non-escaping <literal>ref</literal>-s is structured in three phases:</simpara>
15005 <itemizedlist>
15006 <listitem>
15007 <simpara>
15008 analysis&#8201;&#8212;&#8201;a variable <literal>r = Ref_ref x</literal> escapes if
15009 </simpara>
15010 <itemizedlist>
15011 <listitem>
15012 <simpara>
15013 <literal>r</literal> is used in any context besides <literal>Ref_assign (r, _)</literal> or <literal>Ref_deref r</literal>
15014 </simpara>
15015 </listitem>
15016 <listitem>
15017 <simpara>
15018 all uses <literal>r</literal> reachable from a (direct or indirect) call to <literal>Thread_copyCurrent</literal> are of the same flavor (either <literal>Ref_assign</literal> or <literal>Ref_deref</literal>); this also requires the <link linkend="Multi">Multi</link> analysis.
15019 </simpara>
15020 </listitem>
15021 </itemizedlist>
15022 </listitem>
15023 <listitem>
15024 <simpara>
15025 transformation
15026 </simpara>
15027 <itemizedlist>
15028 <listitem>
15029 <simpara>
15030 rewrites <literal>r = Ref_ref x</literal> to <literal>r = x</literal>
15031 </simpara>
15032 </listitem>
15033 <listitem>
15034 <simpara>
15035 rewrites <literal>_ = Ref_assign (r, y)</literal> to <literal>r = y</literal>
15036 </simpara>
15037 </listitem>
15038 <listitem>
15039 <simpara>
15040 rewrites <literal>z = Ref_deref r</literal> to <literal>z = r</literal>
15041 </simpara>
15042 </listitem>
15043 </itemizedlist>
15044 <simpara>Note that the resulting program violates the SSA condition.</simpara>
15045 </listitem>
15046 <listitem>
15047 <simpara>
15048 <link linkend="Restore">Restore</link>&#8201;&#8212;&#8201;restore the SSA condition.
15049 </simpara>
15050 </listitem>
15051 </itemizedlist>
15052 <simpara><?asciidoc-pagebreak?></simpara>
15053 </section>
15054 </section>
15055 <section id="Logo">
15056 <title>Logo</title>
15057 <informalfigure>
15058 <mediaobject>
15059 <imageobject>
15060 <imagedata fileref="Logo.attachments/mlton-128.pdf" align="center"/>
15061 </imageobject>
15062 <textobject><phrase>Logo.attachments/mlton-128.pdf</phrase></textobject>
15063 </mediaobject>
15064 </informalfigure>
15065 <section id="_files">
15066 <title>Files</title>
15067 <itemizedlist>
15068 <listitem>
15069 <simpara>
15070 <ulink url="guide/Logo.attachments/mlton.svg"><literal>mlton.svg</literal></ulink>
15071 </simpara>
15072 </listitem>
15073 <listitem>
15074 <simpara>
15075 <ulink url="guide/Logo.attachments/mlton-1024.png"><literal>mlton-1024.png</literal></ulink>
15076 </simpara>
15077 </listitem>
15078 <listitem>
15079 <simpara>
15080 <ulink url="guide/Logo.attachments/mlton-512.png"><literal>mlton-512.png</literal></ulink>
15081 </simpara>
15082 </listitem>
15083 <listitem>
15084 <simpara>
15085 <ulink url="guide/Logo.attachments/mlton-256.png"><literal>mlton-256.png</literal></ulink>
15086 </simpara>
15087 </listitem>
15088 <listitem>
15089 <simpara>
15090 <ulink url="guide/Logo.attachments/mlton-128.png"><literal>mlton-128.png</literal></ulink>
15091 </simpara>
15092 </listitem>
15093 <listitem>
15094 <simpara>
15095 <ulink url="guide/Logo.attachments/mlton-64.png"><literal>mlton-64.png</literal></ulink>
15096 </simpara>
15097 </listitem>
15098 <listitem>
15099 <simpara>
15100 <ulink url="guide/Logo.attachments/mlton-32.png"><literal>mlton-32.png</literal></ulink>
15101 </simpara>
15102 </listitem>
15103 </itemizedlist>
15104 <simpara><?asciidoc-pagebreak?></simpara>
15105 </section>
15106 </section>
15107 <section id="LoopInvariant">
15108 <title>LoopInvariant</title>
15109 <simpara><link linkend="LoopInvariant">LoopInvariant</link> is an optimization pass for the <link linkend="SSA">SSA</link>
15110 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
15111 <section id="_description_32">
15112 <title>Description</title>
15113 <simpara>This pass removes loop invariant arguments to local loops.</simpara>
15114 <screen> loop (x, y)
15115 ...
15116 ...
15117 loop (x, z)
15118 ...</screen>
15119 <simpara>becomes</simpara>
15120 <screen> loop' (x, y)
15121 loop (y)
15122 loop (y)
15123 ...
15124 ...
15125 loop (z)
15126 ...</screen>
15127 </section>
15128 <section id="_implementation_35">
15129 <title>Implementation</title>
15130 <itemizedlist>
15131 <listitem>
15132 <simpara>
15133 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/loop-invariant.fun"><literal>loop-invariant.fun</literal></ulink>
15134 </simpara>
15135 </listitem>
15136 </itemizedlist>
15137 </section>
15138 <section id="_details_and_notes_35">
15139 <title>Details and Notes</title>
15140 <simpara></simpara>
15141 <simpara><?asciidoc-pagebreak?></simpara>
15142 </section>
15143 </section>
15144 <section id="LoopUnroll">
15145 <title>LoopUnroll</title>
15146 <simpara><link linkend="LoopUnroll">LoopUnroll</link> is an optimization pass for the <link linkend="SSA">SSA</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>,
15147 invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
15148 <section id="_description_33">
15149 <title>Description</title>
15150 <simpara>A simple loop unrolling optimization.</simpara>
15151 </section>
15152 <section id="_implementation_36">
15153 <title>Implementation</title>
15154 <itemizedlist>
15155 <listitem>
15156 <simpara>
15157 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/loop-unroll.fun"><literal>loop-unroll.fun</literal></ulink>
15158 </simpara>
15159 </listitem>
15160 </itemizedlist>
15161 </section>
15162 <section id="_details_and_notes_36">
15163 <title>Details and Notes</title>
15164 <simpara></simpara>
15165 <simpara><?asciidoc-pagebreak?></simpara>
15166 </section>
15167 </section>
15168 <section id="LoopUnswitch">
15169 <title>LoopUnswitch</title>
15170 <simpara><link linkend="LoopUnswitch">LoopUnswitch</link> is an optimization pass for the <link linkend="SSA">SSA</link>
15171 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
15172 <section id="_description_34">
15173 <title>Description</title>
15174 <simpara>A simple loop unswitching optimization.</simpara>
15175 </section>
15176 <section id="_implementation_37">
15177 <title>Implementation</title>
15178 <itemizedlist>
15179 <listitem>
15180 <simpara>
15181 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/loop-unswitch.fun"><literal>loop-unswitch.fun</literal></ulink>
15182 </simpara>
15183 </listitem>
15184 </itemizedlist>
15185 </section>
15186 <section id="_details_and_notes_37">
15187 <title>Details and Notes</title>
15188 <simpara></simpara>
15189 <simpara><?asciidoc-pagebreak?></simpara>
15190 </section>
15191 </section>
15192 <section id="Machine">
15193 <title>Machine</title>
15194 <simpara><link linkend="Machine">Machine</link> is an <link linkend="IntermediateLanguage">IntermediateLanguage</link>, translated from <link linkend="RSSA">RSSA</link>
15195 by <link linkend="ToMachine">ToMachine</link> and used as input by the <link linkend="Codegen">Codegen</link>.</simpara>
15196 <section id="_description_35">
15197 <title>Description</title>
15198 <simpara><link linkend="Machine">Machine</link> is an <link linkend="Untyped">Untyped</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>, corresponding
15199 to a abstract register machine.</simpara>
15200 </section>
15201 <section id="_implementation_38">
15202 <title>Implementation</title>
15203 <itemizedlist>
15204 <listitem>
15205 <simpara>
15206 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/machine.sig"><literal>machine.sig</literal></ulink>
15207 </simpara>
15208 </listitem>
15209 <listitem>
15210 <simpara>
15211 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/machine.fun"><literal>machine.fun</literal></ulink>
15212 </simpara>
15213 </listitem>
15214 </itemizedlist>
15215 </section>
15216 <section id="_type_checking_3">
15217 <title>Type Checking</title>
15218 <simpara>The <link linkend="Machine">Machine</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> has a primitive type checker
15219 (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/machine.sig"><literal>machine.sig</literal></ulink>,
15220 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/machine.fun"><literal>machine.fun</literal></ulink>), which only checks
15221 some liveness properties.</simpara>
15222 </section>
15223 <section id="_details_and_notes_38">
15224 <title>Details and Notes</title>
15225 <simpara>The runtime structure sets some constants according to the
15226 configuration files on the target architecture and OS.</simpara>
15227 <simpara><?asciidoc-pagebreak?></simpara>
15228 </section>
15229 </section>
15230 <section id="ManualPage">
15231 <title>ManualPage</title>
15232 <simpara>MLton is run from the command line with a collection of options
15233 followed by a file name and a list of files to compile, assemble, and
15234 link with.</simpara>
15235 <screen>mlton [option ...] file.{c|mlb|o|sml} [file.{c|o|s|S} ...]</screen>
15236 <simpara>The simplest case is to run <literal>mlton foo.sml</literal>, where <literal>foo.sml</literal> contains
15237 a valid SML program, in which case MLton compiles the program to
15238 produce an executable <literal>foo</literal>. Since MLton does not support separate
15239 compilation, the program must be the entire program you wish to
15240 compile. However, the program may refer to signatures and structures
15241 defined in the <link linkend="BasisLibrary">Basis Library</link>.</simpara>
15242 <simpara>Larger programs, spanning many files, can be compiled with the
15243 <link linkend="MLBasis">ML Basis system</link>. In this case, <literal>mlton foo.mlb</literal> will
15244 compile the complete SML program described by the basis <literal>foo.mlb</literal>,
15245 which may specify both SML files and additional bases.</simpara>
15246 <section id="_next_steps_3">
15247 <title>Next Steps</title>
15248 <itemizedlist>
15249 <listitem>
15250 <simpara>
15251 <link linkend="CompileTimeOptions">CompileTimeOptions</link>
15252 </simpara>
15253 </listitem>
15254 <listitem>
15255 <simpara>
15256 <link linkend="RunTimeOptions">RunTimeOptions</link>
15257 </simpara>
15258 </listitem>
15259 </itemizedlist>
15260 <simpara><?asciidoc-pagebreak?></simpara>
15261 </section>
15262 </section>
15263 <section id="MatchCompilation">
15264 <title>MatchCompilation</title>
15265 <simpara>Match compilation is the process of translating an SML match into a
15266 nested tree (or dag) of simple case expressions and tests.</simpara>
15267 <simpara>MLton&#8217;s match compiler is described <link linkend="MatchCompile">here</link>.</simpara>
15268 <section id="_match_compilation_in_other_compilers">
15269 <title>Match compilation in other compilers</title>
15270 <itemizedlist>
15271 <listitem>
15272 <simpara>
15273 <link linkend="References_BaudinetMacQueen85">BaudinetMacQueen85</link>
15274 </simpara>
15275 </listitem>
15276 <listitem>
15277 <simpara>
15278 <link linkend="References_Leroy90">Leroy90</link>, pages 60-69.
15279 </simpara>
15280 </listitem>
15281 <listitem>
15282 <simpara>
15283 <link linkend="References_Sestoft96">Sestoft96</link>
15284 </simpara>
15285 </listitem>
15286 <listitem>
15287 <simpara>
15288 <link linkend="References_ScottRamsey00">ScottRamsey00</link>
15289 </simpara>
15290 </listitem>
15291 </itemizedlist>
15292 <simpara><?asciidoc-pagebreak?></simpara>
15293 </section>
15294 </section>
15295 <section id="MatchCompile">
15296 <title>MatchCompile</title>
15297 <simpara><link linkend="MatchCompile">MatchCompile</link> is a translation pass, agnostic in the
15298 <link linkend="IntermediateLanguage">IntermediateLanguage</link>s between which it translates.</simpara>
15299 <section id="_description_36">
15300 <title>Description</title>
15301 <simpara><link linkend="MatchCompilation">Match compilation</link> converts a case expression with
15302 nested patterns into a case expression with flat patterns.</simpara>
15303 </section>
15304 <section id="_implementation_39">
15305 <title>Implementation</title>
15306 <itemizedlist>
15307 <listitem>
15308 <simpara>
15309 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/match-compile/match-compile.sig"><literal>match-compile.sig</literal></ulink>
15310 </simpara>
15311 </listitem>
15312 <listitem>
15313 <simpara>
15314 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/match-compile/match-compile.fun"><literal>match-compile.fun</literal></ulink>
15315 </simpara>
15316 </listitem>
15317 </itemizedlist>
15318 </section>
15319 <section id="_details_and_notes_39">
15320 <title>Details and Notes</title>
15321 <programlisting language="sml" linenumbering="unnumbered">val matchCompile:
15322 {caseType: Type.t, (* type of entire expression *)
15323 cases: (NestedPat.t * ((Var.t -&gt; Var.t) -&gt; Exp.t)) vector,
15324 conTycon: Con.t -&gt; Tycon.t,
15325 region: Region.t,
15326 test: Var.t,
15327 testType: Type.t,
15328 tyconCons: Tycon.t -&gt; {con: Con.t, hasArg: bool} vector}
15329 -&gt; Exp.t * (unit -&gt; ((Layout.t * {isOnlyExns: bool}) vector) vector)</programlisting>
15330 <simpara><literal>matchCompile</literal> is complicated by the desire for modularity between the
15331 match compiler and its caller. Its caller is responsible for building
15332 the right hand side of a rule <literal>p =&gt; e</literal>. On the other hand, the match
15333 compiler is responsible for destructing the test and binding new
15334 variables to the components. In order to connect the new variables
15335 created by the match compiler with the variables in the pattern <literal>p</literal>,
15336 the match compiler passes an environment back to its caller that maps
15337 each variable in <literal>p</literal> to the corresponding variable introduced by the
15338 match compiler.</simpara>
15339 <simpara>The match compiler builds a tree of n-way case expressions by working
15340 from outside to inside and left to right in the patterns. For example,</simpara>
15341 <programlisting language="sml" linenumbering="unnumbered">case x of
15342 (_, C1 a) =&gt; e1
15343 | (C2 b, C3 c) =&gt; e2</programlisting>
15344 <simpara>is translated to</simpara>
15345 <programlisting language="sml" linenumbering="unnumbered">let
15346 fun f1 a = e1
15347 fun f2 (b, c) = e2
15348 in
15349 case x of
15350 (x1, x2) =&gt;
15351 (case x1 of
15352 C2 b' =&gt; (case x2 of
15353 C1 a' =&gt; f1 a'
15354 | C3 c' =&gt; f2(b',c')
15355 | _ =&gt; raise Match)
15356 | _ =&gt; (case x2 of
15357 C1 a_ =&gt; f1 a_
15358 | _ =&gt; raise Match))
15359 end</programlisting>
15360 <simpara>Here you can see the necessity of abstracting out the ride hand sides
15361 of the cases in order to avoid code duplication. Right hand sides are
15362 always abstracted. The simplifier cleans things up. You can also see
15363 the new (primed) variables introduced by the match compiler and how
15364 the renaming works. Finally, you can see how the match compiler
15365 introduces the necessary default clauses in order to make a match
15366 exhaustive, i.e. cover all the cases.</simpara>
15367 <simpara>The match compiler uses <literal>numCons</literal> and <literal>tyconCons</literal> to determine
15368 the exhaustivity of matches against constructors.</simpara>
15369 <simpara><?asciidoc-pagebreak?></simpara>
15370 </section>
15371 </section>
15372 <section id="MatthewFluet">
15373 <title>MatthewFluet</title>
15374 <simpara>Matthew Fluet (
15375 <ulink url="mailto:matthew.fluet@gmail.com">matthew.fluet@gmail.com</ulink>
15376 ,
15377 <ulink url="http://www.cs.rit.edu/%7Emtf">http://www.cs.rit.edu/%7Emtf</ulink>
15378 )
15379 is an Assistant Professor at the <ulink url="http://www.rit.edu">Rochester Institute of Technology</ulink>.</simpara>
15380 <simpara><?asciidoc-hr?></simpara>
15381 <simpara>Current MLton projects:</simpara>
15382 <itemizedlist>
15383 <listitem>
15384 <simpara>
15385 general maintenance
15386 </simpara>
15387 </listitem>
15388 <listitem>
15389 <simpara>
15390 release new version
15391 </simpara>
15392 </listitem>
15393 </itemizedlist>
15394 <simpara><?asciidoc-hr?></simpara>
15395 <simpara>Misc. and underspecified TODOs:</simpara>
15396 <itemizedlist>
15397 <listitem>
15398 <simpara>
15399 understand <link linkend="RefFlatten">RefFlatten</link> and <link linkend="DeepFlatten">DeepFlatten</link>
15400 </simpara>
15401 <itemizedlist>
15402 <listitem>
15403 <simpara>
15404 <ulink url="http://www.mlton.org/pipermail/mlton/2005-April/026990.html">http://www.mlton.org/pipermail/mlton/2005-April/026990.html</ulink>
15405 </simpara>
15406 </listitem>
15407 <listitem>
15408 <simpara>
15409 <ulink url="http://www.mlton.org/pipermail/mlton/2007-November/030056.html">http://www.mlton.org/pipermail/mlton/2007-November/030056.html</ulink>
15410 </simpara>
15411 </listitem>
15412 <listitem>
15413 <simpara>
15414 <ulink url="http://www.mlton.org/pipermail/mlton/2008-April/030250.html">http://www.mlton.org/pipermail/mlton/2008-April/030250.html</ulink>
15415 </simpara>
15416 </listitem>
15417 <listitem>
15418 <simpara>
15419 <ulink url="http://www.mlton.org/pipermail/mlton/2008-July/030279.html">http://www.mlton.org/pipermail/mlton/2008-July/030279.html</ulink>
15420 </simpara>
15421 </listitem>
15422 <listitem>
15423 <simpara>
15424 <ulink url="http://www.mlton.org/pipermail/mlton/2008-August/030312.html">http://www.mlton.org/pipermail/mlton/2008-August/030312.html</ulink>
15425 </simpara>
15426 </listitem>
15427 <listitem>
15428 <simpara>
15429 <ulink url="http://www.mlton.org/pipermail/mlton/2008-September/030360.html">http://www.mlton.org/pipermail/mlton/2008-September/030360.html</ulink>
15430 </simpara>
15431 </listitem>
15432 <listitem>
15433 <simpara>
15434 <ulink url="http://www.mlton.org/pipermail/mlton-user/2009-June/001542.html">http://www.mlton.org/pipermail/mlton-user/2009-June/001542.html</ulink>
15435 </simpara>
15436 </listitem>
15437 </itemizedlist>
15438 </listitem>
15439 <listitem>
15440 <simpara>
15441 <literal>MSG_DONTWAIT</literal> isn&#8217;t Posix
15442 </simpara>
15443 </listitem>
15444 <listitem>
15445 <simpara>
15446 coordinate w/ Dan Spoonhower and Lukasz Ziarek and Armand Navabi on multi-threaded
15447 </simpara>
15448 <itemizedlist>
15449 <listitem>
15450 <simpara>
15451 <ulink url="http://www.mlton.org/pipermail/mlton/2008-March/030214.html">http://www.mlton.org/pipermail/mlton/2008-March/030214.html</ulink>
15452 </simpara>
15453 </listitem>
15454 </itemizedlist>
15455 </listitem>
15456 <listitem>
15457 <simpara>
15458 Intel Research bug: <literal>no tyconRep property</literal> (company won&#8217;t release sample code)
15459 </simpara>
15460 <itemizedlist>
15461 <listitem>
15462 <simpara>
15463 <ulink url="http://www.mlton.org/pipermail/mlton-user/2008-March/001358.html">http://www.mlton.org/pipermail/mlton-user/2008-March/001358.html</ulink>
15464 </simpara>
15465 </listitem>
15466 </itemizedlist>
15467 </listitem>
15468 <listitem>
15469 <simpara>
15470 treatment of real constants
15471 </simpara>
15472 <itemizedlist>
15473 <listitem>
15474 <simpara>
15475 <ulink url="http://www.mlton.org/pipermail/mlton/2008-May/030262.html">http://www.mlton.org/pipermail/mlton/2008-May/030262.html</ulink>
15476 </simpara>
15477 </listitem>
15478 <listitem>
15479 <simpara>
15480 <ulink url="http://www.mlton.org/pipermail/mlton/2008-June/030271.html">http://www.mlton.org/pipermail/mlton/2008-June/030271.html</ulink>
15481 </simpara>
15482 </listitem>
15483 </itemizedlist>
15484 </listitem>
15485 <listitem>
15486 <simpara>
15487 representation of <literal>bool</literal> and <literal>_bool</literal> in <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link>
15488 </simpara>
15489 <itemizedlist>
15490 <listitem>
15491 <simpara>
15492 <ulink url="http://www.mlton.org/pipermail/mlton/2008-May/030264.html">http://www.mlton.org/pipermail/mlton/2008-May/030264.html</ulink>
15493 </simpara>
15494 </listitem>
15495 </itemizedlist>
15496 </listitem>
15497 <listitem>
15498 <simpara>
15499 <ulink url="http://www.icfpcontest.org">http://www.icfpcontest.org</ulink>
15500 </simpara>
15501 <itemizedlist>
15502 <listitem>
15503 <simpara>
15504 John Reppy claims that "It looks like the card-marking overhead that one incurs when using generational collection swamps the benefits of generational collection."
15505 </simpara>
15506 </listitem>
15507 </itemizedlist>
15508 </listitem>
15509 <listitem>
15510 <simpara>
15511 page to disk policy / single heap
15512 </simpara>
15513 <itemizedlist>
15514 <listitem>
15515 <simpara>
15516 <ulink url="http://www.mlton.org/pipermail/mlton/2008-June/030278.html">http://www.mlton.org/pipermail/mlton/2008-June/030278.html</ulink>
15517 </simpara>
15518 </listitem>
15519 <listitem>
15520 <simpara>
15521 <ulink url="http://www.mlton.org/pipermail/mlton/2008-August/030318.html">http://www.mlton.org/pipermail/mlton/2008-August/030318.html</ulink>
15522 </simpara>
15523 </listitem>
15524 </itemizedlist>
15525 </listitem>
15526 <listitem>
15527 <simpara>
15528 <literal>MLton.GC.pack</literal> doesn&#8217;t keep a small heap if a garbage collection occurs before <literal>MLton.GC.unpack</literal>.
15529 </simpara>
15530 <itemizedlist>
15531 <listitem>
15532 <simpara>
15533 It might be preferable for <literal>MLton.GC.pack</literal> to be implemented as a (new) <literal>MLton.GC.Ratios.setLive 1.1</literal> followed by <literal>MLton.GC.collect ()</literal> and for <literal>MLton.GC.unpack</literal> to be implemented as <literal>MLton.GC.Ratios.setLive 8.0</literal> followed by <literal>MLton.GC.collect ()</literal>.
15534 </simpara>
15535 </listitem>
15536 </itemizedlist>
15537 </listitem>
15538 <listitem>
15539 <simpara>
15540 The <literal>static struct GC_objectType objectTypes[] =</literal> array includes many duplicates. Objects of distinct source type, but equivalent representations (in terms of size, bytes non-pointers, number pointers) can share the objectType index.
15541 </simpara>
15542 </listitem>
15543 <listitem>
15544 <simpara>
15545 PolySpace bug: <link linkend="Redundant">Redundant</link> optimization (company won&#8217;t release sample code)
15546 </simpara>
15547 <itemizedlist>
15548 <listitem>
15549 <simpara>
15550 <ulink url="http://www.mlton.org/pipermail/mlton/2008-September/030355.html">http://www.mlton.org/pipermail/mlton/2008-September/030355.html</ulink>
15551 </simpara>
15552 </listitem>
15553 </itemizedlist>
15554 </listitem>
15555 <listitem>
15556 <simpara>
15557 treatment of exception raised during <link linkend="BasisLibrary">BasisLibrary</link> evaluation
15558 </simpara>
15559 <itemizedlist>
15560 <listitem>
15561 <simpara>
15562 <ulink url="http://www.mlton.org/pipermail/mlton/2008-December/030501.html">http://www.mlton.org/pipermail/mlton/2008-December/030501.html</ulink>
15563 </simpara>
15564 </listitem>
15565 <listitem>
15566 <simpara>
15567 <ulink url="http://www.mlton.org/pipermail/mlton/2008-December/030502.html">http://www.mlton.org/pipermail/mlton/2008-December/030502.html</ulink>
15568 </simpara>
15569 </listitem>
15570 <listitem>
15571 <simpara>
15572 <ulink url="http://www.mlton.org/pipermail/mlton/2008-December/030503.html">http://www.mlton.org/pipermail/mlton/2008-December/030503.html</ulink>
15573 </simpara>
15574 </listitem>
15575 </itemizedlist>
15576 </listitem>
15577 <listitem>
15578 <simpara>
15579 Use <literal>memcpy</literal>
15580 </simpara>
15581 <itemizedlist>
15582 <listitem>
15583 <simpara>
15584 <ulink url="http://www.mlton.org/pipermail/mlton-user/2009-January/001506.html">http://www.mlton.org/pipermail/mlton-user/2009-January/001506.html</ulink>
15585 </simpara>
15586 </listitem>
15587 <listitem>
15588 <simpara>
15589 <ulink url="http://www.mlton.org/pipermail/mlton/2009-January/030506.html">http://www.mlton.org/pipermail/mlton/2009-January/030506.html</ulink>
15590 </simpara>
15591 </listitem>
15592 </itemizedlist>
15593 </listitem>
15594 <listitem>
15595 <simpara>
15596 Implement more 64bit primops in x86 codegen
15597 </simpara>
15598 <itemizedlist>
15599 <listitem>
15600 <simpara>
15601 <ulink url="http://www.mlton.org/pipermail/mlton/2009-January/030507.html">http://www.mlton.org/pipermail/mlton/2009-January/030507.html</ulink>
15602 </simpara>
15603 </listitem>
15604 </itemizedlist>
15605 </listitem>
15606 <listitem>
15607 <simpara>
15608 Enrich path-map file syntax:
15609 </simpara>
15610 <itemizedlist>
15611 <listitem>
15612 <simpara>
15613 <ulink url="http://www.mlton.org/pipermail/mlton/2008-September/030348.html">http://www.mlton.org/pipermail/mlton/2008-September/030348.html</ulink>
15614 </simpara>
15615 </listitem>
15616 <listitem>
15617 <simpara>
15618 <ulink url="http://www.mlton.org/pipermail/mlton-user/2009-January/001507.html">http://www.mlton.org/pipermail/mlton-user/2009-January/001507.html</ulink>
15619 </simpara>
15620 </listitem>
15621 </itemizedlist>
15622 </listitem>
15623 <listitem>
15624 <simpara>
15625 PolySpace bug: crash during Cheney-copy collection
15626 </simpara>
15627 <itemizedlist>
15628 <listitem>
15629 <simpara>
15630 <ulink url="http://www.mlton.org/pipermail/mlton/2009-February/030513.html">http://www.mlton.org/pipermail/mlton/2009-February/030513.html</ulink>
15631 </simpara>
15632 </listitem>
15633 </itemizedlist>
15634 </listitem>
15635 <listitem>
15636 <simpara>
15637 eliminate <literal>-build-constants</literal>
15638 </simpara>
15639 <itemizedlist>
15640 <listitem>
15641 <simpara>
15642 all <literal>_const</literal>-s are known by <literal>runtime/gen/basis-ffi.def</literal>
15643 </simpara>
15644 </listitem>
15645 <listitem>
15646 <simpara>
15647 generate <literal>gen-constants.c</literal> from <literal>basis-ffi.def</literal>
15648 </simpara>
15649 </listitem>
15650 <listitem>
15651 <simpara>
15652 generate <literal>constants</literal> from <literal>gen-constants.c</literal> and <literal>libmlton.a</literal>
15653 </simpara>
15654 </listitem>
15655 <listitem>
15656 <simpara>
15657 similar to <literal>gen-sizes.c</literal> and <literal>sizes</literal>
15658 </simpara>
15659 </listitem>
15660 </itemizedlist>
15661 </listitem>
15662 <listitem>
15663 <simpara>
15664 eliminate "Windows hacks" for Cygwin from <literal>Path</literal> module
15665 </simpara>
15666 <itemizedlist>
15667 <listitem>
15668 <simpara>
15669 <ulink url="http://www.mlton.org/pipermail/mlton/2009-July/030606.html">http://www.mlton.org/pipermail/mlton/2009-July/030606.html</ulink>
15670 </simpara>
15671 </listitem>
15672 </itemizedlist>
15673 </listitem>
15674 <listitem>
15675 <simpara>
15676 extend IL type checkers to check for empty property lists
15677 </simpara>
15678 </listitem>
15679 <listitem>
15680 <simpara>
15681 make (unsafe) <literal>IntInf</literal> conversions into primitives
15682 </simpara>
15683 <itemizedlist>
15684 <listitem>
15685 <simpara>
15686 <ulink url="http://www.mlton.org/pipermail/mlton/2009-July/030622.html">http://www.mlton.org/pipermail/mlton/2009-July/030622.html</ulink>
15687 </simpara>
15688 </listitem>
15689 </itemizedlist>
15690 </listitem>
15691 </itemizedlist>
15692 <simpara><?asciidoc-pagebreak?></simpara>
15693 </section>
15694 <section id="mGTK">
15695 <title>mGTK</title>
15696 <simpara><ulink url="http://mgtk.sourceforge.net/">mGTK</ulink> is a wrapper for
15697 <ulink url="http://www.gtk.org/">GTK+</ulink>, a GUI toolkit.</simpara>
15698 <simpara>We recommend using mGTK 0.93, which is not listed on their home page,
15699 but is available at the
15700 <ulink url="http://sourceforge.net/project/showfiles.php?group_id=23226&amp;package_id=16523">file
15701 release page</ulink>. To test it, after unpacking, do <literal>cd examples; make
15702 mlton</literal>, after which you should be able to run the many examples
15703 (<literal>signup-mlton</literal>, <literal>listview-mlton</literal>, &#8230;).</simpara>
15704 <section id="_also_see_10">
15705 <title>Also see</title>
15706 <itemizedlist>
15707 <listitem>
15708 <simpara>
15709 <link linkend="Glade">Glade</link>
15710 </simpara>
15711 </listitem>
15712 </itemizedlist>
15713 <simpara><?asciidoc-pagebreak?></simpara>
15714 </section>
15715 </section>
15716 <section id="MichaelNorrish">
15717 <title>MichaelNorrish</title>
15718 <simpara>I am a researcher at <ulink url="http://nicta.com.au">NICTA</ulink>, with a web-page <ulink url="http://web.rsise.anu.edu.au/%7Emichaeln/">here</ulink>.</simpara>
15719 <simpara>I&#8217;m interested in MLton because of the chance that it might be a good vehicle for future implementations of the <ulink url="http://hol.sf.net">HOL</ulink> theorem-proving system. It&#8217;s beginning to look as if one route forward will be to embed an SML interpreter into a MLton-compiled executable. I don&#8217;t know if an extensible interpreter of the kind we&#8217;re looking for already exists.</simpara>
15720 <simpara><?asciidoc-pagebreak?></simpara>
15721 </section>
15722 <section id="MikeThomas">
15723 <title>MikeThomas</title>
15724 <simpara>Here is a picture at home in Brisbane, Queensland, Australia, taken in January 2004.</simpara>
15725 <informalfigure>
15726 <mediaobject>
15727 <imageobject>
15728 <imagedata fileref="MikeThomas.attachments/picture.jpg" align="center"/>
15729 </imageobject>
15730 <textobject><phrase>MikeThomas.attachments/picture.jpg</phrase></textobject>
15731 </mediaobject>
15732 </informalfigure>
15733 <simpara><?asciidoc-pagebreak?></simpara>
15734 </section>
15735 <section id="ML">
15736 <title>ML</title>
15737 <simpara>ML stands for <emphasis>meta language</emphasis>. ML was originally designed in the
15738 1970s as a programming language to assist theorem proving in the logic
15739 LCF. In the 1980s, ML split into two variants,
15740 <link linkend="StandardML">Standard ML</link> and <link linkend="OCaml">OCaml</link>, both of which are still used
15741 today.</simpara>
15742 <simpara><?asciidoc-pagebreak?></simpara>
15743 </section>
15744 <section id="MLAntlr">
15745 <title>MLAntlr</title>
15746 <simpara><ulink url="http://smlnj-gforge.cs.uchicago.edu/projects/ml-lpt/">MLAntlr</ulink> is a
15747 parser generator for <link linkend="StandardML">Standard ML</link>.</simpara>
15748 <section id="_also_see_11">
15749 <title>Also see</title>
15750 <itemizedlist>
15751 <listitem>
15752 <simpara>
15753 <link linkend="MLULex">MLULex</link>
15754 </simpara>
15755 </listitem>
15756 <listitem>
15757 <simpara>
15758 <link linkend="MLLPTLibrary">MLLPTLibrary</link>
15759 </simpara>
15760 </listitem>
15761 </itemizedlist>
15762 <simpara><?asciidoc-pagebreak?></simpara>
15763 </section>
15764 </section>
15765 <section id="MLBasis">
15766 <title>MLBasis</title>
15767 <simpara>The ML Basis system extends <link linkend="StandardML">Standard ML</link> to support
15768 programming-in-the-very-large, namespace management at the module
15769 level, separate delivery of library sources, and more. While Standard
15770 ML modules are a sophisticated language for programming-in-the-large,
15771 it is difficult, if not impossible, to accomplish a number of routine
15772 namespace management operations when a program draws upon multiple
15773 libraries provided by different vendors.</simpara>
15774 <simpara>The ML Basis system is a simple, yet powerful, approach that builds
15775 upon the programmer&#8217;s intuitive notion (and
15776 <link linkend="DefinitionOfStandardML">The Definition of Standard ML (Revised)</link>'s
15777 formal notion) of the top-level environment (a <emphasis>basis</emphasis>). The system
15778 is designed as a natural extension of <link linkend="StandardML">Standard ML</link>; the
15779 formal specification of the ML Basis system
15780 (<ulink url="guide/MLBasis.attachments/mlb-formal.pdf"><literal>mlb-formal.pdf</literal></ulink>) is given in the style
15781 of the Definition.</simpara>
15782 <simpara>Here are some of the key features of the ML Basis system:</simpara>
15783 <orderedlist numeration="arabic">
15784 <listitem>
15785 <simpara>
15786 Explicit file order: The order of files (and, hence, the order of
15787 evaluation) in the program is explicit. The ML Basis system&#8217;s
15788 semantics are structured in such a way that for any well-formed
15789 project, there will be exactly one possible interpretation of the
15790 project&#8217;s syntax, static semantics, and dynamic semantics.
15791 </simpara>
15792 </listitem>
15793 <listitem>
15794 <simpara>
15795 Implicit dependencies: A source file (corresponding to an SML
15796 top-level declaration) is elaborated in the environment described by
15797 preceding declarations. It is not necessary to explicitly list the
15798 dependencies of a file.
15799 </simpara>
15800 </listitem>
15801 <listitem>
15802 <simpara>
15803 Scoping and renaming: The ML Basis system provides mechanisms for
15804 limiting the scope of (i.e, hiding) and renaming identifiers.
15805 </simpara>
15806 </listitem>
15807 <listitem>
15808 <simpara>
15809 No naming convention for finding the file that defines a module.
15810 To import a module, its defining file must appear in some ML Basis
15811 file.
15812 </simpara>
15813 </listitem>
15814 </orderedlist>
15815 <section id="_next_steps_4">
15816 <title>Next steps</title>
15817 <itemizedlist>
15818 <listitem>
15819 <simpara>
15820 <link linkend="MLBasisSyntaxAndSemantics">MLBasisSyntaxAndSemantics</link>
15821 </simpara>
15822 </listitem>
15823 <listitem>
15824 <simpara>
15825 <link linkend="MLBasisExamples">MLBasisExamples</link>
15826 </simpara>
15827 </listitem>
15828 <listitem>
15829 <simpara>
15830 <link linkend="MLBasisPathMap">MLBasisPathMap</link>
15831 </simpara>
15832 </listitem>
15833 <listitem>
15834 <simpara>
15835 <link linkend="MLBasisAnnotations">MLBasisAnnotations</link>
15836 </simpara>
15837 </listitem>
15838 <listitem>
15839 <simpara>
15840 <link linkend="MLBasisAvailableLibraries">MLBasisAvailableLibraries</link>
15841 </simpara>
15842 </listitem>
15843 </itemizedlist>
15844 <simpara><?asciidoc-pagebreak?></simpara>
15845 </section>
15846 </section>
15847 <section id="MLBasisAnnotationExamples">
15848 <title>MLBasisAnnotationExamples</title>
15849 <simpara>Here are some example uses of <link linkend="MLBasisAnnotations">MLBasisAnnotations</link>.</simpara>
15850 <section id="_eliminate_spurious_warnings_in_automatically_generated_code">
15851 <title>Eliminate spurious warnings in automatically generated code</title>
15852 <simpara>Programs that automatically generate source code can often produce
15853 nonexhaustive patterns, relying on invariants of the generated code to
15854 ensure that the pattern matchings never fail. A programmer may wish
15855 to elide the nonexhaustive warnings from this code, in order that
15856 legitimate warnings are not missed in a flurry of false positives. To
15857 do so, the programmer simply annotates the generated code with the
15858 <literal>nonexhaustiveBind ignore</literal> and <literal>nonexhaustiveMatch ignore</literal>
15859 annotations:</simpara>
15860 <screen>local
15861 $(GEN_ROOT)/gen-lib.mlb
15862
15863 ann
15864 "nonexhaustiveBind ignore"
15865 "nonexhaustiveMatch ignore"
15866 in
15867 foo.gen.sml
15868 end
15869 in
15870 signature FOO
15871 structure Foo
15872 end</screen>
15873 </section>
15874 <section id="_deliver_a_library">
15875 <title>Deliver a library</title>
15876 <simpara>Standard ML libraries can be delivered via <literal>.mlb</literal> files. Authors of
15877 such libraries should strive to be mindful of the ways in which
15878 programmers may choose to compile their programs. For example,
15879 although the defaults for <literal>sequenceNonUnit</literal> and <literal>warnUnused</literal> are
15880 <literal>ignore</literal> and <literal>false</literal>, periodically compiling with these annotations
15881 defaulted to <literal>warn</literal> and <literal>true</literal> can help uncover likely bugs. However,
15882 a programmer is unlikely to be interested in unused modules from an
15883 imported library, and the behavior of <literal>sequenceNonUnit error</literal> may be
15884 incompatible with some libraries. Hence, a library author may choose
15885 to deliver a library as follows:</simpara>
15886 <screen>ann
15887 "nonexhaustiveBind warn" "nonexhaustiveMatch warn"
15888 "redundantBind warn" "redundantMatch warn"
15889 "sequenceNonUnit warn"
15890 "warnUnused true" "forceUsed"
15891 in
15892 local
15893 file1.sml
15894 ...
15895 filen.sml
15896 in
15897 functor F1
15898 ...
15899 signature S1
15900 ...
15901 structure SN
15902 ...
15903 end
15904 end</screen>
15905 <simpara>The annotations <literal>nonexhaustiveBind warn</literal>, <literal>redundantBind warn</literal>,
15906 <literal>nonexhaustiveMatch warn</literal>, <literal>redundantMatch warn</literal>, and <literal>sequenceNonUnit
15907 warn</literal> have the obvious effect on elaboration. The annotations
15908 <literal>warnUnused true</literal> and <literal>forceUsed</literal> work in conjunction&#8201;&#8212;&#8201;warning on
15909 any identifiers that do not contribute to the exported modules, and
15910 preventing warnings on exported modules that are not used in the
15911 remainder of the program. Many of the
15912 <link linkend="MLBasisAvailableLibraries">available libraries</link> are delivered with
15913 these annotations.</simpara>
15914 <simpara><?asciidoc-pagebreak?></simpara>
15915 </section>
15916 </section>
15917 <section id="MLBasisAnnotations">
15918 <title>MLBasisAnnotations</title>
15919 <simpara><link linkend="MLBasis">ML Basis</link> annotations control options that affect the
15920 elaboration of SML source files. Conceptually, a basis file is
15921 elaborated in a default annotation environment (just as it is
15922 elaborated in an empty basis). The declaration
15923 <literal>ann</literal>&#160;<literal>"</literal><emphasis>ann</emphasis><literal>"</literal>&#160;<literal>in</literal>&#160;<emphasis>basdec</emphasis>&#160;<literal>end</literal>
15924 merges the annotation <emphasis>ann</emphasis> with the "current" annotation environment
15925 for the elaboration of <emphasis>basdec</emphasis>. To allow for future expansion,
15926 <literal>"</literal><emphasis>ann</emphasis><literal>"</literal> is lexed as a single SML string constant. To
15927 conveniently specify multiple annotations, the following derived form
15928 is provided:</simpara>
15929 <sidebar>
15930 <simpara><literal>ann</literal> <literal>"</literal><emphasis>ann</emphasis><literal>"</literal> (<literal>"</literal><emphasis>ann</emphasis><literal>"</literal> )<superscript>+</superscript> <literal>in</literal> <emphasis>basdec</emphasis> <literal>end</literal>
15931 &#8658;
15932 <literal>ann</literal> <literal>"</literal><emphasis>ann</emphasis><literal>"</literal> <literal>in</literal> <literal>ann</literal> (<literal>"</literal><emphasis>ann</emphasis><literal>"</literal>)<superscript>+</superscript> <literal>in</literal> <emphasis>basdec</emphasis> <literal>end</literal> <literal>end</literal></simpara>
15933 </sidebar>
15934 <simpara>Here are the available annotations. In the explanation below, for
15935 annotations that take an argument, the first value listed is the
15936 default.</simpara>
15937 <itemizedlist>
15938 <listitem>
15939 <simpara>
15940 <literal>allowFFI {false|true}</literal>
15941 </simpara>
15942 <simpara>If <literal>true</literal>, allow <literal>_address</literal>, <literal>_export</literal>, <literal>_import</literal>, and <literal>_symbol</literal>
15943 expressions to appear in source files. See
15944 <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link>.</simpara>
15945 </listitem>
15946 <listitem>
15947 <simpara>
15948 <literal>allowSuccessorML {false|true}</literal>
15949 </simpara>
15950 <simpara>Allow or disallow all of the <link linkend="SuccessorML">SuccessorML</link> features. This is a
15951 proxy for all of the following annotations.</simpara>
15952 <itemizedlist>
15953 <listitem>
15954 <simpara>
15955 <literal>allowDoDecls {false|true}</literal>
15956 </simpara>
15957 <simpara>If <literal>true</literal>, allow a <literal>do <emphasis>exp</emphasis></literal> declaration form.</simpara>
15958 </listitem>
15959 <listitem>
15960 <simpara>
15961 <literal>allowExtendedConsts {false|true}</literal>
15962 </simpara>
15963 <simpara>Allow or disallow all of the extended constants features. This is a
15964 proxy for all of the following annotations.</simpara>
15965 <itemizedlist>
15966 <listitem>
15967 <simpara>
15968 <literal>allowExtendedNumConsts {false|true}</literal>
15969 </simpara>
15970 <simpara>If <literal>true</literal>, allow extended numeric constants.</simpara>
15971 </listitem>
15972 <listitem>
15973 <simpara>
15974 <literal>allowExtendedTextConsts {false|true}</literal>
15975 </simpara>
15976 <simpara>If <literal>true</literal>, allow extended text constants.</simpara>
15977 </listitem>
15978 </itemizedlist>
15979 </listitem>
15980 <listitem>
15981 <simpara>
15982 <literal>allowLineComments {false|true}</literal>
15983 </simpara>
15984 <simpara>If <literal>true</literal>, allow line comments beginning with the token <literal>(*)</literal>.</simpara>
15985 </listitem>
15986 <listitem>
15987 <simpara>
15988 <literal>allowOptBar {false|true}</literal>
15989 </simpara>
15990 <simpara>If <literal>true</literal>, allow a bar to appear before the first match rule of a
15991 <literal>case</literal>, <literal>fn</literal>, or <literal>handle</literal> expression, allow a bar to appear before the
15992 first function-value binding of a <literal>fun</literal> declaration, and allow a bar
15993 to appear before the first constructor binding or description of a
15994 <literal>datatype</literal> declaration or specification.</simpara>
15995 </listitem>
15996 <listitem>
15997 <simpara>
15998 <literal>allowOptSemicolon {false|true}</literal>
15999 </simpara>
16000 <simpara>If <literal>true</literal>, allows a semicolon to appear after the last expression in a
16001 sequence expression or <literal>let</literal> body.</simpara>
16002 </listitem>
16003 <listitem>
16004 <simpara>
16005 <literal>allowOrPats {false|true}</literal>
16006 </simpara>
16007 <simpara>If <literal>true</literal>, allows disjunctive (a.k.a., "or") patterns of the form
16008 <literal><emphasis>pat</emphasis> | <emphasis>pat</emphasis></literal>.</simpara>
16009 </listitem>
16010 <listitem>
16011 <simpara>
16012 <literal>allowRecordPunExps {false|true}</literal>
16013 </simpara>
16014 <simpara>If <literal>true</literal>, allows record punning expressions.</simpara>
16015 </listitem>
16016 <listitem>
16017 <simpara>
16018 <literal>allowSigWithtype {false|true}</literal>
16019 </simpara>
16020 <simpara>If <literal>true</literal>, allows <literal>withtype</literal> to modify a <literal>datatype</literal> specification in a
16021 signature.</simpara>
16022 </listitem>
16023 <listitem>
16024 <simpara>
16025 <literal>allowVectorExpsAndPats {false|true}</literal>
16026 </simpara>
16027 <simpara>Allow or disallow vector expressions and vector patterns. This is a
16028 proxy for all of the following annotations.</simpara>
16029 <itemizedlist>
16030 <listitem>
16031 <simpara>
16032 <literal>allowVectorExps {false|true}</literal>
16033 </simpara>
16034 <simpara>If <literal>true</literal>, allow vector expressions.</simpara>
16035 </listitem>
16036 <listitem>
16037 <simpara>
16038 <literal>allowVectorPats {false|true}</literal>
16039 </simpara>
16040 <simpara>If <literal>true</literal>, allow vector patterns.</simpara>
16041 </listitem>
16042 </itemizedlist>
16043 </listitem>
16044 </itemizedlist>
16045 </listitem>
16046 <listitem>
16047 <simpara>
16048 <literal>forceUsed</literal>
16049 </simpara>
16050 <simpara>Force all identifiers in the basis denoted by the body of the <literal>ann</literal> to
16051 be considered used; use in conjunction with <literal>warnUnused true</literal>.</simpara>
16052 </listitem>
16053 <listitem>
16054 <simpara>
16055 <literal>nonexhaustiveBind {warn|error|ignore}</literal>
16056 </simpara>
16057 <simpara>If <literal>error</literal> or <literal>warn</literal>, report nonexhaustive patterns in <literal>val</literal>
16058 declarations (i.e., pattern-match failures that raise the <literal>Bind</literal>
16059 exception). An error will abort a compile, while a warning will not.</simpara>
16060 </listitem>
16061 <listitem>
16062 <simpara>
16063 <literal>nonexhaustiveExnBind {default|ignore}</literal>
16064 </simpara>
16065 <simpara>If <literal>ignore</literal>, suppress errors and warnings about nonexhaustive matches
16066 in <literal>val</literal> declarations that arise solely from unmatched exceptions.
16067 If <literal>default</literal>, follow the behavior of <literal>nonexhaustiveBind</literal>.</simpara>
16068 </listitem>
16069 <listitem>
16070 <simpara>
16071 <literal>nonexhaustiveExnMatch {default|ignore}</literal>
16072 </simpara>
16073 <simpara>If <literal>ignore</literal>, suppress errors and warnings about nonexhaustive matches
16074 in <literal>fn</literal> expressions, <literal>case</literal> expressions, and <literal>fun</literal> declarations that
16075 arise solely from unmatched exceptions. If <literal>default</literal>, follow the
16076 behavior of <literal>nonexhaustiveMatch</literal>.</simpara>
16077 </listitem>
16078 <listitem>
16079 <simpara>
16080 <literal>nonexhaustiveExnRaise {ignore|default}</literal>
16081 </simpara>
16082 <simpara>If <literal>ignore</literal>, suppress errors and warnings about nonexhaustive matches
16083 in <literal>handle</literal> expressions that arise solely from unmatched exceptions.
16084 If <literal>default</literal>, follow the behavior of <literal>nonexhaustiveRaise</literal>.</simpara>
16085 </listitem>
16086 <listitem>
16087 <simpara>
16088 <literal>nonexhaustiveMatch {warn|error|ignore}</literal>
16089 </simpara>
16090 <simpara>If <literal>error</literal> or <literal>warn</literal>, report nonexhaustive patterns in <literal>fn</literal>
16091 expressions, <literal>case</literal> expressions, and <literal>fun</literal> declarations (i.e.,
16092 pattern-match failures that raise the <literal>Match</literal> exception). An error
16093 will abort a compile, while a warning will not.</simpara>
16094 </listitem>
16095 <listitem>
16096 <simpara>
16097 <literal>nonexhaustiveRaise {ignore|warn|error}</literal>
16098 </simpara>
16099 <simpara>If <literal>error</literal> or <literal>warn</literal>, report nonexhaustive patterns in <literal>handle</literal>
16100 expressions (i.e., pattern-match failures that implicitly (re)raise
16101 the unmatched exception). An error will abort a compile, while a
16102 warning will not.</simpara>
16103 </listitem>
16104 <listitem>
16105 <simpara>
16106 <literal>redundantBind {warn|error|ignore}</literal>
16107 </simpara>
16108 <simpara>If <literal>error</literal> or <literal>warn</literal>, report redundant patterns in <literal>val</literal> declarations.
16109 An error will abort a compile, while a warning will not.</simpara>
16110 </listitem>
16111 <listitem>
16112 <simpara>
16113 <literal>redundantMatch {warn|error|ignore}</literal>
16114 </simpara>
16115 <simpara>If <literal>error</literal> or <literal>warn</literal>, report redundant patterns in <literal>fn</literal> expressions,
16116 <literal>case</literal> expressions, and <literal>fun</literal> declarations. An error will abort a
16117 compile, while a warning will not.</simpara>
16118 </listitem>
16119 <listitem>
16120 <simpara>
16121 <literal>redundantRaise {warn|error|ignore}</literal>
16122 </simpara>
16123 <simpara>If <literal>error</literal> or <literal>warn</literal>, report redundant patterns in <literal>handle</literal>
16124 expressions. An error will abort a compile, while a warning will not.</simpara>
16125 </listitem>
16126 <listitem>
16127 <simpara>
16128 <literal>resolveScope {strdec|dec|topdec|program}</literal>
16129 </simpara>
16130 <simpara>Used to control the scope at which overload constraints are resolved
16131 to default types (if not otherwise resolved by type inference) and the
16132 scope at which unresolved flexible record constraints are reported.</simpara>
16133 <simpara>The syntactic-class argument means to perform resolution checks at the
16134 smallest enclosing syntactic form of the given class. The default
16135 behavior is to resolve at the smallest enclosing <emphasis>strdec</emphasis> (which is
16136 equivalent to the largest enclosing <emphasis>dec</emphasis>). Other useful behaviors
16137 are to resolve at the smallest enclosing <emphasis>topdec</emphasis> (which is equivalent
16138 to the largest enclosing <emphasis>strdec</emphasis>) and at the smallest enclosing
16139 <emphasis>program</emphasis> (which corresponds to a single <literal>.sml</literal> file and does not
16140 correspond to the whole <literal>.mlb</literal> program).</simpara>
16141 </listitem>
16142 <listitem>
16143 <simpara>
16144 <literal>sequenceNonUnit {ignore|error|warn}</literal>
16145 </simpara>
16146 <simpara>If <literal>error</literal> or <literal>warn</literal>, report when <literal>e1</literal> is not of type <literal>unit</literal> in the
16147 sequence expression <literal>(e1; e2)</literal>. This can be helpful in detecting
16148 curried applications that are mistakenly not fully applied. To
16149 silence spurious messages, you can use <literal>ignore e1</literal>.</simpara>
16150 </listitem>
16151 <listitem>
16152 <simpara>
16153 <literal>valrecConstr {warn|error|ignore}</literal>
16154 </simpara>
16155 <simpara>If <literal>error</literal> or <literal>warn</literal>, report when a <literal>val rec</literal> (or <literal>fun</literal>) declaration
16156 redefines an identifier that previously had constructor status. An
16157 error will abort a compile, while a warning will not.</simpara>
16158 </listitem>
16159 <listitem>
16160 <simpara>
16161 <literal>warnUnused {false|true}</literal>
16162 </simpara>
16163 <simpara>Report unused identifiers.</simpara>
16164 </listitem>
16165 </itemizedlist>
16166 <section id="_next_steps_5">
16167 <title>Next Steps</title>
16168 <itemizedlist>
16169 <listitem>
16170 <simpara>
16171 <link linkend="MLBasisAnnotationExamples">MLBasisAnnotationExamples</link>
16172 </simpara>
16173 </listitem>
16174 <listitem>
16175 <simpara>
16176 <link linkend="WarnUnusedAnomalies">WarnUnusedAnomalies</link>
16177 </simpara>
16178 </listitem>
16179 </itemizedlist>
16180 <simpara><?asciidoc-pagebreak?></simpara>
16181 </section>
16182 </section>
16183 <section id="MLBasisAvailableLibraries">
16184 <title>MLBasisAvailableLibraries</title>
16185 <simpara>MLton comes with the following <link linkend="MLBasis">ML Basis</link> files available.</simpara>
16186 <itemizedlist>
16187 <listitem>
16188 <simpara>
16189 <literal>$(SML_LIB)/basis/basis.mlb</literal>
16190 </simpara>
16191 <simpara>The <link linkend="BasisLibrary">Basis Library</link>.</simpara>
16192 </listitem>
16193 <listitem>
16194 <simpara>
16195 <literal>$(SML_LIB)/basis/basis-1997.mlb</literal>
16196 </simpara>
16197 <simpara>The (deprecated) 1997 version of the <link linkend="BasisLibrary">Basis Library</link>.</simpara>
16198 </listitem>
16199 <listitem>
16200 <simpara>
16201 <literal>$(SML_LIB)/basis/mlton.mlb</literal>
16202 </simpara>
16203 <simpara>The <link linkend="MLtonStructure">MLton</link> structure and signatures.</simpara>
16204 </listitem>
16205 <listitem>
16206 <simpara>
16207 <literal>$(SML_LIB)/basis/c-types.mlb</literal>
16208 </simpara>
16209 <simpara>Various structure aliases useful as <link linkend="ForeignFunctionInterfaceTypes">ForeignFunctionInterfaceTypes</link>.</simpara>
16210 </listitem>
16211 <listitem>
16212 <simpara>
16213 <literal>$(SML_LIB)/basis/unsafe.mlb</literal>
16214 </simpara>
16215 <simpara>The <link linkend="UnsafeStructure">Unsafe</link> structure and signature.</simpara>
16216 </listitem>
16217 <listitem>
16218 <simpara>
16219 <literal>$(SML_LIB)/basis/sml-nj.mlb</literal>
16220 </simpara>
16221 <simpara>The <link linkend="SMLofNJStructure">SMLofNJ</link> structure and signature.</simpara>
16222 </listitem>
16223 <listitem>
16224 <simpara>
16225 <literal>$(SML_LIB)/mlyacc-lib/mlyacc-lib.mlb</literal>
16226 </simpara>
16227 <simpara>Modules used by parsers built with <link linkend="MLYacc">MLYacc</link>.</simpara>
16228 </listitem>
16229 <listitem>
16230 <simpara>
16231 <literal>$(SML_LIB)/cml/cml.mlb</literal>
16232 </simpara>
16233 <simpara><link linkend="ConcurrentML">ConcurrentML</link>, a library for message-passing concurrency.</simpara>
16234 </listitem>
16235 <listitem>
16236 <simpara>
16237 <literal>$(SML_LIB)/mlnlffi-lib/mlnlffi-lib.mlb</literal>
16238 </simpara>
16239 <simpara><link linkend="MLNLFFI">ML-NLFFI</link>, a library for foreign function interfaces.</simpara>
16240 </listitem>
16241 <listitem>
16242 <simpara>
16243 <literal>$(SML_LIB)/mlrisc-lib/...</literal>
16244 </simpara>
16245 <simpara><link linkend="MLRISCLibrary">MLRISCLibrary</link>, a library for retargetable and optimizing compiler back ends.</simpara>
16246 </listitem>
16247 <listitem>
16248 <simpara>
16249 <literal>$(SML_LIB)/smlnj-lib/...</literal>
16250 </simpara>
16251 <simpara><link linkend="SMLNJLibrary">SMLNJLibrary</link>, a collection of libraries distributed with SML/NJ.</simpara>
16252 </listitem>
16253 <listitem>
16254 <simpara>
16255 <literal>$(SML_LIB)/ckit-lib/ckit-lib.mlb</literal>
16256 </simpara>
16257 <simpara><link linkend="CKitLibrary">CKitLibrary</link>, a library for C source code.</simpara>
16258 </listitem>
16259 <listitem>
16260 <simpara>
16261 <literal>$(SML_LIB)/mllpt-lib/mllpt-lib.mlb</literal>
16262 </simpara>
16263 <simpara><link linkend="MLLPTLibrary">MLLPTLibrary</link>, a support library for the <link linkend="MLULex">MLULex</link> scanner generator and the <link linkend="MLAntlr">MLAntlr</link> parser generator.</simpara>
16264 </listitem>
16265 </itemizedlist>
16266 <section id="_basis_fragments">
16267 <title>Basis fragments</title>
16268 <simpara>There are a number of specialized ML Basis files for importing
16269 fragments of the <link linkend="BasisLibrary">Basis Library</link> that can not be
16270 expressed within SML.</simpara>
16271 <itemizedlist>
16272 <listitem>
16273 <simpara>
16274 <literal>$(SML_LIB)/basis/pervasive-types.mlb</literal>
16275 </simpara>
16276 <simpara>The top-level types and constructors of the Basis Library.</simpara>
16277 </listitem>
16278 <listitem>
16279 <simpara>
16280 <literal>$(SML_LIB)/basis/pervasive-exns.mlb</literal>
16281 </simpara>
16282 <simpara>The top-level exception constructors of the Basis Library.</simpara>
16283 </listitem>
16284 <listitem>
16285 <simpara>
16286 <literal>$(SML_LIB)/basis/pervasive-vals.mlb</literal>
16287 </simpara>
16288 <simpara>The top-level values of the Basis Library, without infix status.</simpara>
16289 </listitem>
16290 <listitem>
16291 <simpara>
16292 <literal>$(SML_LIB)/basis/overloads.mlb</literal>
16293 </simpara>
16294 <simpara>The top-level overloaded values of the Basis Library, without infix status.</simpara>
16295 </listitem>
16296 <listitem>
16297 <simpara>
16298 <literal>$(SML_LIB)/basis/equal.mlb</literal>
16299 </simpara>
16300 <simpara>The polymorphic equality <literal>=</literal> and inequality <literal>&lt;&gt;</literal> values, without infix status.</simpara>
16301 </listitem>
16302 <listitem>
16303 <simpara>
16304 <literal>$(SML_LIB)/basis/infixes.mlb</literal>
16305 </simpara>
16306 <simpara>The infix declarations of the Basis Library.</simpara>
16307 </listitem>
16308 <listitem>
16309 <simpara>
16310 <literal>$(SML_LIB)/basis/pervasive.mlb</literal>
16311 </simpara>
16312 <simpara>The entire top-level value and type environment of the Basis Library, with infix status. This is the same as importing the above six MLB files.</simpara>
16313 </listitem>
16314 </itemizedlist>
16315 <simpara><?asciidoc-pagebreak?></simpara>
16316 </section>
16317 </section>
16318 <section id="MLBasisExamples">
16319 <title>MLBasisExamples</title>
16320 <simpara>Here are some example uses of <link linkend="MLBasis">ML Basis</link> files.</simpara>
16321 <section id="_complete_program">
16322 <title>Complete program</title>
16323 <simpara>Suppose your complete program consists of the files <literal>file1.sml</literal>, &#8230;,
16324 <literal>filen.sml</literal>, which depend upon libraries <literal>lib1.mlb</literal>, &#8230;, <literal>libm.mlb</literal>.</simpara>
16325 <screen>(* import libraries *)
16326 lib1.mlb
16327 ...
16328 libm.mlb
16329
16330 (* program files *)
16331 file1.sml
16332 ...
16333 filen.sml</screen>
16334 <simpara>The bases denoted by <literal>lib1.mlb</literal>, &#8230;, <literal>libm.mlb</literal> are merged (bindings
16335 of names in later bases take precedence over bindings of the same name
16336 in earlier bases), producing a basis in which <literal>file1.sml</literal>, &#8230;,
16337 <literal>filen.sml</literal> are elaborated, adding additional bindings to the basis.</simpara>
16338 </section>
16339 <section id="_export_filter">
16340 <title>Export filter</title>
16341 <simpara>Suppose you only want to export certain structures, signatures, and
16342 functors from a collection of files.</simpara>
16343 <screen>local
16344 file1.sml
16345 ...
16346 filen.sml
16347 in
16348 (* export filter here *)
16349 functor F
16350 structure S
16351 end</screen>
16352 <simpara>While <literal>file1.sml</literal>, &#8230;, <literal>filen.sml</literal> may declare top-level identifiers
16353 in addition to <literal>F</literal> and <literal>S</literal>, such names are not accessible to programs
16354 and libraries that import this <literal>.mlb</literal>.</simpara>
16355 </section>
16356 <section id="_export_filter_with_renaming">
16357 <title>Export filter with renaming</title>
16358 <simpara>Suppose you want an export filter, but want to rename one of the
16359 modules.</simpara>
16360 <screen>local
16361 file1.sml
16362 ...
16363 filen.sml
16364 in
16365 (* export filter, with renaming, here *)
16366 functor F
16367 structure S' = S
16368 end</screen>
16369 <simpara>Note that <literal>functor F</literal> is an abbreviation for <literal>functor F = F</literal>, which
16370 simply exports an identifier under the same name.</simpara>
16371 </section>
16372 <section id="_import_filter">
16373 <title>Import filter</title>
16374 <simpara>Suppose you only want to import a functor <literal>F</literal> from one library and a
16375 structure <literal>S</literal> from another library.</simpara>
16376 <screen>local
16377 lib1.mlb
16378 in
16379 (* import filter here *)
16380 functor F
16381 end
16382 local
16383 lib2.mlb
16384 in
16385 (* import filter here *)
16386 structure S
16387 end
16388 file1.sml
16389 ...
16390 filen.sml</screen>
16391 </section>
16392 <section id="_import_filter_with_renaming">
16393 <title>Import filter with renaming</title>
16394 <simpara>Suppose you want to import a structure <literal>S</literal> from one library and
16395 another structure <literal>S</literal> from another library.</simpara>
16396 <screen>local
16397 lib1.mlb
16398 in
16399 (* import filter, with renaming, here *)
16400 structure S1 = S
16401 end
16402 local
16403 lib2.mlb
16404 in
16405 (* import filter, with renaming, here *)
16406 structure S2 = S
16407 end
16408 file1.sml
16409 ...
16410 filen.sml</screen>
16411 </section>
16412 <section id="_full_basis">
16413 <title>Full Basis</title>
16414 <simpara>Since the Modules level of SML is the natural means for organizing
16415 program and library components, MLB files provide convenient syntax
16416 for renaming Modules level identifiers (in fact, renaming of functor
16417 identifiers provides a mechanism that is not available in SML).
16418 However, please note that <literal>.mlb</literal> files elaborate to full bases
16419 including top-level types and values (including infix status), in
16420 addition to structures, signatures, and functors. For example,
16421 suppose you wished to extend the <link linkend="BasisLibrary">Basis Library</link> with an
16422 <literal>('a, 'b) either</literal> datatype corresponding to a disjoint sum; the type
16423 and some operations should be available at the top-level;
16424 additionally, a signature and structure provide the complete
16425 interface.</simpara>
16426 <simpara>We could use the following files.</simpara>
16427 <simpara><literal>either-sigs.sml</literal></simpara>
16428 <programlisting language="sml" linenumbering="unnumbered">signature EITHER_GLOBAL =
16429 sig
16430 datatype ('a, 'b) either = Left of 'a | Right of 'b
16431 val &amp; : ('a -&gt; 'c) * ('b -&gt; 'c) -&gt; ('a, 'b) either -&gt; 'c
16432 val &amp;&amp; : ('a -&gt; 'c) * ('b -&gt; 'd) -&gt; ('a, 'b) either -&gt; ('c, 'd) either
16433 end
16434
16435 signature EITHER =
16436 sig
16437 include EITHER_GLOBAL
16438 val isLeft : ('a, 'b) either -&gt; bool
16439 val isRight : ('a, 'b) either -&gt; bool
16440 ...
16441 end</programlisting>
16442 <simpara><literal>either-strs.sml</literal></simpara>
16443 <programlisting language="sml" linenumbering="unnumbered">structure Either : EITHER =
16444 struct
16445 datatype ('a, 'b) either = Left of 'a | Right of 'b
16446 fun f &amp; g = fn x =&gt;
16447 case x of Left z =&gt; f z | Right z =&gt; g z
16448 fun f &amp;&amp; g = (Left o f) &amp; (Right o g)
16449 fun isLeft x = ((fn _ =&gt; true) &amp; (fn _ =&gt; false)) x
16450 fun isRight x = (not o isLeft) x
16451 ...
16452 end
16453 structure EitherGlobal : EITHER_GLOBAL = Either</programlisting>
16454 <simpara><literal>either-infixes.sml</literal></simpara>
16455 <programlisting language="sml" linenumbering="unnumbered">infixr 3 &amp; &amp;&amp;</programlisting>
16456 <simpara><literal>either-open.sml</literal></simpara>
16457 <programlisting language="sml" linenumbering="unnumbered">open EitherGlobal</programlisting>
16458 <simpara><literal>either.mlb</literal></simpara>
16459 <screen>either-infixes.sml
16460 local
16461 (* import Basis Library *)
16462 $(SML_LIB)/basis/basis.mlb
16463 either-sigs.sml
16464 either-strs.sml
16465 in
16466 signature EITHER
16467 structure Either
16468 either-open.sml
16469 end</screen>
16470 <simpara>A client that imports <literal>either.mlb</literal> will have access to neither
16471 <literal>EITHER_GLOBAL</literal> nor <literal>EitherGlobal</literal>, but will have access to the type
16472 <literal>either</literal> and the values <literal>&amp;</literal> and <literal>&amp;&amp;</literal> (with infix status) in the
16473 top-level environment. Note that <literal>either-infixes.sml</literal> is outside the
16474 scope of the local, because we want the infixes available in the
16475 implementation of the library and to clients of the library.</simpara>
16476 <simpara><?asciidoc-pagebreak?></simpara>
16477 </section>
16478 </section>
16479 <section id="MLBasisPathMap">
16480 <title>MLBasisPathMap</title>
16481 <simpara>An <link linkend="MLBasis">ML Basis</link> <emphasis>path map</emphasis> describes a map from ML Basis path
16482 variables (of the form <literal>$(VAR)</literal>) to file system paths. ML Basis path
16483 variables provide a flexible way to refer to libraries while allowing
16484 them to be moved without changing their clients.</simpara>
16485 <simpara>The format of an <literal>mlb-path-map</literal> file is a sequence of lines; each line
16486 consists of two, white-space delimited tokens. The first token is a
16487 path variable <literal>VAR</literal> and the second token is the path to which the
16488 variable is mapped. The path may include path variables, which are
16489 recursively expanded.</simpara>
16490 <simpara>The mapping from path variables to paths is initialized by the compiler.
16491 Additional path maps can be specified with <literal>-mlb-path-map</literal> and
16492 individual path variable mappings can be specified with
16493 <literal>-mlb-path-var</literal> (see <link linkend="CompileTimeOptions">CompileTimeOptions</link>). Configuration files are
16494 processed from first to last and from top to bottom, later mappings
16495 take precedence over earlier mappings.</simpara>
16496 <simpara>The compiler and system-wide configuration file makes the following
16497 path variables available.</simpara>
16498 <informaltable
16499 frame="all"
16500 rowsep="1" colsep="1"
16501 >
16502 <tgroup cols="2">
16503 <colspec colname="col_1" colwidth="25*"/>
16504 <colspec colname="col_2" colwidth="75*"/>
16505 <thead>
16506 <row>
16507 <entry align="center" valign="top">MLB path variable</entry>
16508 <entry align="left" valign="top">Description</entry>
16509 </row>
16510 </thead>
16511 <tbody>
16512 <row>
16513 <entry align="center" valign="top"><simpara><literal>SML_LIB</literal></simpara></entry>
16514 <entry align="left" valign="top"><simpara>path to system-wide libraries, usually <literal>/usr/lib/mlton/sml</literal></simpara></entry>
16515 </row>
16516 <row>
16517 <entry align="center" valign="top"><simpara><literal>TARGET_ARCH</literal></simpara></entry>
16518 <entry align="left" valign="top"><simpara>string representation of target architecture</simpara></entry>
16519 </row>
16520 <row>
16521 <entry align="center" valign="top"><simpara><literal>TARGET_OS</literal></simpara></entry>
16522 <entry align="left" valign="top"><simpara>string representation of target operating system</simpara></entry>
16523 </row>
16524 <row>
16525 <entry align="center" valign="top"><simpara><literal>DEFAULT_INT</literal></simpara></entry>
16526 <entry align="left" valign="top"><simpara>binding for default int, usually <literal>int32</literal></simpara></entry>
16527 </row>
16528 <row>
16529 <entry align="center" valign="top"><simpara><literal>DEFAULT_WORD</literal></simpara></entry>
16530 <entry align="left" valign="top"><simpara>binding for default word, usually <literal>word32</literal></simpara></entry>
16531 </row>
16532 <row>
16533 <entry align="center" valign="top"><simpara><literal>DEFAULT_REAL</literal></simpara></entry>
16534 <entry align="left" valign="top"><simpara>binding for default real, usually <literal>real64</literal></simpara></entry>
16535 </row>
16536 </tbody>
16537 </tgroup>
16538 </informaltable>
16539 <simpara><?asciidoc-pagebreak?></simpara>
16540 </section>
16541 <section id="MLBasisSyntaxAndSemantics">
16542 <title>MLBasisSyntaxAndSemantics</title>
16543 <simpara>An <link linkend="MLBasis">ML Basis</link> (MLB) file should have the <literal>.mlb</literal> suffix and
16544 should contain a basis declaration.</simpara>
16545 <section id="_syntax">
16546 <title>Syntax</title>
16547 <simpara>A basis declaration (<emphasis>basdec</emphasis>) must be one of the following forms.</simpara>
16548 <itemizedlist>
16549 <listitem>
16550 <simpara>
16551 <literal>basis</literal> <emphasis>basid</emphasis> <literal>=</literal> <emphasis>basexp</emphasis> (<literal>and</literal> <emphasis>basid</emphasis> <literal>=</literal> <emphasis>basexp</emphasis>)<superscript>*</superscript>
16552 </simpara>
16553 </listitem>
16554 <listitem>
16555 <simpara>
16556 <literal>open</literal> <emphasis>basid<subscript>1</subscript></emphasis> &#8230; <emphasis>basid<subscript>n</subscript></emphasis>
16557 </simpara>
16558 </listitem>
16559 <listitem>
16560 <simpara>
16561 <literal>local</literal> <emphasis>basdec</emphasis> <literal>in</literal> <emphasis>basdec</emphasis> <literal>end</literal>
16562 </simpara>
16563 </listitem>
16564 <listitem>
16565 <simpara>
16566 <emphasis>basdec</emphasis> [<literal>;</literal>] <emphasis>basdec</emphasis>
16567 </simpara>
16568 </listitem>
16569 <listitem>
16570 <simpara>
16571 <literal>structure</literal> <emphasis>strid</emphasis> [<literal>=</literal> <emphasis>strid</emphasis>] (<literal>and</literal> <emphasis>strid</emphasis>[<literal>=</literal> <emphasis>strid</emphasis>])<superscript>*</superscript>
16572 </simpara>
16573 </listitem>
16574 <listitem>
16575 <simpara>
16576 <literal>signature</literal> <emphasis>sigid</emphasis> [<literal>=</literal> <emphasis>sigid</emphasis>] (<literal>and</literal> <emphasis>sigid</emphasis> [<literal>=</literal> <emphasis>sigid</emphasis>])<superscript>*</superscript>
16577 </simpara>
16578 </listitem>
16579 <listitem>
16580 <simpara>
16581 <literal>functor</literal> <emphasis>funid</emphasis> [<literal>=</literal> <emphasis>funid</emphasis>] (<literal>and</literal> <emphasis>funid</emphasis> [<literal>=</literal> <emphasis>funid</emphasis>])<superscript>*</superscript>
16582 </simpara>
16583 </listitem>
16584 <listitem>
16585 <simpara>
16586 <emphasis>path</emphasis><literal>.sml</literal>, <emphasis>path</emphasis><literal>.sig</literal>, or <emphasis>path</emphasis><literal>.fun</literal>
16587 </simpara>
16588 </listitem>
16589 <listitem>
16590 <simpara>
16591 <emphasis>path</emphasis><literal>.mlb</literal>
16592 </simpara>
16593 </listitem>
16594 <listitem>
16595 <simpara>
16596 <literal>ann</literal> <literal>"</literal><emphasis>ann</emphasis><literal>"</literal> <literal>in</literal> <emphasis>basdec</emphasis> <literal>end</literal>
16597 </simpara>
16598 </listitem>
16599 </itemizedlist>
16600 <simpara>A basis expression (<emphasis>basexp</emphasis>) must be of one the following forms.</simpara>
16601 <itemizedlist>
16602 <listitem>
16603 <simpara>
16604 <literal>bas</literal> <emphasis>basdec</emphasis> <literal>end</literal>
16605 </simpara>
16606 </listitem>
16607 <listitem>
16608 <simpara>
16609 <emphasis>basid</emphasis>
16610 </simpara>
16611 </listitem>
16612 <listitem>
16613 <simpara>
16614 <literal>let</literal> <emphasis>basdec</emphasis> <literal>in</literal> <emphasis>basexp</emphasis> <literal>end</literal>
16615 </simpara>
16616 </listitem>
16617 </itemizedlist>
16618 <simpara>Nested SML-style comments (enclosed with <literal>(*</literal> and <literal>*)</literal>) are ignored
16619 (but <link linkend="LineDirective">LineDirective</link>s are recognized).</simpara>
16620 <simpara>Paths can be relative or absolute. Relative paths are relative to the
16621 directory containing the MLB file. Paths may include path variables
16622 and are expanded according to a <link linkend="MLBasisPathMap">path map</link>. Unquoted
16623 paths may include alpha-numeric characters and the symbols "<literal>-</literal>" and
16624 "<literal>_</literal>", along with the arc separator "<literal>/</literal>" and extension separator
16625 "<literal>.</literal>". More complicated paths, including paths with spaces, may be
16626 included by quoting the path with <literal>"</literal>. A quoted path is lexed as an
16627 SML string constant.</simpara>
16628 <simpara><link linkend="MLBasisAnnotations">Annotations</link> allow a library author to
16629 control options that affect the elaboration of SML source files.</simpara>
16630 </section>
16631 <section id="_semantics">
16632 <title>Semantics</title>
16633 <simpara>There is a <ulink url="guide/MLBasis.attachments/mlb-formal.pdf">formal semantics</ulink> for
16634 ML Basis files in the style of the
16635 <link linkend="DefinitionOfStandardML">Definition</link>. Here, we give an informal
16636 explanation.</simpara>
16637 <simpara>An SML structure is a collection of types, values, and other
16638 structures. Similarly, a basis is a collection, but of more kinds of
16639 objects: types, values, structures, fixities, signatures, functors,
16640 and other bases.</simpara>
16641 <simpara>A basis declaration denotes a basis. A structure, signature, or
16642 functor declaration denotes a basis containing the corresponding
16643 module. Sequencing of basis declarations merges bases, with later
16644 definitions taking precedence over earlier ones, just like sequencing
16645 of SML declarations. Local declarations provide name hiding, just
16646 like SML local declarations. A reference to an SML source file causes
16647 the file to be elaborated in the basis extant at the point of
16648 reference. A reference to an MLB file causes the basis denoted by
16649 that MLB file to be imported&#8201;&#8212;&#8201;the basis at the point of reference
16650 does <emphasis>not</emphasis> affect the imported basis.</simpara>
16651 <simpara>Basis expressions and basis identifiers allow binding a basis to a
16652 name.</simpara>
16653 <simpara>An MLB file is elaborated starting in an empty basis. Each MLB file
16654 is elaborated and evaluated only once, with the result being cached.
16655 Subsequent references use the cached value. Thus, any observable
16656 effects due to evaluation are not duplicated if the MLB file is
16657 referred to multiple times.</simpara>
16658 <simpara><?asciidoc-pagebreak?></simpara>
16659 </section>
16660 </section>
16661 <section id="MLj">
16662 <title>MLj</title>
16663 <simpara><ulink url="http://www.dcs.ed.ac.uk/home/mlj/">MLj</ulink> is a
16664 <link linkend="StandardMLImplementations">Standard ML implementation</link> that targets
16665 Java bytecode. It is no longer maintained. It has morphed into
16666 <link linkend="SMLNET">SML.NET</link>.</simpara>
16667 <section id="_also_see_12">
16668 <title>Also see</title>
16669 <itemizedlist>
16670 <listitem>
16671 <simpara>
16672 <link linkend="References_BentonEtAl98">BentonEtAl98</link>
16673 </simpara>
16674 </listitem>
16675 <listitem>
16676 <simpara>
16677 <link linkend="References_BentonKennedy99">BentonKennedy99</link>
16678 </simpara>
16679 </listitem>
16680 </itemizedlist>
16681 <simpara><?asciidoc-pagebreak?></simpara>
16682 </section>
16683 </section>
16684 <section id="MLKit">
16685 <title>MLKit</title>
16686 <simpara>The <ulink url="http://sourceforge.net/apps/mediawiki/mlkit">ML Kit</ulink> is a
16687 <link linkend="StandardMLImplementations">Standard ML implementation</link>.</simpara>
16688 <simpara>MLKit supports:</simpara>
16689 <itemizedlist>
16690 <listitem>
16691 <simpara>
16692 <link linkend="DefinitionOfStandardML">SML&#8217;97</link>
16693 </simpara>
16694 <itemizedlist>
16695 <listitem>
16696 <simpara>
16697 including most of the latest <link linkend="BasisLibrary">Basis Library</link>
16698 <ulink url="http://www.standardml.org/Basis">specification</ulink>,
16699 </simpara>
16700 </listitem>
16701 </itemizedlist>
16702 </listitem>
16703 <listitem>
16704 <simpara>
16705 <link linkend="MLBasis">ML Basis</link> files
16706 </simpara>
16707 <itemizedlist>
16708 <listitem>
16709 <simpara>
16710 and separate compilation,
16711 </simpara>
16712 </listitem>
16713 </itemizedlist>
16714 </listitem>
16715 <listitem>
16716 <simpara>
16717 <link linkend="Regions">Region-Based Memory Management</link>
16718 </simpara>
16719 <itemizedlist>
16720 <listitem>
16721 <simpara>
16722 and <link linkend="GarbageCollection">garbage collection</link>,
16723 </simpara>
16724 </listitem>
16725 </itemizedlist>
16726 </listitem>
16727 <listitem>
16728 <simpara>
16729 Multiple backends, including
16730 </simpara>
16731 <itemizedlist>
16732 <listitem>
16733 <simpara>
16734 native x86,
16735 </simpara>
16736 </listitem>
16737 <listitem>
16738 <simpara>
16739 bytecode, and
16740 </simpara>
16741 </listitem>
16742 <listitem>
16743 <simpara>
16744 JavaScript (see <ulink url="http://www.itu.dk/people/mael/smltojs/">SMLtoJs</ulink>).
16745 </simpara>
16746 </listitem>
16747 </itemizedlist>
16748 </listitem>
16749 </itemizedlist>
16750 <simpara>At the time of writing, MLKit does not support:</simpara>
16751 <itemizedlist>
16752 <listitem>
16753 <simpara>
16754 concurrent programming / threads,
16755 </simpara>
16756 </listitem>
16757 <listitem>
16758 <simpara>
16759 calling from C to SML.
16760 </simpara>
16761 </listitem>
16762 </itemizedlist>
16763 <simpara><?asciidoc-pagebreak?></simpara>
16764 </section>
16765 <section id="MLLex">
16766 <title>MLLex</title>
16767 <simpara><link linkend="MLLex">MLLex</link> is a lexical analyzer generator for <link linkend="StandardML">Standard ML</link>
16768 modeled after the Lex lexical analyzer generator.</simpara>
16769 <simpara>A version of MLLex, ported from the <link linkend="SMLNJ">SML/NJ</link> sources, is
16770 distributed with MLton.</simpara>
16771 <section id="_description_37">
16772 <title>Description</title>
16773 <simpara>MLLex takes as input the lex language as defined in the ML-Lex manual,
16774 and outputs a lexical analyzer in SML.</simpara>
16775 </section>
16776 <section id="_implementation_40">
16777 <title>Implementation</title>
16778 <itemizedlist>
16779 <listitem>
16780 <simpara>
16781 <ulink url="https://github.com/MLton/mlton/blob/master/mllex/lexgen.sml"><literal>lexgen.sml</literal></ulink>
16782 </simpara>
16783 </listitem>
16784 <listitem>
16785 <simpara>
16786 <ulink url="https://github.com/MLton/mlton/blob/master/mllex/main.sml"><literal>main.sml</literal></ulink>
16787 </simpara>
16788 </listitem>
16789 <listitem>
16790 <simpara>
16791 <ulink url="https://github.com/MLton/mlton/blob/master/mllex/call-main.sml"><literal>call-main.sml</literal></ulink>
16792 </simpara>
16793 </listitem>
16794 </itemizedlist>
16795 </section>
16796 <section id="_details_and_notes_40">
16797 <title>Details and Notes</title>
16798 <simpara>There are 3 main passes in the MLLex tool:</simpara>
16799 <itemizedlist>
16800 <listitem>
16801 <simpara>
16802 Source parsing. In this pass, lex source program are parsed into internal representations. The core part of this pass is a hand-written lexer and an LL(1) parser. The output of this pass is a record of user code, rules (along with start states) and actions. (MLLex definitions are wiped off.)
16803 </simpara>
16804 </listitem>
16805 <listitem>
16806 <simpara>
16807 DFA construction. In this pass, a DFA is constructed by the algorithm of H. Yamada et. al.
16808 </simpara>
16809 </listitem>
16810 <listitem>
16811 <simpara>
16812 Output. In this pass, the generated DFA is written out as a transition table, along with a table-driven algorithm, to an SML file.
16813 </simpara>
16814 </listitem>
16815 </itemizedlist>
16816 </section>
16817 <section id="_also_see_13">
16818 <title>Also see</title>
16819 <itemizedlist>
16820 <listitem>
16821 <simpara>
16822 <ulink url="guide/Documentation.attachments/mllex.pdf"><literal>mllex.pdf</literal></ulink>
16823 </simpara>
16824 </listitem>
16825 <listitem>
16826 <simpara>
16827 <link linkend="MLYacc">MLYacc</link>
16828 </simpara>
16829 </listitem>
16830 <listitem>
16831 <simpara>
16832 <link linkend="References_AppelEtAl94">AppelEtAl94</link>
16833 </simpara>
16834 </listitem>
16835 <listitem>
16836 <simpara>
16837 <link linkend="References_Price09">Price09</link>
16838 </simpara>
16839 </listitem>
16840 </itemizedlist>
16841 <simpara><?asciidoc-pagebreak?></simpara>
16842 </section>
16843 </section>
16844 <section id="MLLPTLibrary">
16845 <title>MLLPTLibrary</title>
16846 <simpara>The
16847 <ulink url="http://smlnj-gforge.cs.uchicago.edu/projects/ml-lpt/">ML-LPT Library</ulink>
16848 is a support library for the <link linkend="MLULex">MLULex</link> scanner generator and the
16849 <link linkend="MLAntlr">MLAntlr</link> parser generator. The ML-LPT Library is distributed with
16850 SML/NJ.</simpara>
16851 <simpara>As of 20180119, MLton includes the ML-LPT Library synchronized with
16852 SML/NJ version 110.82.</simpara>
16853 <section id="_usage_5">
16854 <title>Usage</title>
16855 <itemizedlist>
16856 <listitem>
16857 <simpara>
16858 You can import the ML-LPT Library into an MLB file with:
16859 </simpara>
16860 <informaltable
16861 frame="all"
16862 rowsep="1" colsep="1"
16863 >
16864 <tgroup cols="2">
16865 <colspec colname="col_1" colwidth="50*"/>
16866 <colspec colname="col_2" colwidth="50*"/>
16867 <thead>
16868 <row>
16869 <entry align="left" valign="top">MLB file</entry>
16870 <entry align="left" valign="top">Description</entry>
16871 </row>
16872 </thead>
16873 <tbody>
16874 <row>
16875 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mllpt-lib/mllpt-lib.mlb</literal></simpara></entry>
16876 <entry align="left" valign="top"><simpara></simpara></entry>
16877 </row>
16878 </tbody>
16879 </tgroup>
16880 </informaltable>
16881 </listitem>
16882 <listitem>
16883 <simpara>
16884 If you are porting a project from SML/NJ&#8217;s <link linkend="CompilationManager">CompilationManager</link> to
16885 MLton&#8217;s <link linkend="MLBasis">ML Basis system</link> using <literal>cm2mlb</literal>, note that the
16886 following map is included by default:
16887 </simpara>
16888 <screen># MLLPT Library
16889 $ml-lpt-lib.cm $(SML_LIB)/mllpt-lib
16890 $ml-lpt-lib.cm/ml-lpt-lib.cm $(SML_LIB)/mllpt-lib/mllpt-lib.mlb</screen>
16891 <simpara>This will automatically convert a <literal>$/mllpt-lib.cm</literal> import in an input
16892 <literal>.cm</literal> file into a <literal>$(SML_LIB)/mllpt-lib/mllpt-lib.mlb</literal> import in the
16893 output <literal>.mlb</literal> file.</simpara>
16894 </listitem>
16895 </itemizedlist>
16896 </section>
16897 <section id="_details_2">
16898 <title>Details</title>
16899 <simpara></simpara>
16900 </section>
16901 <section id="_patch_2">
16902 <title>Patch</title>
16903 <itemizedlist>
16904 <listitem>
16905 <simpara>
16906 <ulink url="https://github.com/MLton/mlton/blob/master/lib/mllpt-lib/ml-lpt.patch"><literal>ml-lpt.patch</literal></ulink>
16907 </simpara>
16908 </listitem>
16909 </itemizedlist>
16910 <simpara><?asciidoc-pagebreak?></simpara>
16911 </section>
16912 </section>
16913 <section id="MLmon">
16914 <title>MLmon</title>
16915 <simpara>An <literal>mlmon.out</literal> file records dynamic <link linkend="Profiling">profiling</link> counts.</simpara>
16916 <section id="_file_format">
16917 <title>File format</title>
16918 <simpara>An <literal>mlmon.out</literal> file is a text file with a sequence of lines.</simpara>
16919 <itemizedlist>
16920 <listitem>
16921 <simpara>
16922 The string "<literal>MLton prof</literal>".
16923 </simpara>
16924 </listitem>
16925 <listitem>
16926 <simpara>
16927 The string "<literal>alloc</literal>", "<literal>count</literal>", or "<literal>time</literal>", depending on the kind
16928 of profiling information, corresponding to the command-line argument
16929 supplied to <literal>mlton -profile</literal>.
16930 </simpara>
16931 </listitem>
16932 <listitem>
16933 <simpara>
16934 The string "<literal>current</literal>" or "<literal>stack</literal>" depending on whether profiling
16935 data was gathered for only the current function (the top of the stack)
16936 or for all functions on the stack. This corresponds to whether the
16937 executable was compiled with <literal>-profile-stack false</literal> or <literal>-profile-stack
16938 true</literal>.
16939 </simpara>
16940 </listitem>
16941 <listitem>
16942 <simpara>
16943 The magic number of the executable.
16944 </simpara>
16945 </listitem>
16946 <listitem>
16947 <simpara>
16948 The number of non-gc ticks, followed by a space, then the number of
16949 GC ticks.
16950 </simpara>
16951 </listitem>
16952 <listitem>
16953 <simpara>
16954 The number of (split) functions for which data is recorded.
16955 </simpara>
16956 </listitem>
16957 <listitem>
16958 <simpara>
16959 A line for each (split) function with counts. Each line contains an
16960 integer count of the number of ticks while the function was current.
16961 In addition, if stack data was gathered (<literal>-profile-stack true</literal>), then
16962 the line contains two additional tick counts:
16963 </simpara>
16964 <itemizedlist>
16965 <listitem>
16966 <simpara>
16967 the number of ticks while the function was on the stack.
16968 </simpara>
16969 </listitem>
16970 <listitem>
16971 <simpara>
16972 the number of ticks while the function was on the stack and a GC
16973 was performed.
16974 </simpara>
16975 </listitem>
16976 </itemizedlist>
16977 </listitem>
16978 <listitem>
16979 <simpara>
16980 The number of (master) functions for which data is recorded.
16981 </simpara>
16982 </listitem>
16983 <listitem>
16984 <simpara>
16985 A line for each (master) function with counts. The lines have the
16986 same format and meaning as with split-function counts.
16987 </simpara>
16988 </listitem>
16989 </itemizedlist>
16990 <simpara><?asciidoc-pagebreak?></simpara>
16991 </section>
16992 </section>
16993 <section id="MLNLFFI">
16994 <title>MLNLFFI</title>
16995 <simpara><link linkend="References_Blume01">ML-NLFFI</link> is the no-longer-foreign-function interface
16996 library for SML.</simpara>
16997 <simpara>As of 20050212, MLton has an initial port of ML-NLFFI from SML/NJ to
16998 MLton. All of the ML-NLFFI functionality is present.</simpara>
16999 <simpara>Additionally, MLton has an initial port of the
17000 <link linkend="MLNLFFIGen">mlnlffigen</link> tool from SML/NJ to MLton. Due to low-level
17001 details, the code generated by SML/NJ&#8217;s <literal>ml-nlffigen</literal> is not
17002 compatible with MLton, and vice-versa. However, the generated code
17003 has the same interface, so portable client code can be written.
17004 MLton&#8217;s <literal>mlnlffigen</literal> does not currently support C functions with
17005 <literal>struct</literal> or <literal>union</literal> arguments.</simpara>
17006 <section id="_usage_6">
17007 <title>Usage</title>
17008 <itemizedlist>
17009 <listitem>
17010 <simpara>
17011 You can import the ML-NLFFI Library into an MLB file with
17012 </simpara>
17013 <informaltable
17014 frame="all"
17015 rowsep="1" colsep="1"
17016 >
17017 <tgroup cols="2">
17018 <colspec colname="col_1" colwidth="50*"/>
17019 <colspec colname="col_2" colwidth="50*"/>
17020 <thead>
17021 <row>
17022 <entry align="left" valign="top">MLB file</entry>
17023 <entry align="left" valign="top">Description</entry>
17024 </row>
17025 </thead>
17026 <tbody>
17027 <row>
17028 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlnlffi-lib/mlnlffi-lib.mlb</literal></simpara></entry>
17029 <entry align="left" valign="top"><simpara></simpara></entry>
17030 </row>
17031 </tbody>
17032 </tgroup>
17033 </informaltable>
17034 </listitem>
17035 <listitem>
17036 <simpara>
17037 If you are porting a project from SML/NJ&#8217;s <link linkend="CompilationManager">CompilationManager</link> to
17038 MLton&#8217;s <link linkend="MLBasis">ML Basis system</link> using <literal>cm2mlb</literal>, note that the
17039 following maps are included by default:
17040 </simpara>
17041 <screen># MLNLFFI Library
17042 $c $(SML_LIB)/mlnlffi-lib
17043 $c/c.cm $(SML_LIB)/mlnlffi-lib/mlnlffi-lib.mlb</screen>
17044 <simpara>This will automatically convert a <literal>$/c.cm</literal> import in an input <literal>.cm</literal>
17045 file into a <literal>$(SML_LIB)/mlnlffi-lib/mlnlffi-lib.mlb</literal> import in the
17046 output <literal>.mlb</literal> file.</simpara>
17047 </listitem>
17048 </itemizedlist>
17049 </section>
17050 <section id="_also_see_14">
17051 <title>Also see</title>
17052 <itemizedlist>
17053 <listitem>
17054 <simpara>
17055 <link linkend="References_Blume01">Blume01</link>
17056 </simpara>
17057 </listitem>
17058 <listitem>
17059 <simpara>
17060 <link linkend="MLNLFFIImplementation">MLNLFFIImplementation</link>
17061 </simpara>
17062 </listitem>
17063 <listitem>
17064 <simpara>
17065 <link linkend="MLNLFFIGen">MLNLFFIGen</link>
17066 </simpara>
17067 </listitem>
17068 </itemizedlist>
17069 <simpara><?asciidoc-pagebreak?></simpara>
17070 </section>
17071 </section>
17072 <section id="MLNLFFIGen">
17073 <title>MLNLFFIGen</title>
17074 <simpara><literal>mlnlffigen</literal> generates a <link linkend="MLNLFFI">MLNLFFI</link> binding from a collection of <literal>.c</literal>
17075 files. It is based on the <link linkend="CKitLibrary">CKitLibrary</link>, which is primarily designed
17076 to handle standardized C and thus does not understand many (any?)
17077 compiler extensions; however, it attempts to recover from errors when
17078 seeing unrecognized definitions.</simpara>
17079 <simpara>In order to work around common gcc extensions, it may be useful to add
17080 <literal>-cppopt</literal> options to the command line; for example
17081 <literal>-cppopt '-D__extension__'</literal> may be occasionally useful. Fortunately,
17082 most portable libraries largely avoid the use of these types of
17083 extensions in header files.</simpara>
17084 <simpara><literal>mlnlffigen</literal> will normally not generate bindings for <literal>#included</literal>
17085 files; see <literal>-match</literal> and <literal>-allSU</literal> if this is desirable.</simpara>
17086 <simpara><?asciidoc-pagebreak?></simpara>
17087 </section>
17088 <section id="MLNLFFIImplementation">
17089 <title>MLNLFFIImplementation</title>
17090 <simpara>MLton&#8217;s implementation(s) of the <link linkend="MLNLFFI">MLNLFFI</link> library differs from the
17091 SML/NJ implementation in two important ways:</simpara>
17092 <itemizedlist>
17093 <listitem>
17094 <simpara>
17095 MLton cannot utilize the <literal>Unsafe.cast</literal> "cheat" described in Section
17096 3.7 of <link linkend="References_Blume01">Blume01</link>. (MLton&#8217;s representation of
17097 <link linkend="Closure">closures</link> and
17098 <link linkend="PackedRepresentation">aggressive representation</link> optimizations make
17099 an <literal>Unsafe.cast</literal> even more "unsafe" than in other implementations.)
17100 </simpara>
17101 <simpara>We have considered two solutions:</simpara>
17102 <itemizedlist>
17103 <listitem>
17104 <simpara>
17105 One solution is to utilize an additional type parameter (as
17106 described in Section 3.7 of <link linkend="References_Blume01">Blume01</link>):
17107 </simpara>
17108 <blockquote>
17109 <programlisting language="sml" linenumbering="unnumbered">signature C = sig
17110 type ('t, 'f, 'c) obj
17111 eqtype ('t, 'f, 'c) obj'
17112 ...
17113 type ('o, 'f) ptr
17114 eqtype ('o, 'f) ptr'
17115 ...
17116 type 'f fptr
17117 type 'f ptr'
17118 ...
17119 structure T : sig
17120 type ('t, 'f) typ
17121 ...
17122 end
17123 end</programlisting>
17124 <simpara>The rule for <literal>('t, 'f, 'c) obj</literal>,<literal>('t, 'f, 'c) ptr</literal>, and also <literal>('t, 'f)
17125 T.typ</literal> is that whenever <literal>F fptr</literal> occurs within the instantiation of
17126 <literal>'t</literal>, then <literal>'f</literal> must be instantiated to <literal>F</literal>. In all other cases, <literal>'f</literal>
17127 will be instantiated to <literal>unit</literal>.</simpara>
17128 </blockquote>
17129 <simpara>(In the actual MLton implementation, an abstract type <literal>naf</literal>
17130 (not-a-function) is used instead of <literal>unit</literal>.)</simpara>
17131 <simpara>While this means that type-annotated programs may not type-check under
17132 both the SML/NJ implementation and the MLton implementation, this
17133 should not be a problem in practice. Tools, like <literal>ml-nlffigen</literal>, which
17134 are necessarily implementation dependent (in order to make
17135 <link linkend="CallingFromSMLToCFunctionPointer">calls through a C function pointer</link>), may be easily extended to emit the additional type
17136 parameter. Client code which uses such generated glue-code (e.g.,
17137 Section 1 of <link linkend="References_Blume01">Blume01</link>) need rarely write type-annotations,
17138 thanks to the magic of type inference.</simpara>
17139 </listitem>
17140 <listitem>
17141 <simpara>
17142 The above implementation suffers from two disadvantages.
17143 </simpara>
17144 <simpara>First, it changes the MLNLFFI Library interface, meaning that the same
17145 program may not type-check under both the SML/NJ implementation and
17146 the MLton implementation (though, in light of type inference and the
17147 richer <literal>MLRep</literal> structure provided by MLton, this point is mostly
17148 moot).</simpara>
17149 <simpara>Second, it appears to unnecessarily duplicate type information. For
17150 example, an external C variable of type <literal>int (* f[3])(int)</literal> (that is,
17151 an array of three function pointers), would be represented by the SML
17152 type <literal>(((sint -&gt; sint) fptr, dec dg3) arr, sint -&gt; sint, rw) obj</literal>.
17153 One might well ask why the <literal>'f</literal> instantiation (<literal>sint -&gt; sint</literal> in this
17154 case) cannot be <emphasis>extracted</emphasis> from the <literal>'t</literal> instantiation
17155 (<literal>((sint -&gt; sint) fptr, dec dg3) arr</literal> in this case), obviating the
17156 need for a separate <emphasis>function-type</emphasis> type argument. There are a number
17157 of components to an complete answer to this question. Foremost is the
17158 fact that <link linkend="StandardML">Standard ML</link> supports neither (general)
17159 type-level functions nor intensional polymorphism.</simpara>
17160 <simpara>A more direct answer for MLNLFFI is that in the SML/NJ implemention,
17161 the definition of the types <literal>('t, 'c) obj</literal> and <literal>('t, 'c) ptr</literal> are made
17162 in such a way that the type variables <literal>'t</literal> and <literal>'c</literal> are <link linkend="PhantomType">phantom</link> (not contributing to the run-time representation of an
17163 <literal>('t, 'c) obj</literal> or <literal>('t, 'c) ptr</literal> value), despite the fact that the
17164 types <literal>((sint -&gt; sint) fptr, rw) ptr</literal> and
17165 <literal>((double -&gt; double) fptr, rw) ptr</literal> necessarily carry distinct (and
17166 type incompatible) run-time (C-)type information (RTTI), corresponding
17167 to the different calling conventions of the two C functions. The
17168 <literal>Unsafe.cast</literal> "cheat" overcomes the type incompatibility without
17169 introducing a new type variable (as in the first solution above).</simpara>
17170 <simpara>Hence, the reason that <emphasis>function-type</emphasis> type cannot be extracted from
17171 the <literal>'t</literal> type variable instantiation is that the type of the
17172 representation of RTTI doesn&#8217;t even <emphasis>see</emphasis> the (phantom) <literal>'t</literal> type
17173 variable. The solution which presents itself is to give up on the
17174 phantomness of the <literal>'t</literal> type variable, making it available to the
17175 representation of RTTI.</simpara>
17176 <simpara>This is not without some small drawbacks. Because many of the types
17177 used to instantiate <literal>'t</literal> carry more structure than is strictly
17178 necessary for <literal>'t</literal>'s RTTI, it is sometimes necessary to wrap and
17179 unwrap RTTI to accommodate the additional structure. (In the other
17180 implementations, the corresponding operations can pass along the RTTI
17181 unchanged.) However, these coercions contribute minuscule overhead;
17182 in fact, in a majority of cases, MLton&#8217;s optimizations will completely
17183 eliminate the RTTI from the final program.</simpara>
17184 </listitem>
17185 </itemizedlist>
17186 <simpara>The implementation distributed with MLton uses the second solution.</simpara>
17187 <simpara>Bonus question: Why can&#8217;t one use a <link linkend="UniversalType">universal type</link>
17188 to eliminate the use of <literal>Unsafe.cast</literal>?</simpara>
17189 <itemizedlist>
17190 <listitem>
17191 <simpara>
17192 Answer: ???
17193 </simpara>
17194 </listitem>
17195 </itemizedlist>
17196 </listitem>
17197 <listitem>
17198 <simpara>
17199 MLton (in both of the above implementations) provides a richer
17200 <literal>MLRep</literal> structure, utilizing <literal>Int<emphasis>&lt;N&gt;</emphasis></literal> and <literal>Word<emphasis>&lt;N&gt;</emphasis></literal>
17201 structures.
17202 </simpara>
17203 <programlisting language="sml" linenumbering="unnumbered">structure MLRep = struct
17204 structure Char =
17205 struct
17206 structure Signed = Int8
17207 structure Unsigned = Word8
17208 (* word-style bit-operations on integers... *)
17209 structure &lt;:SignedBitops:&gt; = IntBitOps(structure I = Signed
17210 structure W = Unsigned)
17211 end
17212 structure Short =
17213 struct
17214 structure Signed = Int16
17215 structure Unsigned = Word16
17216 (* word-style bit-operations on integers... *)
17217 structure &lt;:SignedBitops:&gt; = IntBitOps(structure I = Signed
17218 structure W = Unsigned)
17219 end
17220 structure Int =
17221 struct
17222 structure Signed = Int32
17223 structure Unsigned = Word32
17224 (* word-style bit-operations on integers... *)
17225 structure &lt;:SignedBitops:&gt; = IntBitOps(structure I = Signed
17226 structure W = Unsigned)
17227 end
17228 structure Long =
17229 struct
17230 structure Signed = Int32
17231 structure Unsigned = Word32
17232 (* word-style bit-operations on integers... *)
17233 structure &lt;:SignedBitops:&gt; = IntBitOps(structure I = Signed
17234 structure W = Unsigned)
17235 end
17236 structure &lt;:LongLong:&gt; =
17237 struct
17238 structure Signed = Int64
17239 structure Unsigned = Word64
17240 (* word-style bit-operations on integers... *)
17241 structure &lt;:SignedBitops:&gt; = IntBitOps(structure I = Signed
17242 structure W = Unsigned)
17243 end
17244 structure Float = Real32
17245 structure Double = Real64
17246 end</programlisting>
17247 <simpara>This would appear to be a better interface, even when an
17248 implementation must choose <literal>Int32</literal> and <literal>Word32</literal> as the representation
17249 for smaller C-types.</simpara>
17250 </listitem>
17251 </itemizedlist>
17252 <simpara><?asciidoc-pagebreak?></simpara>
17253 </section>
17254 <section id="MLRISCLibrary">
17255 <title>MLRISCLibrary</title>
17256 <simpara>The <ulink url="http://www.cs.nyu.edu/leunga/www/MLRISC/Doc/html/index.html">MLRISC
17257 Library</ulink> is a framework for retargetable and optimizing compiler back
17258 ends. The MLRISC Library is distributed with SML/NJ. Due to
17259 differences between SML/NJ and MLton, this library will not work
17260 out-of-the box with MLton.</simpara>
17261 <simpara>As of 20180119, MLton includes a port of the MLRISC Library
17262 synchronized with SML/NJ version 110.82.</simpara>
17263 <section id="_usage_7">
17264 <title>Usage</title>
17265 <itemizedlist>
17266 <listitem>
17267 <simpara>
17268 You can import a sub-library of the MLRISC Library into an MLB file with:
17269 </simpara>
17270 <informaltable
17271 frame="all"
17272 rowsep="1" colsep="1"
17273 >
17274 <tgroup cols="2">
17275 <colspec colname="col_1" colwidth="50*"/>
17276 <colspec colname="col_2" colwidth="50*"/>
17277 <thead>
17278 <row>
17279 <entry align="left" valign="top">MLB file</entry>
17280 <entry align="left" valign="top">Description</entry>
17281 </row>
17282 </thead>
17283 <tbody>
17284 <row>
17285 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/ALPHA.mlb</literal></simpara></entry>
17286 <entry align="left" valign="top"><simpara>The ALPHA backend</simpara></entry>
17287 </row>
17288 <row>
17289 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/AMD64.mlb</literal></simpara></entry>
17290 <entry align="left" valign="top"><simpara>The AMD64 backend</simpara></entry>
17291 </row>
17292 <row>
17293 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/AMD64-Peephole.mlb</literal></simpara></entry>
17294 <entry align="left" valign="top"><simpara>The AMD64 peephole optimizer</simpara></entry>
17295 </row>
17296 <row>
17297 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/CCall.mlb</literal></simpara></entry>
17298 <entry align="left" valign="top"><simpara></simpara></entry>
17299 </row>
17300 <row>
17301 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/CCall-sparc.mlb</literal></simpara></entry>
17302 <entry align="left" valign="top"><simpara></simpara></entry>
17303 </row>
17304 <row>
17305 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/CCall-x86-64.mlb</literal></simpara></entry>
17306 <entry align="left" valign="top"><simpara></simpara></entry>
17307 </row>
17308 <row>
17309 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/CCall-x86.mlb</literal></simpara></entry>
17310 <entry align="left" valign="top"><simpara></simpara></entry>
17311 </row>
17312 <row>
17313 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/Control.mlb</literal></simpara></entry>
17314 <entry align="left" valign="top"><simpara></simpara></entry>
17315 </row>
17316 <row>
17317 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/Graphs.mlb</literal></simpara></entry>
17318 <entry align="left" valign="top"><simpara></simpara></entry>
17319 </row>
17320 <row>
17321 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/HPPA.mlb</literal></simpara></entry>
17322 <entry align="left" valign="top"><simpara>The HPPA backend</simpara></entry>
17323 </row>
17324 <row>
17325 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/IA32.mlb</literal></simpara></entry>
17326 <entry align="left" valign="top"><simpara>The IA32 backend</simpara></entry>
17327 </row>
17328 <row>
17329 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/IA32-Peephole.mlb</literal></simpara></entry>
17330 <entry align="left" valign="top"><simpara>The IA32 peephole optimizer</simpara></entry>
17331 </row>
17332 <row>
17333 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/Lib.mlb</literal></simpara></entry>
17334 <entry align="left" valign="top"><simpara></simpara></entry>
17335 </row>
17336 <row>
17337 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/MLRISC.mlb</literal></simpara></entry>
17338 <entry align="left" valign="top"><simpara></simpara></entry>
17339 </row>
17340 <row>
17341 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/MLTREE.mlb</literal></simpara></entry>
17342 <entry align="left" valign="top"><simpara></simpara></entry>
17343 </row>
17344 <row>
17345 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/Peephole.mlb</literal></simpara></entry>
17346 <entry align="left" valign="top"><simpara></simpara></entry>
17347 </row>
17348 <row>
17349 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/PPC.mlb</literal></simpara></entry>
17350 <entry align="left" valign="top"><simpara>The PPC backend</simpara></entry>
17351 </row>
17352 <row>
17353 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/RA.mlb</literal></simpara></entry>
17354 <entry align="left" valign="top"><simpara></simpara></entry>
17355 </row>
17356 <row>
17357 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/SPARC.mlb</literal></simpara></entry>
17358 <entry align="left" valign="top"><simpara>The Sparc backend</simpara></entry>
17359 </row>
17360 <row>
17361 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/StagedAlloc.mlb</literal></simpara></entry>
17362 <entry align="left" valign="top"><simpara></simpara></entry>
17363 </row>
17364 <row>
17365 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/mlrisc-lib/mlb/Visual.mlb</literal></simpara></entry>
17366 <entry align="left" valign="top"><simpara></simpara></entry>
17367 </row>
17368 </tbody>
17369 </tgroup>
17370 </informaltable>
17371 </listitem>
17372 <listitem>
17373 <simpara>
17374 If you are porting a project from SML/NJ&#8217;s <link linkend="CompilationManager">CompilationManager</link> to
17375 MLton&#8217;s <link linkend="MLBasis">ML Basis system</link> using <literal>cm2mlb</literal>, note that the
17376 following map is included by default:
17377 </simpara>
17378 <screen># MLRISC Library
17379 $SMLNJ-MLRISC $(SML_LIB)/mlrisc-lib/mlb</screen>
17380 <simpara>This will automatically convert a <literal>$SMLNJ-MLRISC/MLRISC.cm</literal> import in
17381 an input <literal>.cm</literal> file into a <literal>$(SML_LIB)/mlrisc-lib/mlb/MLRISC.mlb</literal>
17382 import in the output <literal>.mlb</literal> file.</simpara>
17383 </listitem>
17384 </itemizedlist>
17385 </section>
17386 <section id="_details_3">
17387 <title>Details</title>
17388 <simpara>The following changes were made to the MLRISC Library, in addition to
17389 deriving the <literal>.mlb</literal> files from the <literal>.cm</literal> files:</simpara>
17390 <itemizedlist>
17391 <listitem>
17392 <simpara>
17393 eliminate sequential <literal>withtype</literal> expansions: Most could be rewritten as a sequence of type definitions and datatype definitions.
17394 </simpara>
17395 </listitem>
17396 <listitem>
17397 <simpara>
17398 eliminate higher-order functors: Every higher-order functor definition and application could be uncurried in the obvious way.
17399 </simpara>
17400 </listitem>
17401 <listitem>
17402 <simpara>
17403 eliminate <literal>where &lt;str&gt; = &lt;str&gt;</literal>: Quite painful to expand out all the flexible types in the respective structures. Furthermore, many of the implied type equalities aren&#8217;t needed, but it&#8217;s too hard to pick out the right ones.
17404 </simpara>
17405 </listitem>
17406 <listitem>
17407 <simpara>
17408 <literal>library/array-noneq.sml</literal> (added, not exported): Implements <literal>signature ARRAY_NONEQ</literal>, similar to <literal>signature ARRAY</literal> from the <link linkend="BasisLibrary">Basis Library</link>, but replacing the latter&#8217;s <literal>eqtype 'a array = 'a array</literal> and <literal>type 'a vector = 'a Vector.vector</literal> with <literal>type 'a array</literal> and <literal>type 'a vector</literal>. Thus, array-like containers may match <literal>ARRAY_NONEQ</literal>, whereas only the pervasive <literal>'a array</literal> container may math <literal>ARRAY</literal>. (SML/NJ&#8217;s implementation of <literal>signature ARRAY</literal> omits the type realizations.)
17409 </simpara>
17410 </listitem>
17411 <listitem>
17412 <simpara>
17413 <literal>library/dynamic-array.sml</literal> and <literal>library/hash-array.sml</literal> (modifed): Replace <literal>include ARRAY</literal> with <literal>include ARRAY_NONEQ</literal>; see above.
17414 </simpara>
17415 </listitem>
17416 </itemizedlist>
17417 </section>
17418 <section id="_patch_3">
17419 <title>Patch</title>
17420 <itemizedlist>
17421 <listitem>
17422 <simpara>
17423 <ulink url="https://github.com/MLton/mlton/blob/master/lib/mlrisc-lib/MLRISC.patch"><literal>MLRISC.patch</literal></ulink>
17424 </simpara>
17425 </listitem>
17426 </itemizedlist>
17427 <simpara><?asciidoc-pagebreak?></simpara>
17428 </section>
17429 </section>
17430 <section id="MLtonArray">
17431 <title>MLtonArray</title>
17432 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_ARRAY =
17433 sig
17434 val unfoldi: int * 'b * (int * 'b -&gt; 'a * 'b) -&gt; 'a array * 'b
17435 end</programlisting>
17436 <itemizedlist>
17437 <listitem>
17438 <simpara>
17439 <literal>unfoldi (n, b, f)</literal>
17440 </simpara>
17441 <simpara>constructs an array <emphasis>a</emphasis> of length <literal>n</literal>, whose elements <emphasis>a<subscript>i</subscript></emphasis> are
17442 determined by the equations <emphasis>b<subscript>0</subscript> = b</emphasis> and
17443 <emphasis>(a<subscript>i</subscript>, b<subscript>i+1</subscript>) = f (i, b<subscript>i</subscript>)</emphasis>.</simpara>
17444 </listitem>
17445 </itemizedlist>
17446 <simpara><?asciidoc-pagebreak?></simpara>
17447 </section>
17448 <section id="MLtonBinIO">
17449 <title>MLtonBinIO</title>
17450 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_BIN_IO = MLTON_IO</programlisting>
17451 <simpara>See <link linkend="MLtonIO">MLtonIO</link>.</simpara>
17452 <simpara><?asciidoc-pagebreak?></simpara>
17453 </section>
17454 <section id="MLtonCont">
17455 <title>MLtonCont</title>
17456 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_CONT =
17457 sig
17458 type 'a t
17459
17460 val callcc: ('a t -&gt; 'a) -&gt; 'a
17461 val isolate: ('a -&gt; unit) -&gt; 'a t
17462 val prepend: 'a t * ('b -&gt; 'a) -&gt; 'b t
17463 val throw: 'a t * 'a -&gt; 'b
17464 val throw': 'a t * (unit -&gt; 'a) -&gt; 'b
17465 end</programlisting>
17466 <itemizedlist>
17467 <listitem>
17468 <simpara>
17469 <literal>type 'a t</literal>
17470 </simpara>
17471 <simpara>the type of continuations that expect a value of type <literal>'a</literal>.</simpara>
17472 </listitem>
17473 <listitem>
17474 <simpara>
17475 <literal>callcc f</literal>
17476 </simpara>
17477 <simpara>applies <literal>f</literal> to the current continuation. This copies the entire
17478 stack; hence, <literal>callcc</literal> takes time proportional to the size of the
17479 current stack.</simpara>
17480 </listitem>
17481 <listitem>
17482 <simpara>
17483 <literal>isolate f</literal>
17484 </simpara>
17485 <simpara>creates a continuation that evaluates <literal>f</literal> in an empty context. This
17486 is a constant time operation, and yields a constant size stack.</simpara>
17487 </listitem>
17488 <listitem>
17489 <simpara>
17490 <literal>prepend (k, f)</literal>
17491 </simpara>
17492 <simpara>composes a function <literal>f</literal> with a continuation <literal>k</literal> to create a
17493 continuation that first does <literal>f</literal> and then does <literal>k</literal>. This is a
17494 constant time operation.</simpara>
17495 </listitem>
17496 <listitem>
17497 <simpara>
17498 <literal>throw (k, v)</literal>
17499 </simpara>
17500 <simpara>throws value <literal>v</literal> to continuation <literal>k</literal>. This copies the entire stack of
17501 <literal>k</literal>; hence, <literal>throw</literal> takes time proportional to the size of this stack.</simpara>
17502 </listitem>
17503 <listitem>
17504 <simpara>
17505 <literal>throw' (k, th)</literal>
17506 </simpara>
17507 <simpara>a generalization of throw that evaluates <literal>th ()</literal> in the context of
17508 <literal>k</literal>. Thus, for example, if <literal>th ()</literal> raises an exception or captures
17509 another continuation, it will see <literal>k</literal>, not the current continuation.</simpara>
17510 </listitem>
17511 </itemizedlist>
17512 <section id="_also_see_15">
17513 <title>Also see</title>
17514 <itemizedlist>
17515 <listitem>
17516 <simpara>
17517 <link linkend="MLtonContIsolateImplementation">MLtonContIsolateImplementation</link>
17518 </simpara>
17519 </listitem>
17520 </itemizedlist>
17521 <simpara><?asciidoc-pagebreak?></simpara>
17522 </section>
17523 </section>
17524 <section id="MLtonContIsolateImplementation">
17525 <title>MLtonContIsolateImplementation</title>
17526 <simpara>As noted before, it is fairly easy to get the operational behavior of <literal>isolate</literal> with just <literal>callcc</literal> and <literal>throw</literal>, but establishing the right space behavior is trickier. Here, we show how to start from the obvious, but inefficient, implementation of <literal>isolate</literal> using only <literal>callcc</literal> and <literal>throw</literal>, and <emphasis>derive</emphasis> an equivalent, but more efficient, implementation of <literal>isolate</literal> using MLton&#8217;s primitive stack capture and copy operations. This isn&#8217;t a formal derivation, as we are not formally showing the equivalence of the programs (though I believe that they are all equivalent, modulo the space behavior).</simpara>
17527 <simpara>Here is a direct implementation of isolate using only <literal>callcc</literal> and <literal>throw</literal>:</simpara>
17528 <programlisting language="sml" linenumbering="unnumbered">val isolate: ('a -&gt; unit) -&gt; 'a t =
17529 fn (f: 'a -&gt; unit) =&gt;
17530 callcc
17531 (fn k1 =&gt;
17532 let
17533 val x = callcc (fn k2 =&gt; throw (k1, k2))
17534 val _ = (f x ; Exit.topLevelSuffix ())
17535 handle exn =&gt; MLtonExn.topLevelHandler exn
17536 in
17537 raise Fail "MLton.Cont.isolate: return from (wrapped) func"
17538 end)</programlisting>
17539 <simpara>We use the standard nested <literal>callcc</literal> trick to return a continuation that is ready to receive an argument, execute the isolated function, and exit the program. Both <literal>Exit.topLevelSuffix</literal> and <literal>MLtonExn.topLevelHandler</literal> will terminate the program.</simpara>
17540 <simpara>Throwing to an isolated function will execute the function in a <emphasis>semantically</emphasis> empty context, in the sense that we never re-execute the <emphasis>original</emphasis> continuation of the call to isolate (i.e., the context that was in place at the time <literal>isolate</literal> was called). However, we assume that the compiler isn&#8217;t able to recognize that the <emphasis>original</emphasis> continuation is unused; for example, while we (the programmer) know that <literal>Exit.topLevelSuffix</literal> and <literal>MLtonExn.topLevelHandler</literal> will terminate the program, the compiler may only see opaque calls to unknown foreign-functions. So, that original continuation (in its entirety) is part of the continuation returned by <literal>isolate</literal> and throwing to the continuation returned by <literal>isolate</literal> will execute <literal>f x</literal> (with the exit wrapper) in the context of that original continuation. Thus, the garbage collector will retain everything reachable from that original continuation during the evaluation of <literal>f x</literal>, even though it is <emphasis>semantically</emphasis> garbage.</simpara>
17541 <simpara>Note that this space-leak is independent of the implementation of continuations (it arises in both MLton&#8217;s stack copying implementation of continuations and would arise in SML/NJ&#8217;s CPS-translation implementation); we are only assuming that the implementation can&#8217;t <emphasis>see</emphasis> the program termination, and so must retain the original continuation (and anything reachable from it).</simpara>
17542 <simpara>So, we need an <emphasis>empty</emphasis> continuation in which to execute <literal>f x</literal>. (No surprise there, as that is the written description of <literal>isolate</literal>.) To do this, we capture a top-level continuation and throw to that in order to execute <literal>f x</literal>:</simpara>
17543 <programlisting language="sml" linenumbering="unnumbered">local
17544 val base: (unit -&gt; unit) t =
17545 callcc
17546 (fn k1 =&gt;
17547 let
17548 val th = callcc (fn k2 =&gt; throw (k1, k2))
17549 val _ = (th () ; Exit.topLevelSuffix ())
17550 handle exn =&gt; MLtonExn.topLevelHandler exn
17551 in
17552 raise Fail "MLton.Cont.isolate: return from (wrapped) func"
17553 end)
17554 in
17555 val isolate: ('a -&gt; unit) -&gt; 'a t =
17556 fn (f: 'a -&gt; unit) =&gt;
17557 callcc
17558 (fn k1 =&gt;
17559 let
17560 val x = callcc (fn k2 =&gt; throw (k1, k2))
17561 in
17562 throw (base, fn () =&gt; f x)
17563 end)
17564 end</programlisting>
17565 <simpara>We presume that <literal>base</literal> is evaluated <emphasis>early</emphasis> in the program. There is a subtlety here, because one needs to believe that this <literal>base</literal> continuation (which technically corresponds to the entire rest of the program evaluation) <emphasis>works</emphasis> as an empty context; in particular, we want it to be the case that executing <literal>f x</literal> in the <literal>base</literal> context retains less space than executing <literal>f x</literal> in the context in place at the call to <literal>isolate</literal> (as occurred in the previous implementation of <literal>isolate</literal>). This isn&#8217;t particularly easy to believe if one takes a normal substitution-based operational semantics, because it seems that the context captured and bound to <literal>base</literal> is arbitrarily large. However, this context is mostly unevaluated code; the only heap-allocated values that are reachable from it are those that were evaluated before the evaluation of <literal>base</literal> (and used in the program after the evaluation of <literal>base</literal>). Assuming that <literal>base</literal> is evaluated <emphasis>early</emphasis> in the program, we conclude that there are few heap-allocated values reachable from its continuation. In contrast, the previous implementation of <literal>isolate</literal> could capture a context that has many heap-allocated values reachable from it (because we could evaluate <literal>isolate f</literal> <emphasis>late</emphasis> in the program and <emphasis>deep</emphasis> in a call stack), which would all remain reachable during the evaluation of
17566 <literal>f x</literal>. [We&#8217;ll return to this point later, as it is taking a slightly MLton-esque view of the evaluation of a program, and may not apply as strongly to other implementations (e.g., SML/NJ).]</simpara>
17567 <simpara>Now, once we throw to <literal>base</literal> and begin executing <literal>f x</literal>, only the heap-allocated values reachable from <literal>f</literal> and <literal>x</literal> and the few heap-allocated values reachable from <literal>base</literal> are retained by the garbage collector. So, it seems that <literal>base</literal> <emphasis>works</emphasis> as an empty context.</simpara>
17568 <simpara>But, what about the continuation returned from <literal>isolate f</literal>? Note that the continuation returned by <literal>isolate</literal> is one that receives an argument <literal>x</literal> and then
17569 throws to <literal>base</literal> to evaluate <literal>f x</literal>. If we used a CPS-translation implementation (and assume sufficient beta-contractions to eliminate administrative redexes), then the original continuation passed to <literal>isolate</literal> (i.e., the continuation bound to <literal>k1</literal>) will not be free in the continuation returned by <literal>isolate f</literal>. Rather, the only free variables in the continuation returned by <literal>isolate f</literal> will be <literal>base</literal> and <literal>f</literal>, so the only heap-allocated values reachable from the continuation returned by <literal>isolate f</literal> will be those values reachable from <literal>base</literal> (assumed to be few) and those values reachable from <literal>f</literal> (necessary in order to execute <literal>f</literal> at some later point).</simpara>
17570 <simpara>But, MLton doesn&#8217;t use a CPS-translation implementation. Rather, at each call to <literal>callcc</literal> in the body of <literal>isolate</literal>, MLton will copy the current execution stack. Thus, <literal>k2</literal> (the continuation returned by <literal>isolate f</literal>) will include execution stack at the time of the call to <literal>isolate f</literal>&#8201;&#8212;&#8201;that is, it will include the <emphasis>original</emphasis> continuation of the call to <literal>isolate f</literal>. Thus, the heap-allocated values reachable from the continuation returned by <literal>isolate f</literal> will include those values reachable from <literal>base</literal>, those values reachable from <literal>f</literal>, and those values reachable from the original continuation of the call to <literal>isolate f</literal>. So, just holding on to the continuation returned by <literal>isolate f</literal> will retain all of the heap-allocated values live at the time <literal>isolate f</literal> was called. This leaks space, since, <emphasis>semantically</emphasis>, the
17571 continuation returned by <literal>isolate f</literal> only needs the heap-allocated values reachable from <literal>f</literal> (and <literal>base</literal>).</simpara>
17572 <simpara>In practice, this probably isn&#8217;t a significant issue. A common use of <literal>isolate</literal> is implement <literal>abort</literal>:</simpara>
17573 <programlisting language="sml" linenumbering="unnumbered">fun abort th = throw (isolate th, ())</programlisting>
17574 <simpara>The continuation returned by <literal>isolate th</literal> is dead immediately after being thrown to&#8201;&#8212;&#8201;the continuation isn&#8217;t retained, so neither is the <emphasis>semantic</emphasis>
17575 garbage it would have retained.</simpara>
17576 <simpara>But, it is easy enough to <emphasis>move</emphasis> onto the <emphasis>empty</emphasis> context <literal>base</literal> the capturing of the context that we want to be returned by <literal>isolate f</literal>:</simpara>
17577 <programlisting language="sml" linenumbering="unnumbered">local
17578 val base: (unit -&gt; unit) t =
17579 callcc
17580 (fn k1 =&gt;
17581 let
17582 val th = callcc (fn k2 =&gt; throw (k1, k2))
17583 val _ = (th () ; Exit.topLevelSuffix ())
17584 handle exn =&gt; MLtonExn.topLevelHandler exn
17585 in
17586 raise Fail "MLton.Cont.isolate: return from (wrapped) func"
17587 end)
17588 in
17589 val isolate: ('a -&gt; unit) -&gt; 'a t =
17590 fn (f: 'a -&gt; unit) =&gt;
17591 callcc
17592 (fn k1 =&gt;
17593 throw (base, fn () =&gt;
17594 let
17595 val x = callcc (fn k2 =&gt; throw (k1, k2))
17596 in
17597 throw (base, fn () =&gt; f x)
17598 end))
17599 end</programlisting>
17600 <simpara>This implementation now has the right space behavior; the continuation returned by <literal>isolate f</literal> will only retain the heap-allocated values reachable from <literal>f</literal> and from <literal>base</literal>. (Technically, the continuation will retain two copies of the stack that was in place at the time <literal>base</literal> was evaluated, but we are assuming that that stack small.)</simpara>
17601 <simpara>One minor inefficiency of this implementation (given MLton&#8217;s implementation of continuations) is that every <literal>callcc</literal> and <literal>throw</literal> entails copying a stack (albeit, some of them are small). We can avoid this in the evaluation of <literal>base</literal> by using a reference cell, because <literal>base</literal> is evaluated at the top-level:</simpara>
17602 <programlisting language="sml" linenumbering="unnumbered">local
17603 val base: (unit -&gt; unit) option t =
17604 let
17605 val baseRef: (unit -&gt; unit) option t option ref = ref NONE
17606 val th = callcc (fn k =&gt; (base := SOME k; NONE))
17607 in
17608 case th of
17609 NONE =&gt; (case !baseRef of
17610 NONE =&gt; raise Fail "MLton.Cont.isolate: missing base"
17611 | SOME base =&gt; base)
17612 | SOME th =&gt; let
17613 val _ = (th () ; Exit.topLevelSuffix ())
17614 handle exn =&gt; MLtonExn.topLevelHandler exn
17615 in
17616 raise Fail "MLton.Cont.isolate: return from (wrapped)
17617 func"
17618 end
17619 end
17620 in
17621 val isolate: ('a -&gt; unit) -&gt; 'a t =
17622 fn (f: 'a -&gt; unit) =&gt;
17623 callcc
17624 (fn k1 =&gt;
17625 throw (base, SOME (fn () =&gt;
17626 let
17627 val x = callcc (fn k2 =&gt; throw (k1, k2))
17628 in
17629 throw (base, SOME (fn () =&gt; f x))
17630 end)))
17631 end</programlisting>
17632 <simpara>Now, to evaluate <literal>base</literal>, we only copy the stack once (instead of 3 times). Because we don&#8217;t have a dummy continuation around to initialize the reference cell, the reference cell holds a continuation <literal>option</literal>. To distinguish between the original evaluation of <literal>base</literal> (when we want to return the continuation) and the subsequent evaluations of <literal>base</literal> (when we want to evaluate a thunk), we capture a <literal>(unit -&gt; unit) option</literal> continuation.</simpara>
17633 <simpara>This seems to be as far as we can go without exploiting the concrete implementation of continuations in <link linkend="MLtonCont">MLtonCont</link>. Examining the implementation, we note that the type of
17634 continuations is given by</simpara>
17635 <programlisting language="sml" linenumbering="unnumbered">type 'a t = (unit -&gt; 'a) -&gt; unit</programlisting>
17636 <simpara>and the implementation of <literal>throw</literal> is given by</simpara>
17637 <programlisting language="sml" linenumbering="unnumbered">fun ('a, 'b) throw' (k: 'a t, v: unit -&gt; 'a): 'b =
17638 (k v; raise Fail "MLton.Cont.throw': return from continuation")
17639
17640 fun ('a, 'b) throw (k: 'a t, v: 'a): 'b = throw' (k, fn () =&gt; v)</programlisting>
17641 <simpara>Suffice to say, a continuation is simply a function that accepts a thunk to yield the thrown value and the body of the function performs the actual throw. Using this knowledge, we can create a dummy continuation to initialize <literal>baseRef</literal> and greatly simplify the body of <literal>isolate</literal>:</simpara>
17642 <programlisting language="sml" linenumbering="unnumbered">local
17643 val base: (unit -&gt; unit) option t =
17644 let
17645 val baseRef: (unit -&gt; unit) option t ref =
17646 ref (fn _ =&gt; raise Fail "MLton.Cont.isolate: missing base")
17647 val th = callcc (fn k =&gt; (baseRef := k; NONE))
17648 in
17649 case th of
17650 NONE =&gt; !baseRef
17651 | SOME th =&gt; let
17652 val _ = (th () ; Exit.topLevelSuffix ())
17653 handle exn =&gt; MLtonExn.topLevelHandler exn
17654 in
17655 raise Fail "MLton.Cont.isolate: return from (wrapped)
17656 func"
17657 end
17658 end
17659 in
17660 val isolate: ('a -&gt; unit) -&gt; 'a t =
17661 fn (f: 'a -&gt; unit) =&gt;
17662 fn (v: unit -&gt; 'a) =&gt;
17663 throw (base, SOME (f o v))
17664 end</programlisting>
17665 <simpara>Note that this implementation of <literal>isolate</literal> makes it clear that the continuation returned by <literal>isolate f</literal> only retains the heap-allocated values reachable from <literal>f</literal> and <literal>base</literal>. It also retains only one copy of the stack that was in place at the time <literal>base</literal> was evaluated. Finally, it completely avoids making any copies of the stack that is in place at the time <literal>isolate f</literal> is evaluated; indeed, <literal>isolate f</literal> is a constant-time operation.</simpara>
17666 <simpara>Next, suppose we limited ourselves to capturing <literal>unit</literal> continuations with <literal>callcc</literal>. We can&#8217;t pass the thunk to be evaluated in the <emphasis>empty</emphasis> context directly, but we can use a reference cell.</simpara>
17667 <programlisting language="sml" linenumbering="unnumbered">local
17668 val thRef: (unit -&gt; unit) option ref = ref NONE
17669 val base: unit t =
17670 let
17671 val baseRef: unit t ref =
17672 ref (fn _ =&gt; raise Fail "MLton.Cont.isolate: missing base")
17673 val () = callcc (fn k =&gt; baseRef := k)
17674 in
17675 case !thRef of
17676 NONE =&gt; !baseRef
17677 | SOME th =&gt;
17678 let
17679 val _ = thRef := NONE
17680 val _ = (th () ; Exit.topLevelSuffix ())
17681 handle exn =&gt; MLtonExn.topLevelHandler exn
17682 in
17683 raise Fail "MLton.Cont.isolate: return from (wrapped) func"
17684 end
17685 end
17686 in
17687 val isolate: ('a -&gt; unit) -&gt; 'a t =
17688 fn (f: 'a -&gt; unit) =&gt;
17689 fn (v: unit -&gt; 'a) =&gt;
17690 let
17691 val () = thRef := SOME (f o v)
17692 in
17693 throw (base, ())
17694 end
17695 end</programlisting>
17696 <simpara>Note that it is important to set <literal>thRef</literal> to <literal>NONE</literal> before evaluating the thunk, so that the garbage collector doesn&#8217;t retain all the heap-allocated values reachable from <literal>f</literal> and <literal>v</literal> during the evaluation of <literal>f (v ())</literal>. This is because <literal>thRef</literal> is still live during the evaluation of the thunk; in particular, it was allocated before the evaluation of <literal>base</literal> (and used after), and so is retained by continuation on which the thunk is evaluated.</simpara>
17697 <simpara>This implementation can be easily adapted to use MLton&#8217;s primitive stack copying operations.</simpara>
17698 <programlisting language="sml" linenumbering="unnumbered">local
17699 val thRef: (unit -&gt; unit) option ref = ref NONE
17700 val base: Thread.preThread =
17701 let
17702 val () = Thread.copyCurrent ()
17703 in
17704 case !thRef of
17705 NONE =&gt; Thread.savedPre ()
17706 | SOME th =&gt;
17707 let
17708 val () = thRef := NONE
17709 val _ = (th () ; Exit.topLevelSuffix ())
17710 handle exn =&gt; MLtonExn.topLevelHandler exn
17711 in
17712 raise Fail "MLton.Cont.isolate: return from (wrapped) func"
17713 end
17714 end
17715 in
17716 val isolate: ('a -&gt; unit) -&gt; 'a t =
17717 fn (f: 'a -&gt; unit) =&gt;
17718 fn (v: unit -&gt; 'a) =&gt;
17719 let
17720 val () = thRef := SOME (f o v)
17721 val new = Thread.copy base
17722 in
17723 Thread.switchTo new
17724 end
17725 end</programlisting>
17726 <simpara>In essence, <literal>Thread.copyCurrent</literal> copies the current execution stack and stores it in an implicit reference cell in the runtime system, which is fetchable with <literal>Thread.savedPre</literal>. When we are ready to throw to the isolated function, <literal>Thread.copy</literal> copies the saved execution stack (because the stack is modified in place during execution, we need to retain a pristine copy in case the isolated function itself throws to other isolated functions) and <literal>Thread.switchTo</literal> abandons the current execution stack, installing the newly copied execution stack.</simpara>
17727 <simpara>The actual implementation of <literal>MLton.Cont.isolate</literal> simply adds some <literal>Thread.atomicBegin</literal> and <literal>Thread.atomicEnd</literal> commands, which effectively protect the global <literal>thRef</literal> and accommodate the fact that <literal>Thread.switchTo</literal> does an implicit <literal>Thread.atomicEnd</literal> (used for leaving a signal handler thread).</simpara>
17728 <programlisting language="sml" linenumbering="unnumbered">local
17729 val thRef: (unit -&gt; unit) option ref = ref NONE
17730 val base: Thread.preThread =
17731 let
17732 val () = Thread.copyCurrent ()
17733 in
17734 case !thRef of
17735 NONE =&gt; Thread.savedPre ()
17736 | SOME th =&gt;
17737 let
17738 val () = thRef := NONE
17739 val _ = MLton.atomicEnd (* Match 1 *)
17740 val _ = (th () ; Exit.topLevelSuffix ())
17741 handle exn =&gt; MLtonExn.topLevelHandler exn
17742 in
17743 raise Fail "MLton.Cont.isolate: return from (wrapped) func"
17744 end
17745 end
17746 in
17747 val isolate: ('a -&gt; unit) -&gt; 'a t =
17748 fn (f: 'a -&gt; unit) =&gt;
17749 fn (v: unit -&gt; 'a) =&gt;
17750 let
17751 val _ = MLton.atomicBegin (* Match 1 *)
17752 val () = thRef := SOME (f o v)
17753 val new = Thread.copy base
17754 val _ = MLton.atomicBegin (* Match 2 *)
17755 in
17756 Thread.switchTo new (* Match 2 *)
17757 end
17758 end</programlisting>
17759 <simpara>It is perhaps interesting to note that the above implementation was originally <emphasis>derived</emphasis> by specializing implementations of the <link linkend="MLtonThread">MLtonThread</link> <literal>new</literal>, <literal>prepare</literal>, and <literal>switch</literal> functions as if their only use was in the following implementation of <literal>isolate</literal>:</simpara>
17760 <programlisting language="sml" linenumbering="unnumbered">val isolate: ('a -&gt; unit) -&gt; 'a t =
17761 fn (f: 'a -&gt; unit) =&gt;
17762 fn (v: unit -&gt; 'a) =&gt;
17763 let
17764 val th = (f (v ()) ; Exit.topLevelSuffix ())
17765 handle exn =&gt; MLtonExn.topLevelHandler exn
17766 val t = MLton.Thread.prepare (MLton.Thread.new th, ())
17767 in
17768 MLton.Thread.switch (fn _ =&gt; t)
17769 end</programlisting>
17770 <simpara>It was pleasant to discover that it could equally well be <emphasis>derived</emphasis> starting from the <literal>callcc</literal> and <literal>throw</literal> implementation.</simpara>
17771 <simpara>As a final comment, we noted that the degree to which the context of <literal>base</literal> could be considered <emphasis>empty</emphasis> (i.e., retaining few heap-allocated values) depended upon a slightly MLton-esque view. In particular, MLton does not heap allocate executable code. So, although the <literal>base</literal> context keeps a lot of unevaluated code <emphasis>live</emphasis>, such code is not heap allocated. In a system like SML/NJ, that does heap allocate executable code, one might want it to be the case that after throwing to an isolated function, the garbage collector retains only the code necessary to evaluate the function, and not any code that was necessary to evaluate the <literal>base</literal> context.</simpara>
17772 <simpara><?asciidoc-pagebreak?></simpara>
17773 </section>
17774 <section id="MLtonCross">
17775 <title>MLtonCross</title>
17776 <simpara>The debian package MLton-Cross adds various targets to MLton. In
17777 combination with the emdebian project, this allows a debian system to
17778 compile SML files to other architectures.</simpara>
17779 <simpara>Currently, these targets are supported:</simpara>
17780 <itemizedlist>
17781 <listitem>
17782 <simpara>
17783 <emphasis>Windows (MinGW)</emphasis>
17784 </simpara>
17785 <itemizedlist>
17786 <listitem>
17787 <simpara>
17788 -target i586-mingw32msvc (mlton-target-i586-mingw32msvc)
17789 </simpara>
17790 </listitem>
17791 <listitem>
17792 <simpara>
17793 -target amd64-mingw32msvc( mlton-target-amd64-mingw32msvc)
17794 </simpara>
17795 </listitem>
17796 </itemizedlist>
17797 </listitem>
17798 <listitem>
17799 <simpara>
17800 <emphasis>Linux (Debian)</emphasis>
17801 </simpara>
17802 <itemizedlist>
17803 <listitem>
17804 <simpara>
17805 -target alpha-linux-gnu (mlton-target-alpha-linux-gnu)
17806 </simpara>
17807 </listitem>
17808 <listitem>
17809 <simpara>
17810 -target arm-linux-gnueabi (mlton-target-arm-linux-gnueabi)
17811 </simpara>
17812 </listitem>
17813 <listitem>
17814 <simpara>
17815 -target hppa-linux-gnu (mlton-target-hppa-linux-gnu)
17816 </simpara>
17817 </listitem>
17818 <listitem>
17819 <simpara>
17820 -target i486-linux-gnu (mlton-target-i486-linux-gnu)
17821 </simpara>
17822 </listitem>
17823 <listitem>
17824 <simpara>
17825 -target ia64-linux-gnu (mlton-target-ia64-linux-gnu)
17826 </simpara>
17827 </listitem>
17828 <listitem>
17829 <simpara>
17830 -target mips-linux-gnu (mlton-target-mips-linux-gnu)
17831 </simpara>
17832 </listitem>
17833 <listitem>
17834 <simpara>
17835 -target mipsel-linux-gnu (mlton-target-mipsel-linux-gnu)
17836 </simpara>
17837 </listitem>
17838 <listitem>
17839 <simpara>
17840 -target powerpc-linux-gnu (mlton-target-powerpc-linux-gnu)
17841 </simpara>
17842 </listitem>
17843 <listitem>
17844 <simpara>
17845 -target s390-linux-gnu (mlton-target-s390-linux-gnu)
17846 </simpara>
17847 </listitem>
17848 <listitem>
17849 <simpara>
17850 -target sparc-linux-gnu (mlton-target-sparc-linux-gnu)
17851 </simpara>
17852 </listitem>
17853 <listitem>
17854 <simpara>
17855 -target x86-64-linux-gnu (mlton-target-x86-64-linux-gnu)
17856 </simpara>
17857 </listitem>
17858 </itemizedlist>
17859 </listitem>
17860 </itemizedlist>
17861 <section id="_download_6">
17862 <title>Download</title>
17863 <simpara>MLton-Cross is kept in-sync with the current MLton release.</simpara>
17864 <itemizedlist>
17865 <listitem>
17866 <simpara>
17867 <ulink url="guide/MLtonCross.attachments/mlton-cross_20100608.orig.tar.gz"><literal>mlton-cross_20100608.orig.tar.gz</literal></ulink>
17868 </simpara>
17869 </listitem>
17870 </itemizedlist>
17871 <simpara><?asciidoc-pagebreak?></simpara>
17872 </section>
17873 </section>
17874 <section id="MLtonExn">
17875 <title>MLtonExn</title>
17876 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_EXN =
17877 sig
17878 val addExnMessager: (exn -&gt; string option) -&gt; unit
17879 val history: exn -&gt; string list
17880
17881 val defaultTopLevelHandler: exn -&gt; 'a
17882 val getTopLevelHandler: unit -&gt; (exn -&gt; unit)
17883 val setTopLevelHandler: (exn -&gt; unit) -&gt; unit
17884 val topLevelHandler: exn -&gt; 'a
17885 end</programlisting>
17886 <itemizedlist>
17887 <listitem>
17888 <simpara>
17889 <literal>addExnMessager f</literal>
17890 </simpara>
17891 <simpara>adds <literal>f</literal> as a pretty-printer to be used by <literal>General.exnMessage</literal> for
17892 converting exceptions to strings. Messagers are tried in order from
17893 most recently added to least recently added.</simpara>
17894 </listitem>
17895 <listitem>
17896 <simpara>
17897 <literal>history e</literal>
17898 </simpara>
17899 <simpara>returns call stack at the point that <literal>e</literal> was first raised. Each
17900 element of the list is a file position. The elements are in reverse
17901 chronological order, i.e. the function called last is at the front of
17902 the list.</simpara>
17903 <simpara><literal>history e</literal> will return <literal>[]</literal> unless the program is compiled with
17904 <literal>-const 'Exn.keepHistory true'</literal>.</simpara>
17905 </listitem>
17906 <listitem>
17907 <simpara>
17908 <literal>defaultTopLevelHandler e</literal>
17909 </simpara>
17910 <simpara>function that behaves as the default top level handler; that is, print
17911 out the unhandled exception message for <literal>e</literal> and exit.</simpara>
17912 </listitem>
17913 <listitem>
17914 <simpara>
17915 <literal>getTopLevelHandler ()</literal>
17916 </simpara>
17917 <simpara>get the top level handler.</simpara>
17918 </listitem>
17919 <listitem>
17920 <simpara>
17921 <literal>setTopLevelHandler f</literal>
17922 </simpara>
17923 <simpara>set the top level handler to the function <literal>f</literal>. The function <literal>f</literal>
17924 should not raise an exception or return normally.</simpara>
17925 </listitem>
17926 <listitem>
17927 <simpara>
17928 <literal>topLevelHandler e</literal>
17929 </simpara>
17930 <simpara>behaves as if the top level handler received the exception <literal>e</literal>.</simpara>
17931 </listitem>
17932 </itemizedlist>
17933 <simpara><?asciidoc-pagebreak?></simpara>
17934 </section>
17935 <section id="MLtonFinalizable">
17936 <title>MLtonFinalizable</title>
17937 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_FINALIZABLE =
17938 sig
17939 type 'a t
17940
17941 val addFinalizer: 'a t * ('a -&gt; unit) -&gt; unit
17942 val finalizeBefore: 'a t * 'b t -&gt; unit
17943 val new: 'a -&gt; 'a t
17944 val touch: 'a t -&gt; unit
17945 val withValue: 'a t * ('a -&gt; 'b) -&gt; 'b
17946 end</programlisting>
17947 <simpara>A <emphasis>finalizable</emphasis> value is a container to which finalizers can be
17948 attached. A container holds a value, which is reachable as long as
17949 the container itself is reachable. A <emphasis>finalizer</emphasis> is a function that
17950 runs at some point after garbage collection determines that the
17951 container to which it is attached has become
17952 <link linkend="Reachability">unreachable</link>. A finalizer is treated like a signal
17953 handler, in that it runs asynchronously in a separate thread, with
17954 signals blocked, and will not interrupt a critical section (see
17955 <link linkend="MLtonThread">MLtonThread</link>).</simpara>
17956 <itemizedlist>
17957 <listitem>
17958 <simpara>
17959 <literal>addFinalizer (v, f)</literal>
17960 </simpara>
17961 <simpara>adds <literal>f</literal> as a finalizer to <literal>v</literal>. This means that sometime after the
17962 last call to <literal>withValue</literal> on <literal>v</literal> completes and <literal>v</literal> becomes unreachable,
17963 <literal>f</literal> will be called with the value of <literal>v</literal>.</simpara>
17964 </listitem>
17965 <listitem>
17966 <simpara>
17967 <literal>finalizeBefore (v1, v2)</literal>
17968 </simpara>
17969 <simpara>ensures that <literal>v1</literal> will be finalized before <literal>v2</literal>. A cycle of values
17970 <literal>v</literal> = <literal>v1</literal>, &#8230;, <literal>vn</literal> = <literal>v</literal> with <literal>finalizeBefore (vi, vi+1)</literal> will
17971 result in none of the <literal>vi</literal> being finalized.</simpara>
17972 </listitem>
17973 <listitem>
17974 <simpara>
17975 <literal>new x</literal>
17976 </simpara>
17977 <simpara>creates a new finalizable value, <literal>v</literal>, with value <literal>x</literal>. The finalizers
17978 of <literal>v</literal> will run sometime after the last call to <literal>withValue</literal> on <literal>v</literal>
17979 when the garbage collector determines that <literal>v</literal> is unreachable.</simpara>
17980 </listitem>
17981 <listitem>
17982 <simpara>
17983 <literal>touch v</literal>
17984 </simpara>
17985 <simpara>ensures that <literal>v</literal>'s finalizers will not run before the call to <literal>touch</literal>.</simpara>
17986 </listitem>
17987 <listitem>
17988 <simpara>
17989 <literal>withValue (v, f)</literal>
17990 </simpara>
17991 <simpara>returns the result of applying <literal>f</literal> to the value of <literal>v</literal> and ensures
17992 that <literal>v</literal>'s finalizers will not run before <literal>f</literal> completes. The call to
17993 <literal>f</literal> is a nontail call.</simpara>
17994 </listitem>
17995 </itemizedlist>
17996 <section id="_example_4">
17997 <title>Example</title>
17998 <simpara>Suppose that <literal>finalizable.sml</literal> contains the following:</simpara>
17999 <programlisting language="sml" linenumbering="unnumbered">signature CLIST =
18000 sig
18001 type t
18002
18003 val cons: int * t -&gt; t
18004 val sing: int -&gt; t
18005 val sum: t -&gt; int
18006 end
18007
18008 functor CList (structure F: MLTON_FINALIZABLE
18009 structure P: MLTON_POINTER
18010 structure Prim:
18011 sig
18012 val cons: int * P.t -&gt; P.t
18013 val free: P.t -&gt; unit
18014 val sing: int -&gt; P.t
18015 val sum: P.t -&gt; int
18016 end): CLIST =
18017 struct
18018 type t = P.t F.t
18019
18020 fun cons (n: int, l: t) =
18021 F.withValue
18022 (l, fn w' =&gt;
18023 let
18024 val c = F.new (Prim.cons (n, w'))
18025 val _ = F.addFinalizer (c, Prim.free)
18026 val _ = F.finalizeBefore (c, l)
18027 in
18028 c
18029 end)
18030
18031 fun sing n =
18032 let
18033 val c = F.new (Prim.sing n)
18034 val _ = F.addFinalizer (c, Prim.free)
18035 in
18036 c
18037 end
18038
18039 fun sum c = F.withValue (c, Prim.sum)
18040 end
18041
18042 functor Test (structure CList: CLIST
18043 structure MLton: sig
18044 structure GC:
18045 sig
18046 val collect: unit -&gt; unit
18047 end
18048 end) =
18049 struct
18050 fun f n =
18051 if n = 1
18052 then ()
18053 else
18054 let
18055 val a = Array.tabulate (n, fn i =&gt; i)
18056 val _ = Array.sub (a, 0) + Array.sub (a, 1)
18057 in
18058 f (n - 1)
18059 end
18060
18061 val l = CList.sing 2
18062 val l = CList.cons (2,l)
18063 val l = CList.cons (2,l)
18064 val l = CList.cons (2,l)
18065 val l = CList.cons (2,l)
18066 val l = CList.cons (2,l)
18067 val l = CList.cons (2,l)
18068 val _ = MLton.GC.collect ()
18069 val _ = f 100
18070 val _ = print (concat ["listSum(l) = ",
18071 Int.toString (CList.sum l),
18072 "\n"])
18073 val _ = MLton.GC.collect ()
18074 val _ = f 100
18075 end
18076
18077 structure CList =
18078 CList (structure F = MLton.Finalizable
18079 structure P = MLton.Pointer
18080 structure Prim =
18081 struct
18082 val cons = _import "listCons": int * P.t -&gt; P.t;
18083 val free = _import "listFree": P.t -&gt; unit;
18084 val sing = _import "listSing": int -&gt; P.t;
18085 val sum = _import "listSum": P.t -&gt; int;
18086 end)
18087
18088 structure S = Test (structure CList = CList
18089 structure MLton = MLton)</programlisting>
18090 <simpara>Suppose that <literal>cons.c</literal> contains the following.</simpara>
18091 <programlisting language="c" linenumbering="unnumbered">#include &lt;stdio.h&gt;
18092
18093 typedef unsigned int uint;
18094
18095 typedef struct Cons {
18096 struct Cons *next;
18097 int value;
18098 } *Cons;
18099
18100 Cons listCons (int n, Cons c) {
18101 Cons res;
18102
18103 res = (Cons) malloc (sizeof(*res));
18104 fprintf (stderr, "0x%08x = listCons (%d)\n", (uint)res, n);
18105 res-&gt;next = c;
18106 res-&gt;value = n;
18107 return res;
18108 }
18109
18110 Cons listSing (int n) {
18111 Cons res;
18112
18113 res = (Cons) malloc (sizeof(*res));
18114 fprintf (stderr, "0x%08x = listSing (%d)\n", (uint)res, n);
18115 res-&gt;next = NULL;
18116 res-&gt;value = n;
18117 return res;
18118 }
18119
18120 void listFree (Cons p) {
18121 fprintf (stderr, "listFree (0x%08x)\n", (uint)p);
18122 free (p);
18123 }
18124
18125 int listSum (Cons c) {
18126 int res;
18127
18128 fprintf (stderr, "listSum\n");
18129 res = 0;
18130 for (; c != NULL; c = c-&gt;next)
18131 res += c-&gt;value;
18132 return res;
18133 }</programlisting>
18134 <simpara>We can compile these to create an executable with</simpara>
18135 <screen>% mlton -default-ann 'allowFFI true' finalizable.sml cons.c</screen>
18136 <simpara>Running this executable will create output like the following.</simpara>
18137 <screen>% finalizable
18138 0x08072890 = listSing (2)
18139 0x080728a0 = listCons (2)
18140 0x080728b0 = listCons (2)
18141 0x080728c0 = listCons (2)
18142 0x080728d0 = listCons (2)
18143 0x080728e0 = listCons (2)
18144 0x080728f0 = listCons (2)
18145 listSum
18146 listSum(l) = 14
18147 listFree (0x080728f0)
18148 listFree (0x080728e0)
18149 listFree (0x080728d0)
18150 listFree (0x080728c0)
18151 listFree (0x080728b0)
18152 listFree (0x080728a0)
18153 listFree (0x08072890)</screen>
18154 </section>
18155 <section id="_synchronous_finalizers">
18156 <title>Synchronous Finalizers</title>
18157 <simpara>Finalizers in MLton are asynchronous. That is, they run at an
18158 unspecified time, interrupting the user program. It is also possible,
18159 and sometimes useful, to have synchronous finalizers, where the user
18160 program explicitly decides when to run enabled finalizers. We have
18161 considered this in MLton, and it seems possible, but there are some
18162 unresolved design issues. See the thread at</simpara>
18163 <itemizedlist>
18164 <listitem>
18165 <simpara>
18166 <ulink url="http://www.mlton.org/pipermail/mlton/2004-September/016570.html">http://www.mlton.org/pipermail/mlton/2004-September/016570.html</ulink>
18167 </simpara>
18168 </listitem>
18169 </itemizedlist>
18170 </section>
18171 <section id="_also_see_16">
18172 <title>Also see</title>
18173 <itemizedlist>
18174 <listitem>
18175 <simpara>
18176 <link linkend="References_Boehm03">Boehm03</link>
18177 </simpara>
18178 </listitem>
18179 </itemizedlist>
18180 <simpara><?asciidoc-pagebreak?></simpara>
18181 </section>
18182 </section>
18183 <section id="MLtonGC">
18184 <title>MLtonGC</title>
18185 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_GC =
18186 sig
18187 val collect: unit -&gt; unit
18188 val pack: unit -&gt; unit
18189 val setMessages: bool -&gt; unit
18190 val setSummary: bool -&gt; unit
18191 val unpack: unit -&gt; unit
18192 structure Statistics :
18193 sig
18194 val bytesAllocated: unit -&gt; IntInf.int
18195 val lastBytesLive: unit -&gt; IntInf.int
18196 val numCopyingGCs: unit -&gt; IntInf.int
18197 val numMarkCompactGCs: unit -&gt; IntInf.int
18198 val numMinorGCs: unit -&gt; IntInf.int
18199 val maxBytesLive: unit -&gt; IntInf.int
18200 end
18201 end</programlisting>
18202 <itemizedlist>
18203 <listitem>
18204 <simpara>
18205 <literal>collect ()</literal>
18206 </simpara>
18207 <simpara>causes a garbage collection to occur.</simpara>
18208 </listitem>
18209 <listitem>
18210 <simpara>
18211 <literal>pack ()</literal>
18212 </simpara>
18213 <simpara>shrinks the heap as much as possible so that other processes can use
18214 available RAM.</simpara>
18215 </listitem>
18216 <listitem>
18217 <simpara>
18218 <literal>setMessages b</literal>
18219 </simpara>
18220 <simpara>controls whether diagnostic messages are printed at the beginning and
18221 end of each garbage collection. It is the same as the <literal>gc-messages</literal>
18222 runtime system option.</simpara>
18223 </listitem>
18224 <listitem>
18225 <simpara>
18226 <literal>setSummary b</literal>
18227 </simpara>
18228 <simpara>controls whether a summary of garbage collection statistics is printed
18229 upon termination of the program. It is the same as the <literal>gc-summary</literal>
18230 runtime system option.</simpara>
18231 </listitem>
18232 <listitem>
18233 <simpara>
18234 <literal>unpack ()</literal>
18235 </simpara>
18236 <simpara>resizes a packed heap to the size desired by the runtime.</simpara>
18237 </listitem>
18238 <listitem>
18239 <simpara>
18240 <literal>Statistics.bytesAllocated ()</literal>
18241 </simpara>
18242 <simpara>returns bytes allocated (as of the most recent garbage collection).</simpara>
18243 </listitem>
18244 <listitem>
18245 <simpara>
18246 <literal>Statistics.lastBytesLive ()</literal>
18247 </simpara>
18248 <simpara>returns bytes live (as of the most recent garbage collection).</simpara>
18249 </listitem>
18250 <listitem>
18251 <simpara>
18252 <literal>Statistics.numCopyingGCs ()</literal>
18253 </simpara>
18254 <simpara>returns number of (major) copying garbage collections performed (as of
18255 the most recent garbage collection).</simpara>
18256 </listitem>
18257 <listitem>
18258 <simpara>
18259 <literal>Statistics.numMarkCompactGCs ()</literal>
18260 </simpara>
18261 <simpara>returns number of (major) mark-compact garbage collections performed
18262 (as of the most recent garbage collection).</simpara>
18263 </listitem>
18264 <listitem>
18265 <simpara>
18266 <literal>Statistics.numMinorGCs ()</literal>
18267 </simpara>
18268 <simpara>returns number of minor garbage collections performed (as of the most
18269 recent garbage collection).</simpara>
18270 </listitem>
18271 <listitem>
18272 <simpara>
18273 <literal>Statistics.maxBytesLive ()</literal>
18274 </simpara>
18275 <simpara>returns maximum bytes live (as of the most recent garbage collection).</simpara>
18276 </listitem>
18277 </itemizedlist>
18278 <simpara><?asciidoc-pagebreak?></simpara>
18279 </section>
18280 <section id="MLtonIntInf">
18281 <title>MLtonIntInf</title>
18282 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_INT_INF =
18283 sig
18284 type t = IntInf.int
18285
18286 val areSmall: t * t -&gt; bool
18287 val gcd: t * t -&gt; t
18288 val isSmall: t -&gt; bool
18289
18290 structure BigWord : WORD
18291 structure SmallInt : INTEGER
18292 datatype rep =
18293 Big of BigWord.word vector
18294 | Small of SmallInt.int
18295 val rep: t -&gt; rep
18296 val fromRep : rep -&gt; t option
18297 end</programlisting>
18298 <simpara>MLton represents an arbitrary precision integer either as an unboxed
18299 word with the bottom bit set to 1 and the top bits representing a
18300 small signed integer, or as a pointer to a vector of words, where the
18301 first word indicates the sign and the rest are the limbs of a
18302 <link linkend="GnuMP">GnuMP</link> big integer.</simpara>
18303 <itemizedlist>
18304 <listitem>
18305 <simpara>
18306 <literal>type t</literal>
18307 </simpara>
18308 <simpara>the same as type <literal>IntInf.int</literal>.</simpara>
18309 </listitem>
18310 <listitem>
18311 <simpara>
18312 <literal>areSmall (a, b)</literal>
18313 </simpara>
18314 <simpara>returns true iff both <literal>a</literal> and <literal>b</literal> are small.</simpara>
18315 </listitem>
18316 <listitem>
18317 <simpara>
18318 <literal>gcd (a, b)</literal>
18319 </simpara>
18320 <simpara>uses the <link linkend="GnuMP">GnuMP&#8217;s</link> fast gcd implementation.</simpara>
18321 </listitem>
18322 <listitem>
18323 <simpara>
18324 <literal>isSmall a</literal>
18325 </simpara>
18326 <simpara>returns true iff <literal>a</literal> is small.</simpara>
18327 </listitem>
18328 <listitem>
18329 <simpara>
18330 <literal>BigWord : WORD</literal>
18331 </simpara>
18332 <simpara>representation of a big <literal>IntInf.int</literal> as a vector of words; on 32-bit
18333 platforms, <literal>BigWord</literal> is likely to be equivalent to <literal>Word32</literal>, and on
18334 64-bit platforms, <literal>BigWord</literal> is likely to be equivalent to <literal>Word64</literal>.</simpara>
18335 </listitem>
18336 <listitem>
18337 <simpara>
18338 <literal>SmallInt : INTEGER</literal>
18339 </simpara>
18340 <simpara>representation of a small <literal>IntInf.int</literal> as a signed integer; on 32-bit
18341 platforms, <literal>SmallInt</literal> is likely to be equivalent to <literal>Int32</literal>, and on
18342 64-bit platforms, <literal>SmallInt</literal> is likely to be equivalent to <literal>Int64</literal>.</simpara>
18343 </listitem>
18344 <listitem>
18345 <simpara>
18346 <literal>datatype rep</literal>
18347 </simpara>
18348 <simpara>the underlying representation of an <literal>IntInf.int</literal>.</simpara>
18349 </listitem>
18350 <listitem>
18351 <simpara>
18352 <literal>rep i</literal>
18353 </simpara>
18354 <simpara>returns the underlying representation of <literal>i</literal>.</simpara>
18355 </listitem>
18356 <listitem>
18357 <simpara>
18358 <literal>fromRep r</literal>
18359 </simpara>
18360 <simpara>converts from the underlying representation back to an <literal>IntInf.int</literal>.
18361 If <literal>fromRep r</literal> is given anything besides the valid result of <literal>rep i</literal>
18362 for some <literal>i</literal>, this function call will return <literal>NONE</literal>.</simpara>
18363 </listitem>
18364 </itemizedlist>
18365 <simpara><?asciidoc-pagebreak?></simpara>
18366 </section>
18367 <section id="MLtonIO">
18368 <title>MLtonIO</title>
18369 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_IO =
18370 sig
18371 type instream
18372 type outstream
18373
18374 val inFd: instream -&gt; Posix.IO.file_desc
18375 val mkstemp: string -&gt; string * outstream
18376 val mkstemps: {prefix: string, suffix: string} -&gt; string * outstream
18377 val newIn: Posix.IO.file_desc * string -&gt; instream
18378 val newOut: Posix.IO.file_desc * string -&gt; outstream
18379 val outFd: outstream -&gt; Posix.IO.file_desc
18380 val tempPrefix: string -&gt; string
18381 end</programlisting>
18382 <itemizedlist>
18383 <listitem>
18384 <simpara>
18385 <literal>inFd ins</literal>
18386 </simpara>
18387 <simpara>returns the file descriptor corresponding to <literal>ins</literal>.</simpara>
18388 </listitem>
18389 <listitem>
18390 <simpara>
18391 <literal>mkstemp s</literal>
18392 </simpara>
18393 <simpara>like the C <literal>mkstemp</literal> function, generates and open a temporary file
18394 with prefix <literal>s</literal>.</simpara>
18395 </listitem>
18396 <listitem>
18397 <simpara>
18398 <literal>mkstemps {prefix, suffix}</literal>
18399 </simpara>
18400 <simpara>like <literal>mkstemp</literal>, except it has both a prefix and suffix.</simpara>
18401 </listitem>
18402 <listitem>
18403 <simpara>
18404 <literal>newIn (fd, name)</literal>
18405 </simpara>
18406 <simpara>creates a new instream from file descriptor <literal>fd</literal>, with <literal>name</literal> used in
18407 any <literal>Io</literal> exceptions later raised.</simpara>
18408 </listitem>
18409 <listitem>
18410 <simpara>
18411 <literal>newOut (fd, name)</literal>
18412 </simpara>
18413 <simpara>creates a new outstream from file descriptor <literal>fd</literal>, with <literal>name</literal> used in
18414 any <literal>Io</literal> exceptions later raised.</simpara>
18415 </listitem>
18416 <listitem>
18417 <simpara>
18418 <literal>outFd out</literal>
18419 </simpara>
18420 <simpara>returns the file descriptor corresponding to <literal>out</literal>.</simpara>
18421 </listitem>
18422 <listitem>
18423 <simpara>
18424 <literal>tempPrefix s</literal>
18425 </simpara>
18426 <simpara>adds a suitable system or user specific prefix (directory) for temp
18427 files.</simpara>
18428 </listitem>
18429 </itemizedlist>
18430 <simpara><?asciidoc-pagebreak?></simpara>
18431 </section>
18432 <section id="MLtonItimer">
18433 <title>MLtonItimer</title>
18434 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_ITIMER =
18435 sig
18436 datatype t =
18437 Prof
18438 | Real
18439 | Virtual
18440
18441 val set: t * {interval: Time.time, value: Time.time} -&gt; unit
18442 val signal: t -&gt; Posix.Signal.signal
18443 end</programlisting>
18444 <itemizedlist>
18445 <listitem>
18446 <simpara>
18447 <literal>set (t, {interval, value})</literal>
18448 </simpara>
18449 <simpara>sets the interval timer (using <literal>setitimer</literal>) specified by <literal>t</literal> to the
18450 given <literal>interval</literal> and <literal>value</literal>.</simpara>
18451 </listitem>
18452 <listitem>
18453 <simpara>
18454 <literal>signal t</literal>
18455 </simpara>
18456 <simpara>returns the signal corresponding to <literal>t</literal>.</simpara>
18457 </listitem>
18458 </itemizedlist>
18459 <simpara><?asciidoc-pagebreak?></simpara>
18460 </section>
18461 <section id="MLtonLibraryProject">
18462 <title>MLtonLibraryProject</title>
18463 <simpara>We have a <ulink url="https://github.com/MLton/mltonlib">MLton Library repository</ulink>
18464 that is intended to collect libraries.</simpara>
18465 <informalexample>
18466 <literallayout class="monospaced">https://github.com/MLton/mltonlib</literallayout>
18467 </informalexample>
18468 <simpara>Libraries are kept in the <literal>master</literal> branch, and are grouped according
18469 to domain name, in the Java package style. For example,
18470 <link linkend="VesaKarvonen">VesaKarvonen</link>, who works at <literal>ssh.com</literal>, has been putting code at:</simpara>
18471 <informalexample>
18472 <literallayout class="monospaced">https://github.com/MLton/mltonlib/tree/master/com/ssh</literallayout>
18473 </informalexample>
18474 <simpara><link linkend="StephenWeeks">StephenWeeks</link>, owning <literal>sweeks.com</literal>, has been putting code at:</simpara>
18475 <informalexample>
18476 <literallayout class="monospaced">https://github.com/MLton/mltonlib/tree/master/com/sweeks</literallayout>
18477 </informalexample>
18478 <simpara>A "library" is a subdirectory of some such directory. For example,
18479 Stephen&#8217;s basis-library replacement library is at</simpara>
18480 <informalexample>
18481 <literallayout class="monospaced">https://github.com/MLton/mltonlib/tree/master/com/sweeks/basic</literallayout>
18482 </informalexample>
18483 <simpara>We use "transparent per-library branching" to handle library
18484 versioning. Each library has an "unstable" subdirectory in which work
18485 happens. When one is happy with a library, one tags it by copying it
18486 to a stable version directory. Stable libraries are immutable&#8201;&#8212;&#8201;when
18487 one refers to a stable library, one always gets exactly the same code.
18488 No one has actually made a stable library yet, but, when I&#8217;m ready to
18489 tag my library, I was thinking that I would do something like copying</simpara>
18490 <informalexample>
18491 <literallayout class="monospaced">https://github.com/MLton/mltonlib/tree/master/com/sweeks/basic/unstable</literallayout>
18492 </informalexample>
18493 <simpara>to</simpara>
18494 <informalexample>
18495 <literallayout class="monospaced">https://github.com/MLton/mltonlib/tree/master/com/sweeks/basic/v1</literallayout>
18496 </informalexample>
18497 <simpara>So far, libraries in the MLton repository have been licensed under
18498 MLton&#8217;s <link linkend="License">License</link>. We haven&#8217;t decided on whether that will be a
18499 requirement to be in the repository or not. For the sake of
18500 simplicity (a single license) and encouraging widest use of code,
18501 contributors are encouraged to use that license. But it may be too
18502 strict to require it.</simpara>
18503 <simpara>If someone wants to contribute a new library to our repository or to
18504 work on an old one, they can make a pull request. If people want to
18505 work in their own repository, they can do so&#8201;&#8212;&#8201;that&#8217;s the point of
18506 using domain names to prevent clashes. The idea is that a user should
18507 be able to bring library collections in from many different
18508 repositories without problems. And those libraries could even work
18509 with each other.</simpara>
18510 <simpara>At some point we may want to settle on an <link linkend="MLBasisPathMap">MLBasisPathMap</link> variable
18511 for the root of the library project. Or, we could reuse <literal>SML_LIB</literal>,
18512 and migrate what we currently keep there into the library
18513 infrastructure.</simpara>
18514 <simpara><?asciidoc-pagebreak?></simpara>
18515 </section>
18516 <section id="MLtonMonoArray">
18517 <title>MLtonMonoArray</title>
18518 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_MONO_ARRAY =
18519 sig
18520 type t
18521 type elem
18522 val fromPoly: elem array -&gt; t
18523 val toPoly: t -&gt; elem array
18524 end</programlisting>
18525 <itemizedlist>
18526 <listitem>
18527 <simpara>
18528 <literal>type t</literal>
18529 </simpara>
18530 <simpara>type of monomorphic array</simpara>
18531 </listitem>
18532 <listitem>
18533 <simpara>
18534 <literal>type elem</literal>
18535 </simpara>
18536 <simpara>type of array elements</simpara>
18537 </listitem>
18538 <listitem>
18539 <simpara>
18540 <literal>fromPoly a</literal>
18541 </simpara>
18542 <simpara>type cast a polymorphic array to its monomorphic counterpart; the
18543 argument and result arrays share the same identity</simpara>
18544 </listitem>
18545 <listitem>
18546 <simpara>
18547 <literal>toPoly a</literal>
18548 </simpara>
18549 <simpara>type cast a monomorphic array to its polymorphic counterpart; the
18550 argument and result arrays share the same identity</simpara>
18551 </listitem>
18552 </itemizedlist>
18553 <simpara><?asciidoc-pagebreak?></simpara>
18554 </section>
18555 <section id="MLtonMonoVector">
18556 <title>MLtonMonoVector</title>
18557 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_MONO_VECTOR =
18558 sig
18559 type t
18560 type elem
18561 val fromPoly: elem vector -&gt; t
18562 val toPoly: t -&gt; elem vector
18563 end</programlisting>
18564 <itemizedlist>
18565 <listitem>
18566 <simpara>
18567 <literal>type t</literal>
18568 </simpara>
18569 <simpara>type of monomorphic vector</simpara>
18570 </listitem>
18571 <listitem>
18572 <simpara>
18573 <literal>type elem</literal>
18574 </simpara>
18575 <simpara>type of vector elements</simpara>
18576 </listitem>
18577 <listitem>
18578 <simpara>
18579 <literal>fromPoly v</literal>
18580 </simpara>
18581 <simpara>type cast a polymorphic vector to its monomorphic counterpart; in
18582 MLton, this is a constant-time operation</simpara>
18583 </listitem>
18584 <listitem>
18585 <simpara>
18586 <literal>toPoly v</literal>
18587 </simpara>
18588 <simpara>type cast a monomorphic vector to its polymorphic counterpart; in
18589 MLton, this is a constant-time operation</simpara>
18590 </listitem>
18591 </itemizedlist>
18592 <simpara><?asciidoc-pagebreak?></simpara>
18593 </section>
18594 <section id="MLtonPlatform">
18595 <title>MLtonPlatform</title>
18596 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_PLATFORM =
18597 sig
18598 structure Arch:
18599 sig
18600 datatype t = Alpha | AMD64 | ARM | ARM64 | HPPA | IA64 | m68k
18601 | MIPS | PowerPC | PowerPC64 | S390 | Sparc | X86
18602
18603 val fromString: string -&gt; t option
18604 val host: t
18605 val toString: t -&gt; string
18606 end
18607
18608 structure OS:
18609 sig
18610 datatype t = AIX | Cygwin | Darwin | FreeBSD | Hurd | HPUX
18611 | Linux | MinGW | NetBSD | OpenBSD | Solaris
18612
18613 val fromString: string -&gt; t option
18614 val host: t
18615 val toString: t -&gt; string
18616 end
18617 end</programlisting>
18618 <itemizedlist>
18619 <listitem>
18620 <simpara>
18621 <literal>datatype Arch.t</literal>
18622 </simpara>
18623 <simpara>processor architectures</simpara>
18624 </listitem>
18625 <listitem>
18626 <simpara>
18627 <literal>Arch.fromString a</literal>
18628 </simpara>
18629 <simpara>converts from string to architecture. Case insensitive.</simpara>
18630 </listitem>
18631 <listitem>
18632 <simpara>
18633 <literal>Arch.host</literal>
18634 </simpara>
18635 <simpara>the architecture for which the program is compiled.</simpara>
18636 </listitem>
18637 <listitem>
18638 <simpara>
18639 <literal>Arch.toString</literal>
18640 </simpara>
18641 <simpara>string for architecture.</simpara>
18642 </listitem>
18643 <listitem>
18644 <simpara>
18645 <literal>datatype OS.t</literal>
18646 </simpara>
18647 <simpara>operating systems</simpara>
18648 </listitem>
18649 <listitem>
18650 <simpara>
18651 <literal>OS.fromString</literal>
18652 </simpara>
18653 <simpara>converts from string to operating system. Case insensitive.</simpara>
18654 </listitem>
18655 <listitem>
18656 <simpara>
18657 <literal>OS.host</literal>
18658 </simpara>
18659 <simpara>the operating system for which the program is compiled.</simpara>
18660 </listitem>
18661 <listitem>
18662 <simpara>
18663 <literal>OS.toString</literal>
18664 </simpara>
18665 <simpara>string for operating system.</simpara>
18666 </listitem>
18667 </itemizedlist>
18668 <simpara><?asciidoc-pagebreak?></simpara>
18669 </section>
18670 <section id="MLtonPointer">
18671 <title>MLtonPointer</title>
18672 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_POINTER =
18673 sig
18674 eqtype t
18675
18676 val add: t * word -&gt; t
18677 val compare: t * t -&gt; order
18678 val diff: t * t -&gt; word
18679 val getInt8: t * int -&gt; Int8.int
18680 val getInt16: t * int -&gt; Int16.int
18681 val getInt32: t * int -&gt; Int32.int
18682 val getInt64: t * int -&gt; Int64.int
18683 val getPointer: t * int -&gt; t
18684 val getReal32: t * int -&gt; Real32.real
18685 val getReal64: t * int -&gt; Real64.real
18686 val getWord8: t * int -&gt; Word8.word
18687 val getWord16: t * int -&gt; Word16.word
18688 val getWord32: t * int -&gt; Word32.word
18689 val getWord64: t * int -&gt; Word64.word
18690 val null: t
18691 val setInt8: t * int * Int8.int -&gt; unit
18692 val setInt16: t * int * Int16.int -&gt; unit
18693 val setInt32: t * int * Int32.int -&gt; unit
18694 val setInt64: t * int * Int64.int -&gt; unit
18695 val setPointer: t * int * t -&gt; unit
18696 val setReal32: t * int * Real32.real -&gt; unit
18697 val setReal64: t * int * Real64.real -&gt; unit
18698 val setWord8: t * int * Word8.word -&gt; unit
18699 val setWord16: t * int * Word16.word -&gt; unit
18700 val setWord32: t * int * Word32.word -&gt; unit
18701 val setWord64: t * int * Word64.word -&gt; unit
18702 val sizeofPointer: word
18703 val sub: t * word -&gt; t
18704 end</programlisting>
18705 <itemizedlist>
18706 <listitem>
18707 <simpara>
18708 <literal>eqtype t</literal>
18709 </simpara>
18710 <simpara>the type of pointers, i.e. machine addresses.</simpara>
18711 </listitem>
18712 <listitem>
18713 <simpara>
18714 <literal>add (p, w)</literal>
18715 </simpara>
18716 <simpara>returns the pointer <literal>w</literal> bytes after than <literal>p</literal>. Does not check for
18717 overflow.</simpara>
18718 </listitem>
18719 <listitem>
18720 <simpara>
18721 <literal>compare (p1, p2)</literal>
18722 </simpara>
18723 <simpara>compares the pointer <literal>p1</literal> to the pointer <literal>p2</literal> (as addresses).</simpara>
18724 </listitem>
18725 <listitem>
18726 <simpara>
18727 <literal>diff (p1, p2)</literal>
18728 </simpara>
18729 <simpara>returns the number of bytes <literal>w</literal> such that <literal>add (p2, w) = p1</literal>. Does
18730 not check for overflow.</simpara>
18731 </listitem>
18732 <listitem>
18733 <simpara>
18734 <literal>get<emphasis>&lt;X&gt;</emphasis> (p, i)</literal>
18735 </simpara>
18736 <simpara>returns the object stored at index i of the array of <emphasis>X</emphasis> objects
18737 pointed to by <literal>p</literal>. For example, <literal>getWord32 (p, 7)</literal> returns the 32-bit
18738 word stored 28 bytes beyond <literal>p</literal>.</simpara>
18739 </listitem>
18740 <listitem>
18741 <simpara>
18742 <literal>null</literal>
18743 </simpara>
18744 <simpara>the null pointer, i.e. 0.</simpara>
18745 </listitem>
18746 <listitem>
18747 <simpara>
18748 <literal>set<emphasis>&lt;X&gt;</emphasis> (p, i, v)</literal>
18749 </simpara>
18750 <simpara>assigns <literal>v</literal> to the object stored at index i of the array of <emphasis>X</emphasis>
18751 objects pointed to by <literal>p</literal>. For example, <literal>setWord32 (p, 7, w)</literal> stores
18752 the 32-bit word <literal>w</literal> at the address 28 bytes beyond <literal>p</literal>.</simpara>
18753 </listitem>
18754 <listitem>
18755 <simpara>
18756 <literal>sizeofPointer</literal>
18757 </simpara>
18758 <simpara>size, in bytes, of a pointer.</simpara>
18759 </listitem>
18760 <listitem>
18761 <simpara>
18762 <literal>sub (p, w)</literal>
18763 </simpara>
18764 <simpara>returns the pointer <literal>w</literal> bytes before <literal>p</literal>. Does not check for
18765 overflow.</simpara>
18766 </listitem>
18767 </itemizedlist>
18768 <simpara><?asciidoc-pagebreak?></simpara>
18769 </section>
18770 <section id="MLtonProcEnv">
18771 <title>MLtonProcEnv</title>
18772 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_PROC_ENV =
18773 sig
18774 type gid
18775
18776 val setenv: {name: string, value: string} -&gt; unit
18777 val setgroups: gid list -&gt; unit
18778 end</programlisting>
18779 <itemizedlist>
18780 <listitem>
18781 <simpara>
18782 <literal>setenv {name, value}</literal>
18783 </simpara>
18784 <simpara>like the C <literal>setenv</literal> function. Does not require <literal>name</literal> or <literal>value</literal> to
18785 be null terminated.</simpara>
18786 </listitem>
18787 <listitem>
18788 <simpara>
18789 <literal>setgroups grps</literal>
18790 </simpara>
18791 <simpara>like the C <literal>setgroups</literal> function.</simpara>
18792 </listitem>
18793 </itemizedlist>
18794 <simpara><?asciidoc-pagebreak?></simpara>
18795 </section>
18796 <section id="MLtonProcess">
18797 <title>MLtonProcess</title>
18798 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_PROCESS =
18799 sig
18800 type pid
18801
18802 val spawn: {args: string list, path: string} -&gt; pid
18803 val spawne: {args: string list, env: string list, path: string} -&gt; pid
18804 val spawnp: {args: string list, file: string} -&gt; pid
18805
18806 type ('stdin, 'stdout, 'stderr) t
18807
18808 type input
18809 type output
18810
18811 type none
18812 type chain
18813 type any
18814
18815 exception MisuseOfForget
18816 exception DoublyRedirected
18817
18818 structure Child:
18819 sig
18820 type ('use, 'dir) t
18821
18822 val binIn: (BinIO.instream, input) t -&gt; BinIO.instream
18823 val binOut: (BinIO.outstream, output) t -&gt; BinIO.outstream
18824 val fd: (Posix.FileSys.file_desc, 'dir) t -&gt; Posix.FileSys.file_desc
18825 val remember: (any, 'dir) t -&gt; ('use, 'dir) t
18826 val textIn: (TextIO.instream, input) t -&gt; TextIO.instream
18827 val textOut: (TextIO.outstream, output) t -&gt; TextIO.outstream
18828 end
18829
18830 structure Param:
18831 sig
18832 type ('use, 'dir) t
18833
18834 val child: (chain, 'dir) Child.t -&gt; (none, 'dir) t
18835 val fd: Posix.FileSys.file_desc -&gt; (none, 'dir) t
18836 val file: string -&gt; (none, 'dir) t
18837 val forget: ('use, 'dir) t -&gt; (any, 'dir) t
18838 val null: (none, 'dir) t
18839 val pipe: ('use, 'dir) t
18840 val self: (none, 'dir) t
18841 end
18842
18843 val create:
18844 {args: string list,
18845 env: string list option,
18846 path: string,
18847 stderr: ('stderr, output) Param.t,
18848 stdin: ('stdin, input) Param.t,
18849 stdout: ('stdout, output) Param.t}
18850 -&gt; ('stdin, 'stdout, 'stderr) t
18851 val getStderr: ('stdin, 'stdout, 'stderr) t -&gt; ('stderr, input) Child.t
18852 val getStdin: ('stdin, 'stdout, 'stderr) t -&gt; ('stdin, output) Child.t
18853 val getStdout: ('stdin, 'stdout, 'stderr) t -&gt; ('stdout, input) Child.t
18854 val kill: ('stdin, 'stdout, 'stderr) t * Posix.Signal.signal -&gt; unit
18855 val reap: ('stdin, 'stdout, 'stderr) t -&gt; Posix.Process.exit_status
18856 end</programlisting>
18857 <section id="_spawn">
18858 <title>Spawn</title>
18859 <simpara>The <literal>spawn</literal> functions provide an alternative to the
18860 <literal>fork</literal>/<literal>exec</literal> idiom that is typically used to create a new
18861 process. On most platforms, the <literal>spawn</literal> functions are simple
18862 wrappers around <literal>fork</literal>/<literal>exec</literal>. However, under Windows, the
18863 <literal>spawn</literal> functions are primitive. All <literal>spawn</literal> functions return
18864 the process id of the spawned process. They differ in how the
18865 executable is found and the environment that it uses.</simpara>
18866 <itemizedlist>
18867 <listitem>
18868 <simpara>
18869 <literal>spawn {args, path}</literal>
18870 </simpara>
18871 <simpara>starts a new process running the executable specified by <literal>path</literal>
18872 with the arguments <literal>args</literal>. Like <literal>Posix.Process.exec</literal>.</simpara>
18873 </listitem>
18874 <listitem>
18875 <simpara>
18876 <literal>spawne {args, env, path}</literal>
18877 </simpara>
18878 <simpara>starts a new process running the executable specified by <literal>path</literal> with
18879 the arguments <literal>args</literal> and environment <literal>env</literal>. Like
18880 <literal>Posix.Process.exece</literal>.</simpara>
18881 </listitem>
18882 <listitem>
18883 <simpara>
18884 <literal>spawnp {args, file}</literal>
18885 </simpara>
18886 <simpara>search the <literal>PATH</literal> environment variable for an executable named <literal>file</literal>,
18887 and start a new process running that executable with the arguments
18888 <literal>args</literal>. Like <literal>Posix.Process.execp</literal>.</simpara>
18889 </listitem>
18890 </itemizedlist>
18891 </section>
18892 <section id="_create">
18893 <title>Create</title>
18894 <simpara><literal>MLton.Process.create</literal> provides functionality similar to
18895 <literal>Unix.executeInEnv</literal>, but provides more control control over the input,
18896 output, and error streams. In addition, <literal>create</literal> works on all
18897 platforms, including Cygwin and MinGW (Windows) where <literal>Posix.fork</literal> is
18898 unavailable. For greatest portability programs should still use the
18899 standard <literal>Unix.execute</literal>, <literal>Unix.executeInEnv</literal>, and <literal>OS.Process.system</literal>.</simpara>
18900 <simpara>The following types and sub-structures are used by the <literal>create</literal>
18901 function. They provide static type checking of correct stream usage.</simpara>
18902 <section id="_child">
18903 <title>Child</title>
18904 <itemizedlist>
18905 <listitem>
18906 <simpara>
18907 <literal>('use, 'dir) Child.t</literal>
18908 </simpara>
18909 <simpara>This represents a handle to one of a child&#8217;s standard streams. The
18910 <literal>'dir</literal> is viewed with respect to the parent. Thus a <literal>('a, input)
18911 Child.t</literal> handle means that the parent may input the output from the
18912 child.</simpara>
18913 </listitem>
18914 <listitem>
18915 <simpara>
18916 <literal>Child.{bin,text}{In,Out} h</literal>
18917 </simpara>
18918 <simpara>These functions take a handle and bind it to a stream of the named
18919 type. The type system will detect attempts to reverse the direction
18920 of a stream or to use the same stream in multiple, incompatible ways.</simpara>
18921 </listitem>
18922 <listitem>
18923 <simpara>
18924 <literal>Child.fd h</literal>
18925 </simpara>
18926 <simpara>This function behaves like the other <literal>Child.*</literal> functions; it opens a
18927 stream. However, it does not enforce that you read or write from the
18928 handle. If you use the descriptor in an inappropriate direction, the
18929 behavior is undefined. Furthermore, this function may potentially be
18930 unavailable on future MLton host platforms.</simpara>
18931 </listitem>
18932 <listitem>
18933 <simpara>
18934 <literal>Child.remember h</literal>
18935 </simpara>
18936 <simpara>This function takes a stream of use <literal>any</literal> and resets the use of the
18937 stream so that the stream may be used by <literal>Child.*</literal>. An <literal>any</literal> stream
18938 may have had use <literal>none</literal> or <literal>'use</literal> prior to calling <literal>Param.forget</literal>. If
18939 the stream was <literal>none</literal> and is used, <literal>MisuseOfForget</literal> is raised.</simpara>
18940 </listitem>
18941 </itemizedlist>
18942 </section>
18943 <section id="_param">
18944 <title>Param</title>
18945 <itemizedlist>
18946 <listitem>
18947 <simpara>
18948 <literal>('use, 'dir) Param.t</literal>
18949 </simpara>
18950 <simpara>This is a handle to an input/output source and will be passed to the
18951 created child process. The <literal>'dir</literal> is relative to the child process.
18952 Input means that the child process will read from this stream.</simpara>
18953 </listitem>
18954 <listitem>
18955 <simpara>
18956 <literal>Param.child h</literal>
18957 </simpara>
18958 <simpara>Connect the stream of the new child process to the stream of a
18959 previously created child process. A single child stream should be
18960 connected to only one child process or else <literal>DoublyRedirected</literal> will be
18961 raised.</simpara>
18962 </listitem>
18963 <listitem>
18964 <simpara>
18965 <literal>Param.fd fd</literal>
18966 </simpara>
18967 <simpara>This creates a stream from the provided file descriptor which will be
18968 closed when <literal>create</literal> is called. This function may not be available on
18969 future MLton host platforms.</simpara>
18970 </listitem>
18971 <listitem>
18972 <simpara>
18973 <literal>Param.forget h</literal>
18974 </simpara>
18975 <simpara>This hides the type of the actual parameter as <literal>any</literal>. This is useful
18976 if you are implementing an application which conditionally attaches
18977 the child process to files or pipes. However, you must ensure that
18978 your use after <literal>Child.remember</literal> matches the original type.</simpara>
18979 </listitem>
18980 <listitem>
18981 <simpara>
18982 <literal>Param.file s</literal>
18983 </simpara>
18984 <simpara>Open the given file and connect it to the child process. Note that the
18985 file will be opened only when <literal>create</literal> is called. So any exceptions
18986 will be raised there and not by this function. If used for <literal>input</literal>,
18987 the file is opened read-only. If used for <literal>output</literal>, the file is opened
18988 read-write.</simpara>
18989 </listitem>
18990 <listitem>
18991 <simpara>
18992 <literal>Param.null</literal>
18993 </simpara>
18994 <simpara>In some situations, the child process should have its output
18995 discarded. The <literal>null</literal> param when passed as <literal>stdout</literal> or <literal>stderr</literal> does
18996 this. When used for <literal>stdin</literal>, the child process will either receive
18997 <literal>EOF</literal> or a failure condition if it attempts to read from <literal>stdin</literal>.</simpara>
18998 </listitem>
18999 <listitem>
19000 <simpara>
19001 <literal>Param.pipe</literal>
19002 </simpara>
19003 <simpara>This will connect the input/output of the child process to a pipe
19004 which the parent process holds. This may later form the input to one
19005 of the <literal>Child.*</literal> functions and/or the <literal>Param.child</literal> function.</simpara>
19006 </listitem>
19007 <listitem>
19008 <simpara>
19009 <literal>Param.self</literal>
19010 </simpara>
19011 <simpara>This will connect the input/output of the child process to the
19012 corresponding stream of the parent process.</simpara>
19013 </listitem>
19014 </itemizedlist>
19015 </section>
19016 <section id="_process">
19017 <title>Process</title>
19018 <itemizedlist>
19019 <listitem>
19020 <simpara>
19021 <literal>type ('stdin, 'stdout, 'stderr) t</literal>
19022 </simpara>
19023 <simpara>represents a handle to a child process. The type arguments capture
19024 how the named stream of the child process may be used.</simpara>
19025 </listitem>
19026 <listitem>
19027 <simpara>
19028 <literal>type any</literal>
19029 </simpara>
19030 <simpara>bypasses the type system in situations where an application does not
19031 want the it to enforce correct usage. See <literal>Child.remember</literal> and
19032 <literal>Param.forget</literal>.</simpara>
19033 </listitem>
19034 <listitem>
19035 <simpara>
19036 <literal>type chain</literal>
19037 </simpara>
19038 <simpara>means that the child process&#8217;s stream was connected via a pipe to the
19039 parent process. The parent process may pass this pipe in turn to
19040 another child, thus chaining them together.</simpara>
19041 </listitem>
19042 <listitem>
19043 <simpara>
19044 <literal>type input, output</literal>
19045 </simpara>
19046 <simpara>record the direction that a stream flows. They are used as a part of
19047 <literal>Param.t</literal> and <literal>Child.t</literal> and is detailed there.</simpara>
19048 </listitem>
19049 <listitem>
19050 <simpara>
19051 <literal>type none</literal>
19052 </simpara>
19053 <simpara>means that the child process&#8217;s stream my not be used by the parent
19054 process. This happens when the child process is connected directly to
19055 some source.</simpara>
19056 <simpara>The types <literal>BinIO.instream</literal>, <literal>BinIO.outstream</literal>, <literal>TextIO.instream</literal>,
19057 <literal>TextIO.outstream</literal>, and <literal>Posix.FileSys.file_desc</literal> are also valid types
19058 with which to instantiate child streams.</simpara>
19059 </listitem>
19060 <listitem>
19061 <simpara>
19062 <literal>exception MisuseOfForget</literal>
19063 </simpara>
19064 <simpara>may be raised if <literal>Child.remember</literal> and <literal>Param.forget</literal> are used to
19065 bypass the normal type checking. This exception will only be raised
19066 in cases where the <literal>forget</literal> mechanism allows a misuse that would be
19067 impossible with the type-safe versions.</simpara>
19068 </listitem>
19069 <listitem>
19070 <simpara>
19071 <literal>exception DoublyRedirected</literal>
19072 </simpara>
19073 <simpara>raised if a stream connected to a child process is redirected to two
19074 separate child processes. It is safe, though bad style, to use the a
19075 <literal>Child.t</literal> with the same <literal>Child.*</literal> function repeatedly.</simpara>
19076 </listitem>
19077 <listitem>
19078 <simpara>
19079 <literal>create {args, path, env, stderr, stdin, stdout}</literal>
19080 </simpara>
19081 <simpara>starts a child process with the given command-line <literal>args</literal> (excluding
19082 the program name). <literal>path</literal> should be an absolute path to the executable
19083 run in the new child process; relative paths work, but are less
19084 robust. Optionally, the environment may be overridden with <literal>env</literal>
19085 where each string element has the form <literal>"key=value"</literal>. The <literal>std*</literal>
19086 options must be provided by the <literal>Param.*</literal> functions documented above.</simpara>
19087 <simpara>Processes which are <literal>create</literal>-d must be either <literal>reap</literal>-ed or <literal>kill</literal>-ed.</simpara>
19088 </listitem>
19089 <listitem>
19090 <simpara>
19091 <literal>getStd{in,out,err} proc</literal>
19092 </simpara>
19093 <simpara>gets a handle to the specified stream. These should be used by the
19094 <literal>Child.*</literal> functions. Failure to use a stream connected via pipe to a
19095 child process may result in runtime dead-lock and elicits a compiler
19096 warning.</simpara>
19097 </listitem>
19098 <listitem>
19099 <simpara>
19100 <literal>kill (proc, sig)</literal>
19101 </simpara>
19102 <simpara>terminates the child process immediately. The signal may or may not
19103 mean anything depending on the host platform. A good value is
19104 <literal>Posix.Signal.term</literal>.</simpara>
19105 </listitem>
19106 <listitem>
19107 <simpara>
19108 <literal>reap proc</literal>
19109 </simpara>
19110 <simpara>waits for the child process to terminate and return its exit status.</simpara>
19111 </listitem>
19112 </itemizedlist>
19113 </section>
19114 </section>
19115 <section id="_important_usage_notes">
19116 <title>Important usage notes</title>
19117 <simpara>When building an application with many pipes between child processes,
19118 it is important to ensure that there are no cycles in the undirected
19119 pipe graph. If this property is not maintained, deadlocks are a very
19120 serious potential bug which may only appear under difficult to
19121 reproduce conditions.</simpara>
19122 <simpara>The danger lies in that most operating systems implement pipes with a
19123 fixed buffer size. If process A has two output pipes which process B
19124 reads, it can happen that process A blocks writing to pipe 2 because
19125 it is full while process B blocks reading from pipe 1 because it is
19126 empty. This same situation can happen with any undirected cycle formed
19127 between processes (vertexes) and pipes (undirected edges) in the
19128 graph.</simpara>
19129 <simpara>It is possible to make this safe using low-level I/O primitives for
19130 polling. However, these primitives are not very portable and
19131 difficult to use properly. A far better approach is to make sure you
19132 never create a cycle in the first place.</simpara>
19133 <simpara>For these reasons, the <literal>Unix.executeInEnv</literal> is a very dangerous
19134 function. Be careful when using it to ensure that the child process
19135 only operates on either <literal>stdin</literal> or <literal>stdout</literal>, but not both.</simpara>
19136 </section>
19137 <section id="_example_use_of_mlton_process_create">
19138 <title>Example use of MLton.Process.create</title>
19139 <simpara>The following example program launches the <literal>ipconfig</literal> utility, pipes
19140 its output through <literal>grep</literal>, and then reads the result back into the
19141 program.</simpara>
19142 <programlisting language="sml" linenumbering="unnumbered">open MLton.Process
19143 val p =
19144 create {args = [ "/all" ],
19145 env = NONE,
19146 path = "C:\\WINDOWS\\system32\\ipconfig.exe",
19147 stderr = Param.self,
19148 stdin = Param.null,
19149 stdout = Param.pipe}
19150 val q =
19151 create {args = [ "IP-Ad" ],
19152 env = NONE,
19153 path = "C:\\msys\\bin\\grep.exe",
19154 stderr = Param.self,
19155 stdin = Param.child (getStdout p),
19156 stdout = Param.pipe}
19157 fun suck h =
19158 case TextIO.inputLine h of
19159 NONE =&gt; ()
19160 | SOME s =&gt; (print ("'" ^ s ^ "'\n"); suck h)
19161
19162 val () = suck (Child.textIn (getStdout q))</programlisting>
19163 <simpara><?asciidoc-pagebreak?></simpara>
19164 </section>
19165 </section>
19166 <section id="MLtonProfile">
19167 <title>MLtonProfile</title>
19168 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_PROFILE =
19169 sig
19170 structure Data:
19171 sig
19172 type t
19173
19174 val equals: t * t -&gt; bool
19175 val free: t -&gt; unit
19176 val malloc: unit -&gt; t
19177 val write: t * string -&gt; unit
19178 end
19179
19180 val isOn: bool
19181 val withData: Data.t * (unit -&gt; 'a) -&gt; 'a
19182 end</programlisting>
19183 <simpara><literal>MLton.Profile</literal> provides <link linkend="Profiling">Profiling</link> control from within the
19184 program, allowing you to profile individual portions of your
19185 program. With <literal>MLton.Profile</literal>, you can create many units of profiling
19186 data (essentially, mappings from functions to counts) during a run of
19187 a program, switch between them while the program is running, and
19188 output multiple <literal>mlmon.out</literal> files.</simpara>
19189 <itemizedlist>
19190 <listitem>
19191 <simpara>
19192 <literal>isOn</literal>
19193 </simpara>
19194 <simpara>a compile-time constant that is false only when compiling <literal>-profile no</literal>.</simpara>
19195 </listitem>
19196 <listitem>
19197 <simpara>
19198 <literal>type Data.t</literal>
19199 </simpara>
19200 <simpara>the type of a unit of profiling data. In order to most efficiently
19201 execute non-profiled programs, when compiling <literal>-profile no</literal> (the
19202 default), <literal>Data.t</literal> is equivalent to <literal>unit ref</literal>.</simpara>
19203 </listitem>
19204 <listitem>
19205 <simpara>
19206 <literal>Data.equals (x, y)</literal>
19207 </simpara>
19208 <simpara>returns true if the <literal>x</literal> and <literal>y</literal> are the same unit of profiling data.</simpara>
19209 </listitem>
19210 <listitem>
19211 <simpara>
19212 <literal>Data.free x</literal>
19213 </simpara>
19214 <simpara>frees the memory associated with the unit of profiling data <literal>x</literal>. It
19215 is an error to free the current unit of profiling data or to free a
19216 previously freed unit of profiling data. When compiling
19217 <literal>-profile no</literal>, <literal>Data.free x</literal> is a no-op.</simpara>
19218 </listitem>
19219 <listitem>
19220 <simpara>
19221 <literal>Data.malloc ()</literal>
19222 </simpara>
19223 <simpara>returns a new unit of profiling data. Each unit of profiling data is
19224 allocated from the process address space (but is <emphasis>not</emphasis> in the MLton
19225 heap) and consumes memory proportional to the number of source
19226 functions. When compiling <literal>-profile no</literal>, <literal>Data.malloc ()</literal> is
19227 equivalent to allocating a new <literal>unit ref</literal>.</simpara>
19228 </listitem>
19229 <listitem>
19230 <simpara>
19231 <literal>write (x, f)</literal>
19232 </simpara>
19233 <simpara>writes the accumulated ticks in the unit of profiling data <literal>x</literal> to file
19234 <literal>f</literal>. It is an error to write a previously freed unit of profiling
19235 data. When compiling <literal>-profile no</literal>, <literal>write (x, f)</literal> is a no-op. A
19236 profiled program will always write the current unit of profiling data
19237 at program exit to a file named <literal>mlmon.out</literal>.</simpara>
19238 </listitem>
19239 <listitem>
19240 <simpara>
19241 <literal>withData (d, f)</literal>
19242 </simpara>
19243 <simpara>runs <literal>f</literal> with <literal>d</literal> as the unit of profiling data, and returns the
19244 result of <literal>f</literal> after restoring the current unit of profiling data.
19245 When compiling <literal>-profile no</literal>, <literal>withData (d, f)</literal> is equivalent to
19246 <literal>f ()</literal>.</simpara>
19247 </listitem>
19248 </itemizedlist>
19249 <section id="_example_5">
19250 <title>Example</title>
19251 <simpara>Here is an example, taken from the <literal>examples/profiling</literal> directory,
19252 showing how to profile the executions of the <literal>fib</literal> and <literal>tak</literal> functions
19253 separately. Suppose that <literal>fib-tak.sml</literal> contains the following.</simpara>
19254 <programlisting language="sml" linenumbering="unnumbered">structure Profile = MLton.Profile
19255
19256 val fibData = Profile.Data.malloc ()
19257 val takData = Profile.Data.malloc ()
19258
19259 fun wrap (f, d) x =
19260 Profile.withData (d, fn () =&gt; f x)
19261
19262 val rec fib =
19263 fn 0 =&gt; 0
19264 | 1 =&gt; 1
19265 | n =&gt; fib (n - 1) + fib (n - 2)
19266 val fib = wrap (fib, fibData)
19267
19268 fun tak (x,y,z) =
19269 if not (y &lt; x)
19270 then z
19271 else tak (tak (x - 1, y, z),
19272 tak (y - 1, z, x),
19273 tak (z - 1, x, y))
19274 val tak = wrap (tak, takData)
19275
19276 val rec f =
19277 fn 0 =&gt; ()
19278 | n =&gt; (fib 38; f (n-1))
19279 val _ = f 2
19280
19281 val rec g =
19282 fn 0 =&gt; ()
19283 | n =&gt; (tak (18,12,6); g (n-1))
19284 val _ = g 500
19285
19286 fun done (data, file) =
19287 (Profile.Data.write (data, file)
19288 ; Profile.Data.free data)
19289
19290 val _ = done (fibData, "mlmon.fib.out")
19291 val _ = done (takData, "mlmon.tak.out")</programlisting>
19292 <simpara>Compile and run the program.</simpara>
19293 <screen>% mlton -profile time fib-tak.sml
19294 % ./fib-tak</screen>
19295 <simpara>Separately display the profiling data for <literal>fib</literal></simpara>
19296 <screen>% mlprof fib-tak mlmon.fib.out
19297 5.77 seconds of CPU time (0.00 seconds GC)
19298 function cur
19299 --------- -----
19300 fib 96.9%
19301 &lt;unknown&gt; 3.1%</screen>
19302 <simpara>and for <literal>tak</literal></simpara>
19303 <screen>% mlprof fib-tak mlmon.tak.out
19304 0.68 seconds of CPU time (0.00 seconds GC)
19305 function cur
19306 -------- ------
19307 tak 100.0%</screen>
19308 <simpara>Combine the data for <literal>fib</literal> and <literal>tak</literal> by calling <literal>mlprof</literal>
19309 with multiple <literal>mlmon.out</literal> files.</simpara>
19310 <screen>% mlprof fib-tak mlmon.fib.out mlmon.tak.out mlmon.out
19311 6.45 seconds of CPU time (0.00 seconds GC)
19312 function cur
19313 --------- -----
19314 fib 86.7%
19315 tak 10.5%
19316 &lt;unknown&gt; 2.8%</screen>
19317 <simpara><?asciidoc-pagebreak?></simpara>
19318 </section>
19319 </section>
19320 <section id="MLtonRandom">
19321 <title>MLtonRandom</title>
19322 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_RANDOM =
19323 sig
19324 val alphaNumChar: unit -&gt; char
19325 val alphaNumString: int -&gt; string
19326 val rand: unit -&gt; word
19327 val seed: unit -&gt; word option
19328 val srand: word -&gt; unit
19329 val useed: unit -&gt; word option
19330 end</programlisting>
19331 <itemizedlist>
19332 <listitem>
19333 <simpara>
19334 <literal>alphaNumChar ()</literal>
19335 </simpara>
19336 <simpara>returns a random alphanumeric character.</simpara>
19337 </listitem>
19338 <listitem>
19339 <simpara>
19340 <literal>alphaNumString n</literal>
19341 </simpara>
19342 <simpara>returns a string of length <literal>n</literal> of random alphanumeric characters.</simpara>
19343 </listitem>
19344 <listitem>
19345 <simpara>
19346 <literal>rand ()</literal>
19347 </simpara>
19348 <simpara>returns the next pseudo-random number.</simpara>
19349 </listitem>
19350 <listitem>
19351 <simpara>
19352 <literal>seed ()</literal>
19353 </simpara>
19354 <simpara>returns a random word from <literal>/dev/random</literal>. Useful as an arg to
19355 <literal>srand</literal>. If <literal>/dev/random</literal> can not be read from, <literal>seed ()</literal> returns
19356 <literal>NONE</literal>. A call to <literal>seed</literal> may block until enough random bits are
19357 available.</simpara>
19358 </listitem>
19359 <listitem>
19360 <simpara>
19361 <literal>srand w</literal>
19362 </simpara>
19363 <simpara>sets the seed used by <literal>rand</literal> to <literal>w</literal>.</simpara>
19364 </listitem>
19365 <listitem>
19366 <simpara>
19367 <literal>useed ()</literal>
19368 </simpara>
19369 <simpara>returns a random word from <literal>/dev/urandom</literal>. Useful as an arg to
19370 <literal>srand</literal>. If <literal>/dev/urandom</literal> can not be read from, <literal>useed ()</literal> returns
19371 <literal>NONE</literal>. A call to <literal>useed</literal> will never block&#8201;&#8212;&#8201;it will instead return
19372 lower quality random bits.</simpara>
19373 </listitem>
19374 </itemizedlist>
19375 <simpara><?asciidoc-pagebreak?></simpara>
19376 </section>
19377 <section id="MLtonReal">
19378 <title>MLtonReal</title>
19379 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_REAL =
19380 sig
19381 type t
19382
19383 val fromWord: word -&gt; t
19384 val fromLargeWord: LargeWord.word -&gt; t
19385 val toWord: IEEEReal.rounding_mode -&gt; t -&gt; word
19386 val toLargeWord: IEEEReal.rounding_mode -&gt; t -&gt; LargeWord.word
19387 end</programlisting>
19388 <itemizedlist>
19389 <listitem>
19390 <simpara>
19391 <literal>type t</literal>
19392 </simpara>
19393 <simpara>the type of reals. For <literal>MLton.LargeReal</literal> this is <literal>LargeReal.real</literal>,
19394 for <literal>MLton.Real</literal> this is <literal>Real.real</literal>, for <literal>MLton.Real32</literal> this is
19395 <literal>Real32.real</literal>, for <literal>MLton.Real64</literal> this is <literal>Real64.real</literal>.</simpara>
19396 </listitem>
19397 <listitem>
19398 <simpara>
19399 <literal>fromWord w</literal>
19400 </simpara>
19401 </listitem>
19402 <listitem>
19403 <simpara>
19404 <literal>fromLargeWord w</literal>
19405 </simpara>
19406 <simpara>convert the word <literal>w</literal> to a real value. If the value of <literal>w</literal> is larger
19407 than (the appropriate) <literal>REAL.maxFinite</literal>, then infinity is returned.
19408 If <literal>w</literal> cannot be exactly represented as a real value, then the current
19409 rounding mode is used to determine the resulting value.</simpara>
19410 </listitem>
19411 <listitem>
19412 <simpara>
19413 <literal>toWord mode r</literal>
19414 </simpara>
19415 </listitem>
19416 <listitem>
19417 <simpara>
19418 <literal>toLargeWord mode r</literal>
19419 </simpara>
19420 <simpara>convert the argument <literal>r</literal> to a word type using the specified rounding
19421 mode. They raise <literal>Overflow</literal> if the result is not representable, in
19422 particular, if <literal>r</literal> is an infinity. They raise <literal>Domain</literal> if <literal>r</literal> is NaN.</simpara>
19423 </listitem>
19424 <listitem>
19425 <simpara>
19426 <literal>MLton.Real32.castFromWord w</literal>
19427 </simpara>
19428 </listitem>
19429 <listitem>
19430 <simpara>
19431 <literal>MLton.Real64.castFromWord w</literal>
19432 </simpara>
19433 <simpara>convert the argument <literal>w</literal> to a real type as a bit-wise cast.</simpara>
19434 </listitem>
19435 <listitem>
19436 <simpara>
19437 <literal>MLton.Real32.castToWord r</literal>
19438 </simpara>
19439 </listitem>
19440 <listitem>
19441 <simpara>
19442 <literal>MLton.Real64.castToWord r</literal>
19443 </simpara>
19444 <simpara>convert the argument <literal>r</literal> to a word type as a bit-wise cast.</simpara>
19445 </listitem>
19446 </itemizedlist>
19447 <simpara><?asciidoc-pagebreak?></simpara>
19448 </section>
19449 <section id="MLtonRlimit">
19450 <title>MLtonRlimit</title>
19451 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_RLIMIT =
19452 sig
19453 structure RLim : sig
19454 type t
19455 val castFromSysWord: SysWord.word -&gt; t
19456 val castToSysWord: t -&gt; SysWord.word
19457 end
19458
19459 val infinity: RLim.t
19460
19461 type t
19462
19463 val coreFileSize: t (* CORE max core file size *)
19464 val cpuTime: t (* CPU CPU time in seconds *)
19465 val dataSize: t (* DATA max data size *)
19466 val fileSize: t (* FSIZE Maximum filesize *)
19467 val numFiles: t (* NOFILE max number of open files *)
19468 val lockedInMemorySize: t (* MEMLOCK max locked address space *)
19469 val numProcesses: t (* NPROC max number of processes *)
19470 val residentSetSize: t (* RSS max resident set size *)
19471 val stackSize: t (* STACK max stack size *)
19472 val virtualMemorySize: t (* AS virtual memory limit *)
19473
19474 val get: t -&gt; {hard: rlim, soft: rlim}
19475 val set: t * {hard: rlim, soft: rlim} -&gt; unit
19476 end</programlisting>
19477 <simpara><literal>MLton.Rlimit</literal> provides a wrapper around the C <literal>getrlimit</literal> and
19478 <literal>setrlimit</literal> functions.</simpara>
19479 <itemizedlist>
19480 <listitem>
19481 <simpara>
19482 <literal>type Rlim.t</literal>
19483 </simpara>
19484 <simpara>the type of resource limits.</simpara>
19485 </listitem>
19486 <listitem>
19487 <simpara>
19488 <literal>infinity</literal>
19489 </simpara>
19490 <simpara>indicates that a resource is unlimited.</simpara>
19491 </listitem>
19492 <listitem>
19493 <simpara>
19494 <literal>type t</literal>
19495 </simpara>
19496 <simpara>the types of resources that can be inspected and modified.</simpara>
19497 </listitem>
19498 <listitem>
19499 <simpara>
19500 <literal>get r</literal>
19501 </simpara>
19502 <simpara>returns the current hard and soft limits for resource <literal>r</literal>. May raise
19503 <literal>OS.SysErr</literal>.</simpara>
19504 </listitem>
19505 <listitem>
19506 <simpara>
19507 <literal>set (r, {hard, soft})</literal>
19508 </simpara>
19509 <simpara>sets the hard and soft limits for resource <literal>r</literal>. May raise
19510 <literal>OS.SysErr</literal>.</simpara>
19511 </listitem>
19512 </itemizedlist>
19513 <simpara><?asciidoc-pagebreak?></simpara>
19514 </section>
19515 <section id="MLtonRusage">
19516 <title>MLtonRusage</title>
19517 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_RUSAGE =
19518 sig
19519 type t = {utime: Time.time, (* user time *)
19520 stime: Time.time} (* system time *)
19521
19522 val measureGC: bool -&gt; unit
19523 val rusage: unit -&gt; {children: t, gc: t, self: t}
19524 end</programlisting>
19525 <itemizedlist>
19526 <listitem>
19527 <simpara>
19528 <literal>type t</literal>
19529 </simpara>
19530 <simpara>corresponds to a subset of the C <literal>struct rusage</literal>.</simpara>
19531 </listitem>
19532 <listitem>
19533 <simpara>
19534 <literal>measureGC b</literal>
19535 </simpara>
19536 <simpara>controls whether garbage collection time is separately measured during
19537 program execution. This affects the behavior of both <literal>rusage</literal> and
19538 <literal>Timer.checkCPUTimes</literal>, both of which will return gc times of zero with
19539 <literal>measureGC false</literal>. Garbage collection time is always measured when
19540 either <literal>gc-messages</literal> or <literal>gc-summary</literal> is given as a
19541 <link linkend="RunTimeOptions">runtime system option</link>.</simpara>
19542 </listitem>
19543 <listitem>
19544 <simpara>
19545 <literal>rusage ()</literal>
19546 </simpara>
19547 <simpara>corresponds to the C <literal>getrusage</literal> function. It returns the resource
19548 usage of the exited children, the garbage collector, and the process
19549 itself. The <literal>self</literal> component includes the usage of the <literal>gc</literal>
19550 component, regardless of whether <literal>measureGC</literal> is <literal>true</literal> or <literal>false</literal>. If
19551 <literal>rusage</literal> is used in a program, either directly, or indirectly via the
19552 <literal>Timer</literal> structure, then <literal>measureGC true</literal> is automatically called at
19553 the start of the program (it can still be disable by user code later).</simpara>
19554 </listitem>
19555 </itemizedlist>
19556 <simpara><?asciidoc-pagebreak?></simpara>
19557 </section>
19558 <section id="MLtonSignal">
19559 <title>MLtonSignal</title>
19560 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_SIGNAL =
19561 sig
19562 type t = Posix.Signal.signal
19563 type signal = t
19564
19565 structure Handler:
19566 sig
19567 type t
19568
19569 val default: t
19570 val handler: (Thread.Runnable.t -&gt; Thread.Runnable.t) -&gt; t
19571 val ignore: t
19572 val isDefault: t -&gt; bool
19573 val isIgnore: t -&gt; bool
19574 val simple: (unit -&gt; unit) -&gt; t
19575 end
19576
19577 structure Mask:
19578 sig
19579 type t
19580
19581 val all: t
19582 val allBut: signal list -&gt; t
19583 val block: t -&gt; unit
19584 val getBlocked: unit -&gt; t
19585 val isMember: t * signal -&gt; bool
19586 val none: t
19587 val setBlocked: t -&gt; unit
19588 val some: signal list -&gt; t
19589 val unblock: t -&gt; unit
19590 end
19591
19592 val getHandler: t -&gt; Handler.t
19593 val handled: unit -&gt; Mask.t
19594 val prof: t
19595 val restart: bool ref
19596 val setHandler: t * Handler.t -&gt; unit
19597 val suspend: Mask.t -&gt; unit
19598 val vtalrm: t
19599 end</programlisting>
19600 <simpara>Signals handlers are functions from (runnable) threads to (runnable)
19601 threads. When a signal arrives, the corresponding signal handler is
19602 invoked, its argument being the thread that was interrupted by the
19603 signal. The signal handler runs asynchronously, in its own thread.
19604 The signal handler returns the thread that it would like to resume
19605 execution (this is often the thread that it was passed). It is an
19606 error for a signal handler to raise an exception that is not handled
19607 within the signal handler itself.</simpara>
19608 <simpara>A signal handler is never invoked while the running thread is in a
19609 critical section (see <link linkend="MLtonThread">MLtonThread</link>). Invoking a signal handler
19610 implicitly enters a critical section and the normal return of a signal
19611 handler implicitly exits the critical section; hence, a signal handler
19612 is never interrupted by another signal handler.</simpara>
19613 <itemizedlist>
19614 <listitem>
19615 <simpara>
19616 <literal>type t</literal>
19617 </simpara>
19618 <simpara>the type of signals.</simpara>
19619 </listitem>
19620 <listitem>
19621 <simpara>
19622 <literal>type Handler.t</literal>
19623 </simpara>
19624 <simpara>the type of signal handlers.</simpara>
19625 </listitem>
19626 <listitem>
19627 <simpara>
19628 <literal>Handler.default</literal>
19629 </simpara>
19630 <simpara>handles the signal with the default action.</simpara>
19631 </listitem>
19632 <listitem>
19633 <simpara>
19634 <literal>Handler.handler f</literal>
19635 </simpara>
19636 <simpara>returns a handler <literal>h</literal> such that when a signal <literal>s</literal> is handled by <literal>h</literal>,
19637 <literal>f</literal> will be passed the thread that was interrupted by <literal>s</literal> and should
19638 return the thread that will resume execution.</simpara>
19639 </listitem>
19640 <listitem>
19641 <simpara>
19642 <literal>Handler.ignore</literal>
19643 </simpara>
19644 <simpara>is a handler that will ignore the signal.</simpara>
19645 </listitem>
19646 <listitem>
19647 <simpara>
19648 <literal>Handler.isDefault</literal>
19649 </simpara>
19650 <simpara>returns true if the handler is the default handler.</simpara>
19651 </listitem>
19652 <listitem>
19653 <simpara>
19654 <literal>Handler.isIgnore</literal>
19655 </simpara>
19656 <simpara>returns true if the handler is the ignore handler.</simpara>
19657 </listitem>
19658 <listitem>
19659 <simpara>
19660 <literal>Handler.simple f</literal>
19661 </simpara>
19662 <simpara>returns a handler that executes <literal>f ()</literal> and does not switch threads.</simpara>
19663 </listitem>
19664 <listitem>
19665 <simpara>
19666 <literal>type Mask.t</literal>
19667 </simpara>
19668 <simpara>the type of signal masks, which are sets of blocked signals.</simpara>
19669 </listitem>
19670 <listitem>
19671 <simpara>
19672 <literal>Mask.all</literal>
19673 </simpara>
19674 <simpara>a mask of all signals.</simpara>
19675 </listitem>
19676 <listitem>
19677 <simpara>
19678 <literal>Mask.allBut l</literal>
19679 </simpara>
19680 <simpara>a mask of all signals except for those in <literal>l</literal>.</simpara>
19681 </listitem>
19682 <listitem>
19683 <simpara>
19684 <literal>Mask.block m</literal>
19685 </simpara>
19686 <simpara>blocks all signals in <literal>m</literal>.</simpara>
19687 </listitem>
19688 <listitem>
19689 <simpara>
19690 <literal>Mask.getBlocked ()</literal>
19691 </simpara>
19692 <simpara>gets the signal mask <literal>m</literal>, i.e. a signal is blocked if and only if it
19693 is in <literal>m</literal>.</simpara>
19694 </listitem>
19695 <listitem>
19696 <simpara>
19697 <literal>Mask.isMember (m, s)</literal>
19698 </simpara>
19699 <simpara>returns true if the signal <literal>s</literal> is in <literal>m</literal>.</simpara>
19700 </listitem>
19701 <listitem>
19702 <simpara>
19703 <literal>Mask.none</literal>
19704 </simpara>
19705 <simpara>a mask of no signals.</simpara>
19706 </listitem>
19707 <listitem>
19708 <simpara>
19709 <literal>Mask.setBlocked m</literal>
19710 </simpara>
19711 <simpara>sets the signal mask to <literal>m</literal>, i.e. a signal is blocked if and only if
19712 it is in <literal>m</literal>.</simpara>
19713 </listitem>
19714 <listitem>
19715 <simpara>
19716 <literal>Mask.some l</literal>
19717 </simpara>
19718 <simpara>a mask of the signals in <literal>l</literal>.</simpara>
19719 </listitem>
19720 <listitem>
19721 <simpara>
19722 <literal>Mask.unblock m</literal>
19723 </simpara>
19724 <simpara>unblocks all signals in <literal>m</literal>.</simpara>
19725 </listitem>
19726 <listitem>
19727 <simpara>
19728 <literal>getHandler s</literal>
19729 </simpara>
19730 <simpara>returns the current handler for signal <literal>s</literal>.</simpara>
19731 </listitem>
19732 <listitem>
19733 <simpara>
19734 <literal>handled ()</literal>
19735 </simpara>
19736 <simpara>returns the signal mask <literal>m</literal> corresponding to the currently handled
19737 signals; i.e., a signal is handled if and only if it is in <literal>m</literal>.</simpara>
19738 </listitem>
19739 <listitem>
19740 <simpara>
19741 <literal>prof</literal>
19742 </simpara>
19743 <simpara><literal>SIGPROF</literal>, the profiling signal.</simpara>
19744 </listitem>
19745 <listitem>
19746 <simpara>
19747 <literal>restart</literal>
19748 </simpara>
19749 <simpara>dynamically determines the behavior of interrupted system calls; when
19750 <literal>true</literal>, interrupted system calls are restarted; when <literal>false</literal>,
19751 interrupted system calls raise <literal>OS.SysError</literal>.</simpara>
19752 </listitem>
19753 <listitem>
19754 <simpara>
19755 <literal>setHandler (s, h)</literal>
19756 </simpara>
19757 <simpara>sets the handler for signal <literal>s</literal> to <literal>h</literal>.</simpara>
19758 </listitem>
19759 <listitem>
19760 <simpara>
19761 <literal>suspend m</literal>
19762 </simpara>
19763 <simpara>temporarily sets the signal mask to <literal>m</literal> and suspends until an unmasked
19764 signal is received and handled, at which point <literal>suspend</literal> resets the
19765 mask and returns.</simpara>
19766 </listitem>
19767 <listitem>
19768 <simpara>
19769 <literal>vtalrm</literal>
19770 </simpara>
19771 <simpara><literal>SIGVTALRM</literal>, the signal for virtual timers.</simpara>
19772 </listitem>
19773 </itemizedlist>
19774 <section id="_interruptible_system_calls">
19775 <title>Interruptible System Calls</title>
19776 <simpara>Signal handling interacts in a non-trivial way with those functions in
19777 the <link linkend="BasisLibrary">Basis Library</link> that correspond directly to
19778 interruptible system calls (a subset of those functions that may raise
19779 <literal>OS.SysError</literal>). The desire is that these functions should have
19780 predictable semantics. The principal concerns are:</simpara>
19781 <orderedlist numeration="arabic">
19782 <listitem>
19783 <simpara>
19784 System calls that are interrupted by signals should, by default, be
19785 restarted; the alternative is to raise
19786 </simpara>
19787 <programlisting language="sml" linenumbering="unnumbered">OS.SysError (Posix.Error.errorMsg Posix.Error.intr,
19788 SOME Posix.Error.intr)</programlisting>
19789 <simpara>This behavior is determined dynamically by the value of <literal>Signal.restart</literal>.</simpara>
19790 </listitem>
19791 <listitem>
19792 <simpara>
19793 Signal handlers should always get a chance to run (when outside a
19794 critical region). If a system call is interrupted by a signal, then
19795 the signal handler will run before the call is restarted or
19796 <literal>OS.SysError</literal> is raised; that is, before the <literal>Signal.restart</literal> check.
19797 </simpara>
19798 </listitem>
19799 <listitem>
19800 <simpara>
19801 A system call that must be restarted while in a critical section
19802 will be restarted with the handled signals blocked (and the previously
19803 blocked signals remembered). This encourages the system call to
19804 complete, allowing the program to make progress towards leaving the
19805 critical section where the signal can be handled. If the system call
19806 completes, the set of blocked signals are restored to those previously
19807 blocked.
19808 </simpara>
19809 </listitem>
19810 </orderedlist>
19811 <simpara><?asciidoc-pagebreak?></simpara>
19812 </section>
19813 </section>
19814 <section id="MLtonStructure">
19815 <title>MLtonStructure</title>
19816 <simpara>The <literal>MLton</literal> structure contains a lot of functionality that is not
19817 available in the <link linkend="BasisLibrary">Basis Library</link>. As a warning,
19818 please keep in mind that the <literal>MLton</literal> structure and its
19819 substructures do change from release to release of MLton.</simpara>
19820 <programlisting language="sml" linenumbering="unnumbered">structure MLton:
19821 sig
19822 val eq: 'a * 'a -&gt; bool
19823 val equal: 'a * 'a -&gt; bool
19824 val hash: 'a -&gt; Word32.word
19825 val isMLton: bool
19826 val share: 'a -&gt; unit
19827 val shareAll: unit -&gt; unit
19828 val size: 'a -&gt; int
19829
19830 structure Array: MLTON_ARRAY
19831 structure BinIO: MLTON_BIN_IO
19832 structure CharArray: MLTON_MONO_ARRAY where type t = CharArray.array
19833 where type elem = CharArray.elem
19834 structure CharVector: MLTON_MONO_VECTOR where type t = CharVector.vector
19835 where type elem = CharVector.elem
19836 structure Cont: MLTON_CONT
19837 structure Exn: MLTON_EXN
19838 structure Finalizable: MLTON_FINALIZABLE
19839 structure GC: MLTON_GC
19840 structure IntInf: MLTON_INT_INF
19841 structure Itimer: MLTON_ITIMER
19842 structure LargeReal: MLTON_REAL where type t = LargeReal.real
19843 structure LargeWord: MLTON_WORD where type t = LargeWord.word
19844 structure Platform: MLTON_PLATFORM
19845 structure Pointer: MLTON_POINTER
19846 structure ProcEnv: MLTON_PROC_ENV
19847 structure Process: MLTON_PROCESS
19848 structure Profile: MLTON_PROFILE
19849 structure Random: MLTON_RANDOM
19850 structure Real: MLTON_REAL where type t = Real.real
19851 structure Real32: sig
19852 include MLTON_REAL
19853 val castFromWord: Word32.word -&gt; t
19854 val castToWord: t -&gt; Word32.word
19855 end where type t = Real32.real
19856 structure Real64: sig
19857 include MLTON_REAL
19858 val castFromWord: Word64.word -&gt; t
19859 val castToWord: t -&gt; Word64.word
19860 end where type t = Real64.real
19861 structure Rlimit: MLTON_RLIMIT
19862 structure Rusage: MLTON_RUSAGE
19863 structure Signal: MLTON_SIGNAL
19864 structure Syslog: MLTON_SYSLOG
19865 structure TextIO: MLTON_TEXT_IO
19866 structure Thread: MLTON_THREAD
19867 structure Vector: MLTON_VECTOR
19868 structure Weak: MLTON_WEAK
19869 structure Word: MLTON_WORD where type t = Word.word
19870 structure Word8: MLTON_WORD where type t = Word8.word
19871 structure Word16: MLTON_WORD where type t = Word16.word
19872 structure Word32: MLTON_WORD where type t = Word32.word
19873 structure Word64: MLTON_WORD where type t = Word64.word
19874 structure Word8Array: MLTON_MONO_ARRAY where type t = Word8Array.array
19875 where type elem = Word8Array.elem
19876 structure Word8Vector: MLTON_MONO_VECTOR where type t = Word8Vector.vector
19877 where type elem = Word8Vector.elem
19878 structure World: MLTON_WORLD
19879 end</programlisting>
19880 <section id="_substructures">
19881 <title>Substructures</title>
19882 <itemizedlist>
19883 <listitem>
19884 <simpara>
19885 <link linkend="MLtonArray">MLtonArray</link>
19886 </simpara>
19887 </listitem>
19888 <listitem>
19889 <simpara>
19890 <link linkend="MLtonBinIO">MLtonBinIO</link>
19891 </simpara>
19892 </listitem>
19893 <listitem>
19894 <simpara>
19895 <link linkend="MLtonCont">MLtonCont</link>
19896 </simpara>
19897 </listitem>
19898 <listitem>
19899 <simpara>
19900 <link linkend="MLtonExn">MLtonExn</link>
19901 </simpara>
19902 </listitem>
19903 <listitem>
19904 <simpara>
19905 <link linkend="MLtonFinalizable">MLtonFinalizable</link>
19906 </simpara>
19907 </listitem>
19908 <listitem>
19909 <simpara>
19910 <link linkend="MLtonGC">MLtonGC</link>
19911 </simpara>
19912 </listitem>
19913 <listitem>
19914 <simpara>
19915 <link linkend="MLtonIntInf">MLtonIntInf</link>
19916 </simpara>
19917 </listitem>
19918 <listitem>
19919 <simpara>
19920 <link linkend="MLtonIO">MLtonIO</link>
19921 </simpara>
19922 </listitem>
19923 <listitem>
19924 <simpara>
19925 <link linkend="MLtonItimer">MLtonItimer</link>
19926 </simpara>
19927 </listitem>
19928 <listitem>
19929 <simpara>
19930 <link linkend="MLtonMonoArray">MLtonMonoArray</link>
19931 </simpara>
19932 </listitem>
19933 <listitem>
19934 <simpara>
19935 <link linkend="MLtonMonoVector">MLtonMonoVector</link>
19936 </simpara>
19937 </listitem>
19938 <listitem>
19939 <simpara>
19940 <link linkend="MLtonPlatform">MLtonPlatform</link>
19941 </simpara>
19942 </listitem>
19943 <listitem>
19944 <simpara>
19945 <link linkend="MLtonPointer">MLtonPointer</link>
19946 </simpara>
19947 </listitem>
19948 <listitem>
19949 <simpara>
19950 <link linkend="MLtonProcEnv">MLtonProcEnv</link>
19951 </simpara>
19952 </listitem>
19953 <listitem>
19954 <simpara>
19955 <link linkend="MLtonProcess">MLtonProcess</link>
19956 </simpara>
19957 </listitem>
19958 <listitem>
19959 <simpara>
19960 <link linkend="MLtonRandom">MLtonRandom</link>
19961 </simpara>
19962 </listitem>
19963 <listitem>
19964 <simpara>
19965 <link linkend="MLtonReal">MLtonReal</link>
19966 </simpara>
19967 </listitem>
19968 <listitem>
19969 <simpara>
19970 <link linkend="MLtonRlimit">MLtonRlimit</link>
19971 </simpara>
19972 </listitem>
19973 <listitem>
19974 <simpara>
19975 <link linkend="MLtonRusage">MLtonRusage</link>
19976 </simpara>
19977 </listitem>
19978 <listitem>
19979 <simpara>
19980 <link linkend="MLtonSignal">MLtonSignal</link>
19981 </simpara>
19982 </listitem>
19983 <listitem>
19984 <simpara>
19985 <link linkend="MLtonSyslog">MLtonSyslog</link>
19986 </simpara>
19987 </listitem>
19988 <listitem>
19989 <simpara>
19990 <link linkend="MLtonTextIO">MLtonTextIO</link>
19991 </simpara>
19992 </listitem>
19993 <listitem>
19994 <simpara>
19995 <link linkend="MLtonThread">MLtonThread</link>
19996 </simpara>
19997 </listitem>
19998 <listitem>
19999 <simpara>
20000 <link linkend="MLtonVector">MLtonVector</link>
20001 </simpara>
20002 </listitem>
20003 <listitem>
20004 <simpara>
20005 <link linkend="MLtonWeak">MLtonWeak</link>
20006 </simpara>
20007 </listitem>
20008 <listitem>
20009 <simpara>
20010 <link linkend="MLtonWord">MLtonWord</link>
20011 </simpara>
20012 </listitem>
20013 <listitem>
20014 <simpara>
20015 <link linkend="MLtonWorld">MLtonWorld</link>
20016 </simpara>
20017 </listitem>
20018 </itemizedlist>
20019 </section>
20020 <section id="_values">
20021 <title>Values</title>
20022 <itemizedlist>
20023 <listitem>
20024 <simpara>
20025 <literal>eq (x, y)</literal>
20026 </simpara>
20027 <simpara>returns true if <literal>x</literal> and <literal>y</literal> are equal as pointers. For simple types
20028 like <literal>char</literal>, <literal>int</literal>, and <literal>word</literal>, this is the same as equals. For
20029 arrays, datatypes, strings, tuples, and vectors, this is a simple
20030 pointer equality. The semantics is a bit murky.</simpara>
20031 </listitem>
20032 <listitem>
20033 <simpara>
20034 <literal>equal (x, y)</literal>
20035 </simpara>
20036 <simpara>returns true if <literal>x</literal> and <literal>y</literal> are structurally equal. For equality
20037 types, this is the same as <link linkend="PolymorphicEquality">PolymorphicEquality</link>. For other types,
20038 it is a conservative approximation of equivalence.</simpara>
20039 </listitem>
20040 <listitem>
20041 <simpara>
20042 <literal>hash x</literal>
20043 </simpara>
20044 <simpara>returns a structural hash of <literal>x</literal>. The hash function is consistent
20045 between execution of the same program, but may not be consistent
20046 between different programs.</simpara>
20047 </listitem>
20048 <listitem>
20049 <simpara>
20050 <literal>isMLton</literal>
20051 </simpara>
20052 <simpara>is always <literal>true</literal> in a MLton implementation, and is always <literal>false</literal> in a
20053 stub implementation.</simpara>
20054 </listitem>
20055 <listitem>
20056 <simpara>
20057 <literal>share x</literal>
20058 </simpara>
20059 <simpara>maximizes sharing in the heap for the object graph reachable from <literal>x</literal>.</simpara>
20060 </listitem>
20061 <listitem>
20062 <simpara>
20063 <literal>shareAll ()</literal>
20064 </simpara>
20065 <simpara>maximizes sharing in the heap by sharing space for equivalent
20066 immutable objects. A call to <literal>shareAll</literal> performs a major garbage
20067 collection, and takes time proportional to the size of the heap.</simpara>
20068 </listitem>
20069 <listitem>
20070 <simpara>
20071 <literal>size x</literal>
20072 </simpara>
20073 <simpara>returns the amount of heap space (in bytes) taken by the value of <literal>x</literal>,
20074 including all objects reachable from <literal>x</literal> by following pointers. It
20075 takes time proportional to the size of <literal>x</literal>. See below for an example.</simpara>
20076 </listitem>
20077 </itemizedlist>
20078 </section>
20079 <section id="_anchor_id_mltonstructure_size_xreflabel_mltonstructure_size_example_of_literal_mlton_size_literal">
20080 <title><anchor id="MLtonStructure_size" xreflabel="[MLtonStructure_size]"/>Example of <literal>MLton.size</literal></title>
20081 <simpara>This example, <literal>size.sml</literal>, demonstrates the application of <literal>MLton.size</literal>
20082 to many different kinds of objects.</simpara>
20083 <programlisting language="sml" linenumbering="unnumbered">fun 'a printSize (name: string, value: 'a): unit=
20084 (print "The size of "
20085 ; print name
20086 ; print " is "
20087 ; print (Int.toString (MLton.size value))
20088 ; print " bytes.\n")
20089
20090 val l = [1, 2, 3, 4]
20091
20092 val _ =
20093 (
20094 printSize ("an int list of length 4", l)
20095 ; printSize ("a string of length 10", "0123456789")
20096 ; printSize ("an int array of length 10", Array.tabulate (10, fn _ =&gt; 0))
20097 ; printSize ("a double array of length 10",
20098 Array.tabulate (10, fn _ =&gt; 0.0))
20099 ; printSize ("an array of length 10 of 2-ples of ints",
20100 Array.tabulate (10, fn i =&gt; (i, i + 1)))
20101 ; printSize ("a useless function", fn _ =&gt; 13)
20102 )
20103
20104 (* This is here so that the list is "useful".
20105 * If it were removed, then the optimizer (remove-unused-constructors)
20106 * would remove l entirely.
20107 *)
20108 val _ = if 10 = foldl (op +) 0 l
20109 then ()
20110 else raise Fail "bug"
20111
20112 local
20113 open MLton.Cont
20114 in
20115 val rc: int option t option ref = ref NONE
20116 val _ =
20117 case callcc (fn k: int option t =&gt; (rc := SOME k; throw (k, NONE))) of
20118 NONE =&gt; ()
20119 | SOME i =&gt; print (concat [Int.toString i, "\n"])
20120 end
20121
20122 val _ = printSize ("a continuation option ref", rc)
20123
20124 val _ =
20125 case !rc of
20126 NONE =&gt; ()
20127 | SOME k =&gt; (rc := NONE; MLton.Cont.throw (k, SOME 13))</programlisting>
20128 <simpara>Compile and run as usual.</simpara>
20129 <screen>% mlton size.sml
20130 % ./size
20131 The size of an int list of length 4 is 48 bytes.
20132 The size of a string of length 10 is 24 bytes.
20133 The size of an int array of length 10 is 52 bytes.
20134 The size of a double array of length 10 is 92 bytes.
20135 The size of an array of length 10 of 2-ples of ints is 92 bytes.
20136 The size of a useless function is 0 bytes.
20137 The size of a continuation option ref is 4544 bytes.
20138 13
20139 The size of a continuation option ref is 8 bytes.</screen>
20140 <simpara>Note that sizes are dependent upon the target platform and compiler
20141 optimizations.</simpara>
20142 <simpara><?asciidoc-pagebreak?></simpara>
20143 </section>
20144 </section>
20145 <section id="MLtonSyslog">
20146 <title>MLtonSyslog</title>
20147 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_SYSLOG =
20148 sig
20149 type openflag
20150
20151 val CONS : openflag
20152 val NDELAY : openflag
20153 val NOWAIT : openflag
20154 val ODELAY : openflag
20155 val PERROR : openflag
20156 val PID : openflag
20157
20158 type facility
20159
20160 val AUTHPRIV : facility
20161 val CRON : facility
20162 val DAEMON : facility
20163 val KERN : facility
20164 val LOCAL0 : facility
20165 val LOCAL1 : facility
20166 val LOCAL2 : facility
20167 val LOCAL3 : facility
20168 val LOCAL4 : facility
20169 val LOCAL5 : facility
20170 val LOCAL6 : facility
20171 val LOCAL7 : facility
20172 val LPR : facility
20173 val MAIL : facility
20174 val NEWS : facility
20175 val SYSLOG : facility
20176 val USER : facility
20177 val UUCP : facility
20178
20179 type loglevel
20180
20181 val EMERG : loglevel
20182 val ALERT : loglevel
20183 val CRIT : loglevel
20184 val ERR : loglevel
20185 val WARNING : loglevel
20186 val NOTICE : loglevel
20187 val INFO : loglevel
20188 val DEBUG : loglevel
20189
20190 val closelog: unit -&gt; unit
20191 val log: loglevel * string -&gt; unit
20192 val openlog: string * openflag list * facility -&gt; unit
20193 end</programlisting>
20194 <simpara><literal>MLton.Syslog</literal> is a complete interface to the system logging
20195 facilities. See <literal>man 3 syslog</literal> for more details.</simpara>
20196 <itemizedlist>
20197 <listitem>
20198 <simpara>
20199 <literal>closelog ()</literal>
20200 </simpara>
20201 <simpara>closes the connection to the system logger.</simpara>
20202 </listitem>
20203 <listitem>
20204 <simpara>
20205 <literal>log (l, s)</literal>
20206 </simpara>
20207 <simpara>logs message <literal>s</literal> at a loglevel <literal>l</literal>.</simpara>
20208 </listitem>
20209 <listitem>
20210 <simpara>
20211 <literal>openlog (name, flags, facility)</literal>
20212 </simpara>
20213 <simpara>opens a connection to the system logger. <literal>name</literal> will be prefixed to
20214 each message, and is typically set to the program name.</simpara>
20215 </listitem>
20216 </itemizedlist>
20217 <simpara><?asciidoc-pagebreak?></simpara>
20218 </section>
20219 <section id="MLtonTextIO">
20220 <title>MLtonTextIO</title>
20221 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_TEXT_IO = MLTON_IO</programlisting>
20222 <simpara>See <link linkend="MLtonIO">MLtonIO</link>.</simpara>
20223 <simpara><?asciidoc-pagebreak?></simpara>
20224 </section>
20225 <section id="MLtonThread">
20226 <title>MLtonThread</title>
20227 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_THREAD =
20228 sig
20229 structure AtomicState:
20230 sig
20231 datatype t = NonAtomic | Atomic of int
20232 end
20233
20234 val atomically: (unit -&gt; 'a) -&gt; 'a
20235 val atomicBegin: unit -&gt; unit
20236 val atomicEnd: unit -&gt; unit
20237 val atomicState: unit -&gt; AtomicState.t
20238
20239 structure Runnable:
20240 sig
20241 type t
20242 end
20243
20244 type 'a t
20245
20246 val atomicSwitch: ('a t -&gt; Runnable.t) -&gt; 'a
20247 val new: ('a -&gt; unit) -&gt; 'a t
20248 val prepend: 'a t * ('b -&gt; 'a) -&gt; 'b t
20249 val prepare: 'a t * 'a -&gt; Runnable.t
20250 val switch: ('a t -&gt; Runnable.t) -&gt; 'a
20251 end</programlisting>
20252 <simpara><literal>MLton.Thread</literal> provides access to MLton&#8217;s user-level thread
20253 implementation (i.e. not OS-level threads). Threads are lightweight
20254 data structures that represent a paused computation. Runnable threads
20255 are threads that will begin or continue computing when <literal>switch</literal>-ed to.
20256 <literal>MLton.Thread</literal> does not include a default scheduling mechanism, but it
20257 can be used to implement both preemptive and non-preemptive threads.</simpara>
20258 <itemizedlist>
20259 <listitem>
20260 <simpara>
20261 <literal>type AtomicState.t</literal>
20262 </simpara>
20263 <simpara>the type of atomic states.</simpara>
20264 </listitem>
20265 <listitem>
20266 <simpara>
20267 <literal>atomically f</literal>
20268 </simpara>
20269 <simpara>runs <literal>f</literal> in a critical section.</simpara>
20270 </listitem>
20271 <listitem>
20272 <simpara>
20273 <literal>atomicBegin ()</literal>
20274 </simpara>
20275 <simpara>begins a critical section.</simpara>
20276 </listitem>
20277 <listitem>
20278 <simpara>
20279 <literal>atomicEnd ()</literal>
20280 </simpara>
20281 <simpara>ends a critical section.</simpara>
20282 </listitem>
20283 <listitem>
20284 <simpara>
20285 <literal>atomicState ()</literal>
20286 </simpara>
20287 <simpara>returns the current atomic state.</simpara>
20288 </listitem>
20289 <listitem>
20290 <simpara>
20291 <literal>type Runnable.t</literal>
20292 </simpara>
20293 <simpara>the type of threads that can be resumed.</simpara>
20294 </listitem>
20295 <listitem>
20296 <simpara>
20297 <literal>type 'a t</literal>
20298 </simpara>
20299 <simpara>the type of threads that expect a value of type <literal>'a</literal>.</simpara>
20300 </listitem>
20301 <listitem>
20302 <simpara>
20303 <literal>atomicSwitch f</literal>
20304 </simpara>
20305 <simpara>like <literal>switch</literal>, but assumes an atomic calling context. Upon
20306 <literal>switch</literal>-ing back to the current thread, an implicit <literal>atomicEnd</literal> is
20307 performed.</simpara>
20308 </listitem>
20309 <listitem>
20310 <simpara>
20311 <literal>new f</literal>
20312 </simpara>
20313 <simpara>creates a new thread that, when run, applies <literal>f</literal> to the value given to
20314 the thread. <literal>f</literal> must terminate by `switch`ing to another thread or
20315 exiting the process.</simpara>
20316 </listitem>
20317 <listitem>
20318 <simpara>
20319 <literal>prepend (t, f)</literal>
20320 </simpara>
20321 <simpara>creates a new thread (destroying <literal>t</literal> in the process) that first
20322 applies <literal>f</literal> to the value given to the thread and then continues with
20323 <literal>t</literal>. This is a constant time operation.</simpara>
20324 </listitem>
20325 <listitem>
20326 <simpara>
20327 <literal>prepare (t, v)</literal>
20328 </simpara>
20329 <simpara>prepares a new runnable thread (destroying <literal>t</literal> in the process) that
20330 will evaluate <literal>t</literal> on <literal>v</literal>.</simpara>
20331 </listitem>
20332 <listitem>
20333 <simpara>
20334 <literal>switch f</literal>
20335 </simpara>
20336 <simpara>applies <literal>f</literal> to the current thread to get <literal>rt</literal>, and then start running
20337 thread <literal>rt</literal>. It is an error for <literal>f</literal> to perform another <literal>switch</literal>. <literal>f</literal>
20338 is guaranteed to run atomically.</simpara>
20339 </listitem>
20340 </itemizedlist>
20341 <section id="_example_of_non_preemptive_threads">
20342 <title>Example of non-preemptive threads</title>
20343 <programlisting language="sml" linenumbering="unnumbered">structure Queue:
20344 sig
20345 type 'a t
20346
20347 val new: unit -&gt; 'a t
20348 val enque: 'a t * 'a -&gt; unit
20349 val deque: 'a t -&gt; 'a option
20350 end =
20351 struct
20352 datatype 'a t = T of {front: 'a list ref, back: 'a list ref}
20353
20354 fun new () = T {front = ref [], back = ref []}
20355
20356 fun enque (T {back, ...}, x) = back := x :: !back
20357
20358 fun deque (T {front, back}) =
20359 case !front of
20360 [] =&gt; (case !back of
20361 [] =&gt; NONE
20362 | l =&gt; let val l = rev l
20363 in case l of
20364 [] =&gt; raise Fail "deque"
20365 | x :: l =&gt; (back := []; front := l; SOME x)
20366 end)
20367 | x :: l =&gt; (front := l; SOME x)
20368 end
20369
20370 structure Thread:
20371 sig
20372 val exit: unit -&gt; 'a
20373 val run: unit -&gt; unit
20374 val spawn: (unit -&gt; unit) -&gt; unit
20375 val yield: unit -&gt; unit
20376 end =
20377 struct
20378 open MLton
20379 open Thread
20380
20381 val topLevel: Thread.Runnable.t option ref = ref NONE
20382
20383 local
20384 val threads: Thread.Runnable.t Queue.t = Queue.new ()
20385 in
20386 fun ready (t: Thread.Runnable.t) : unit =
20387 Queue.enque(threads, t)
20388 fun next () : Thread.Runnable.t =
20389 case Queue.deque threads of
20390 NONE =&gt; valOf (!topLevel)
20391 | SOME t =&gt; t
20392 end
20393
20394 fun 'a exit (): 'a = switch (fn _ =&gt; next ())
20395
20396 fun new (f: unit -&gt; unit): Thread.Runnable.t =
20397 Thread.prepare
20398 (Thread.new (fn () =&gt; ((f () handle _ =&gt; exit ())
20399 ; exit ())),
20400 ())
20401
20402 fun schedule t = (ready t; next ())
20403
20404 fun yield (): unit = switch (fn t =&gt; schedule (Thread.prepare (t, ())))
20405
20406 val spawn = ready o new
20407
20408 fun run(): unit =
20409 (switch (fn t =&gt;
20410 (topLevel := SOME (Thread.prepare (t, ()))
20411 ; next()))
20412 ; topLevel := NONE)
20413 end
20414
20415 val rec loop =
20416 fn 0 =&gt; ()
20417 | n =&gt; (print(concat[Int.toString n, "\n"])
20418 ; Thread.yield()
20419 ; loop(n - 1))
20420
20421 val rec loop' =
20422 fn 0 =&gt; ()
20423 | n =&gt; (Thread.spawn (fn () =&gt; loop n); loop' (n - 2))
20424
20425 val _ = Thread.spawn (fn () =&gt; loop' 10)
20426
20427 val _ = Thread.run ()
20428
20429 val _ = print "success\n"</programlisting>
20430 </section>
20431 <section id="_example_of_preemptive_threads">
20432 <title>Example of preemptive threads</title>
20433 <programlisting language="sml" linenumbering="unnumbered">structure Queue:
20434 sig
20435 type 'a t
20436
20437 val new: unit -&gt; 'a t
20438 val enque: 'a t * 'a -&gt; unit
20439 val deque: 'a t -&gt; 'a option
20440 end =
20441 struct
20442 datatype 'a t = T of {front: 'a list ref, back: 'a list ref}
20443
20444 fun new () = T {front = ref [], back = ref []}
20445
20446 fun enque (T {back, ...}, x) = back := x :: !back
20447
20448 fun deque (T {front, back}) =
20449 case !front of
20450 [] =&gt; (case !back of
20451 [] =&gt; NONE
20452 | l =&gt; let val l = rev l
20453 in case l of
20454 [] =&gt; raise Fail "deque"
20455 | x :: l =&gt; (back := []; front := l; SOME x)
20456 end)
20457 | x :: l =&gt; (front := l; SOME x)
20458 end
20459
20460 structure Thread:
20461 sig
20462 val exit: unit -&gt; 'a
20463 val run: unit -&gt; unit
20464 val spawn: (unit -&gt; unit) -&gt; unit
20465 val yield: unit -&gt; unit
20466 end =
20467 struct
20468 open Posix.Signal
20469 open MLton
20470 open Itimer Signal Thread
20471
20472 val topLevel: Thread.Runnable.t option ref = ref NONE
20473
20474 local
20475 val threads: Thread.Runnable.t Queue.t = Queue.new ()
20476 in
20477 fun ready (t: Thread.Runnable.t) : unit =
20478 Queue.enque(threads, t)
20479 fun next () : Thread.Runnable.t =
20480 case Queue.deque threads of
20481 NONE =&gt; valOf (!topLevel)
20482 | SOME t =&gt; t
20483 end
20484
20485 fun 'a exit (): 'a = switch (fn _ =&gt; next ())
20486
20487 fun new (f: unit -&gt; unit): Thread.Runnable.t =
20488 Thread.prepare
20489 (Thread.new (fn () =&gt; ((f () handle _ =&gt; exit ())
20490 ; exit ())),
20491 ())
20492
20493 fun schedule t = (ready t; next ())
20494
20495 fun yield (): unit = switch (fn t =&gt; schedule (Thread.prepare (t, ())))
20496
20497 val spawn = ready o new
20498
20499 fun setItimer t =
20500 Itimer.set (Itimer.Real,
20501 {value = t,
20502 interval = t})
20503
20504 fun run (): unit =
20505 (switch (fn t =&gt;
20506 (topLevel := SOME (Thread.prepare (t, ()))
20507 ; new (fn () =&gt; (setHandler (alrm, Handler.handler schedule)
20508 ; setItimer (Time.fromMilliseconds 20)))))
20509 ; setItimer Time.zeroTime
20510 ; ignore alrm
20511 ; topLevel := NONE)
20512 end
20513
20514 val rec delay =
20515 fn 0 =&gt; ()
20516 | n =&gt; delay (n - 1)
20517
20518 val rec loop =
20519 fn 0 =&gt; ()
20520 | n =&gt; (delay 500000; loop (n - 1))
20521
20522 val rec loop' =
20523 fn 0 =&gt; ()
20524 | n =&gt; (Thread.spawn (fn () =&gt; loop n); loop' (n - 1))
20525
20526 val _ = Thread.spawn (fn () =&gt; loop' 10)
20527
20528 val _ = Thread.run ()
20529
20530 val _ = print "success\n"</programlisting>
20531 <simpara><?asciidoc-pagebreak?></simpara>
20532 </section>
20533 </section>
20534 <section id="MLtonVector">
20535 <title>MLtonVector</title>
20536 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_VECTOR =
20537 sig
20538 val create: int -&gt; {done: unit -&gt; 'a vector,
20539 sub: int -&gt; 'a,
20540 update: int * 'a -&gt; unit}
20541 val unfoldi: int * 'b * (int * 'b -&gt; 'a * 'b) -&gt; 'a vector * 'b
20542 end</programlisting>
20543 <itemizedlist>
20544 <listitem>
20545 <simpara>
20546 <literal>create n</literal>
20547 </simpara>
20548 <simpara>initiates the construction a vector <emphasis>v</emphasis> of length <literal>n</literal>, returning
20549 functions to manipulate the vector. The <literal>done</literal> function may be called
20550 to return the created vector; it is an error to call <literal>done</literal> before all
20551 entries have been initialized; it is an error to call <literal>done</literal> after
20552 having called <literal>done</literal>. The <literal>sub</literal> function may be called to return an
20553 initialized vector entry; it is not an error to call <literal>sub</literal> after
20554 having called <literal>done</literal>. The <literal>update</literal> function may be called to
20555 initialize a vector entry; it is an error to call <literal>update</literal> after
20556 having called <literal>done</literal>. One must initialize vector entries in order
20557 from lowest to highest; that is, before calling <literal>update (i, x)</literal>, one
20558 must have already called <literal>update (j, x)</literal> for all <literal>j</literal> in <literal>[0, i)</literal>. The
20559 <literal>done</literal>, <literal>sub</literal>, and <literal>update</literal> functions are all constant-time
20560 operations.</simpara>
20561 </listitem>
20562 <listitem>
20563 <simpara>
20564 <literal>unfoldi (n, b, f)</literal>
20565 </simpara>
20566 <simpara>constructs a vector <emphasis>v</emphasis> of length <literal>n</literal>, whose elements <emphasis>v<subscript>i</subscript></emphasis> are
20567 determined by the equations <emphasis>b<subscript>0</subscript> = b</emphasis> and
20568 <emphasis>(v<subscript>i</subscript>, b<subscript>i+1</subscript>) = f (i, b<subscript>i</subscript>)</emphasis>.</simpara>
20569 </listitem>
20570 </itemizedlist>
20571 <simpara><?asciidoc-pagebreak?></simpara>
20572 </section>
20573 <section id="MLtonWeak">
20574 <title>MLtonWeak</title>
20575 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_WEAK =
20576 sig
20577 type 'a t
20578
20579 val get: 'a t -&gt; 'a option
20580 val new: 'a -&gt; 'a t
20581 end</programlisting>
20582 <simpara>A weak pointer is a pointer to an object that is nulled if the object
20583 becomes <link linkend="Reachability">unreachable</link> due to garbage collection. The
20584 weak pointer does not itself cause the object it points to be retained
20585 by the garbage collector&#8201;&#8212;&#8201;only other strong pointers can do that.
20586 For objects that are not allocated in the heap, like integers, a weak
20587 pointer will always be nulled. So, if <literal>w: int Weak.t</literal>, then
20588 <literal>Weak.get w = NONE</literal>.</simpara>
20589 <itemizedlist>
20590 <listitem>
20591 <simpara>
20592 <literal>type 'a t</literal>
20593 </simpara>
20594 <simpara>the type of weak pointers to objects of type <literal>'a</literal></simpara>
20595 </listitem>
20596 <listitem>
20597 <simpara>
20598 <literal>get w</literal>
20599 </simpara>
20600 <simpara>returns <literal>NONE</literal> if the object pointed to by <literal>w</literal> no longer exists.
20601 Otherwise, returns <literal>SOME</literal> of the object pointed to by <literal>w</literal>.</simpara>
20602 </listitem>
20603 <listitem>
20604 <simpara>
20605 <literal>new x</literal>
20606 </simpara>
20607 <simpara>returns a weak pointer to <literal>x</literal>.</simpara>
20608 </listitem>
20609 </itemizedlist>
20610 <simpara><?asciidoc-pagebreak?></simpara>
20611 </section>
20612 <section id="MLtonWord">
20613 <title>MLtonWord</title>
20614 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_WORD =
20615 sig
20616 type t
20617
20618 val bswap: t -&gt; t
20619 val rol: t * word -&gt; t
20620 val ror: t * word -&gt; t
20621 end</programlisting>
20622 <itemizedlist>
20623 <listitem>
20624 <simpara>
20625 <literal>type t</literal>
20626 </simpara>
20627 <simpara>the type of words. For <literal>MLton.LargeWord</literal> this is <literal>LargeWord.word</literal>,
20628 for <literal>MLton.Word</literal> this is <literal>Word.word</literal>, for <literal>MLton.Word8</literal> this is
20629 <literal>Word8.word</literal>, for <literal>MLton.Word16</literal> this is <literal>Word16.word</literal>, for
20630 <literal>MLton.Word32</literal> this is <literal>Word32.word</literal>, for <literal>MLton.Word64</literal> this is
20631 <literal>Word64.word</literal>.</simpara>
20632 </listitem>
20633 <listitem>
20634 <simpara>
20635 <literal>bswap w</literal>
20636 </simpara>
20637 <simpara>byte swap.</simpara>
20638 </listitem>
20639 <listitem>
20640 <simpara>
20641 <literal>rol (w, w')</literal>
20642 </simpara>
20643 <simpara>rotates left (circular).</simpara>
20644 </listitem>
20645 <listitem>
20646 <simpara>
20647 <literal>ror (w, w')</literal>
20648 </simpara>
20649 <simpara>rotates right (circular).</simpara>
20650 </listitem>
20651 </itemizedlist>
20652 <simpara><?asciidoc-pagebreak?></simpara>
20653 </section>
20654 <section id="MLtonWorld">
20655 <title>MLtonWorld</title>
20656 <programlisting language="sml" linenumbering="unnumbered">signature MLTON_WORLD =
20657 sig
20658 datatype status = Clone | Original
20659
20660 val load: string -&gt; 'a
20661 val save: string -&gt; status
20662 val saveThread: string * Thread.Runnable.t -&gt; unit
20663 end</programlisting>
20664 <itemizedlist>
20665 <listitem>
20666 <simpara>
20667 <literal>datatype status</literal>
20668 </simpara>
20669 <simpara>specifies whether a world is original or restarted (a clone).</simpara>
20670 </listitem>
20671 <listitem>
20672 <simpara>
20673 <literal>load f</literal>
20674 </simpara>
20675 <simpara>loads the saved computation from file <literal>f</literal>.</simpara>
20676 </listitem>
20677 <listitem>
20678 <simpara>
20679 <literal>save f</literal>
20680 </simpara>
20681 <simpara>saves the entire state of the computation to the file <literal>f</literal>. The
20682 computation can then be restarted at a later time using <literal>World.load</literal>
20683 or the <literal>load-world</literal> <link linkend="RunTimeOptions">runtime option</link>. The call to
20684 <literal>save</literal> in the original computation returns <literal>Original</literal> and the call in
20685 the restarted world returns <literal>Clone</literal>.</simpara>
20686 </listitem>
20687 <listitem>
20688 <simpara>
20689 <literal>saveThread (f, rt)</literal>
20690 </simpara>
20691 <simpara>saves the entire state of the computation to the file <literal>f</literal> that will
20692 resume with thread <literal>rt</literal> upon restart.</simpara>
20693 </listitem>
20694 </itemizedlist>
20695 <section id="_notes_2">
20696 <title>Notes</title>
20697 <simpara><anchor id="MLtonWorld_ASLR" xreflabel="[MLtonWorld_ASLR]"/>
20698 Executables that save and load worlds are incompatible with
20699 <ulink url="http://en.wikipedia.org/wiki/Address_space_layout_randomization">address space layout randomization (ASLR)</ulink>
20700 of the executable (though, not of shared libraries). The state of a
20701 computation includes addresses into the code and data segments of the
20702 executable (e.g., static runtime-system data, return addresses); such
20703 addresses are invalid when interpreted by the executable loaded at a
20704 different base address.</simpara>
20705 <simpara>Executables that save and load worlds should be compiled with an
20706 option to suppress the generation of position-independent executables.</simpara>
20707 <itemizedlist>
20708 <listitem>
20709 <simpara>
20710 <link linkend="RunningOnDarwin">Darwin 11 (Mac OS X Lion) and higher</link> : <literal>-link-opt -fno-PIE</literal>
20711 </simpara>
20712 </listitem>
20713 </itemizedlist>
20714 </section>
20715 <section id="_example_6">
20716 <title>Example</title>
20717 <simpara>Suppose that <literal>save-world.sml</literal> contains the following.</simpara>
20718 <programlisting language="sml" linenumbering="unnumbered">open MLton.World
20719
20720 val _ =
20721 case save "world" of
20722 Original =&gt; print "I am the original\n"
20723 | Clone =&gt; print "I am the clone\n"</programlisting>
20724 <simpara>Then, if we compile <literal>save-world.sml</literal> and run it, the <literal>Original</literal>
20725 branch will execute, and a file named <literal>world</literal> will be created.</simpara>
20726 <screen>% mlton save-world.sml
20727 % ./save-world
20728 I am the original</screen>
20729 <simpara>We can then load <literal>world</literal> using the <literal>load-world</literal>
20730 <link linkend="RunTimeOptions">run time option</link>.</simpara>
20731 <screen>% ./save-world @MLton load-world world --
20732 I am the clone</screen>
20733 <simpara><?asciidoc-pagebreak?></simpara>
20734 </section>
20735 </section>
20736 <section id="MLULex">
20737 <title>MLULex</title>
20738 <simpara><ulink url="http://smlnj-gforge.cs.uchicago.edu/projects/ml-lpt/">MLULex</ulink> is a
20739 scanner generator for <link linkend="StandardML">Standard ML</link>.</simpara>
20740 <section id="_also_see_17">
20741 <title>Also see</title>
20742 <itemizedlist>
20743 <listitem>
20744 <simpara>
20745 <link linkend="MLAntlr">MLAntlr</link>
20746 </simpara>
20747 </listitem>
20748 <listitem>
20749 <simpara>
20750 <link linkend="MLLPTLibrary">MLLPTLibrary</link>
20751 </simpara>
20752 </listitem>
20753 <listitem>
20754 <simpara>
20755 <link linkend="References_OwensEtAl09">OwensEtAl09</link>
20756 </simpara>
20757 </listitem>
20758 </itemizedlist>
20759 <simpara><?asciidoc-pagebreak?></simpara>
20760 </section>
20761 </section>
20762 <section id="MLYacc">
20763 <title>MLYacc</title>
20764 <simpara><link linkend="MLYacc">MLYacc</link> is a parser generator for <link linkend="StandardML">Standard ML</link> modeled
20765 after the Yacc parser generator.</simpara>
20766 <simpara>A version of MLYacc, ported from the <link linkend="SMLNJ">SML/NJ</link> sources, is
20767 distributed with MLton.</simpara>
20768 <section id="_also_see_18">
20769 <title>Also see</title>
20770 <itemizedlist>
20771 <listitem>
20772 <simpara>
20773 <ulink url="guide/Documentation.attachments/mlyacc.pdf"><literal>mlyacc.pdf</literal></ulink>
20774 </simpara>
20775 </listitem>
20776 <listitem>
20777 <simpara>
20778 <link linkend="MLLex">MLLex</link>
20779 </simpara>
20780 </listitem>
20781 <listitem>
20782 <simpara>
20783 <link linkend="References_TarditiAppel00">TarditiAppel00</link>
20784 </simpara>
20785 </listitem>
20786 <listitem>
20787 <simpara>
20788 <link linkend="References_Price09">Price09</link>
20789 </simpara>
20790 </listitem>
20791 </itemizedlist>
20792 <simpara><?asciidoc-pagebreak?></simpara>
20793 </section>
20794 </section>
20795 <section id="Monomorphise">
20796 <title>Monomorphise</title>
20797 <simpara><link linkend="Monomorphise">Monomorphise</link> is a translation pass from the <link linkend="XML">XML</link>
20798 <link linkend="IntermediateLanguage">IntermediateLanguage</link> to the <link linkend="SXML">SXML</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>.</simpara>
20799 <section id="_description_38">
20800 <title>Description</title>
20801 <simpara>Monomorphisation eliminates polymorphic values and datatype
20802 declarations by duplicating them for each type at which they are used.</simpara>
20803 <simpara>Consider the following <link linkend="XML">XML</link> program.</simpara>
20804 <programlisting language="sml" linenumbering="unnumbered">datatype 'a t = T of 'a
20805 fun 'a f (x: 'a) = T x
20806 val a = f 1
20807 val b = f 2
20808 val z = f (3, 4)</programlisting>
20809 <simpara>The result of monomorphising this program is the following <link linkend="SXML">SXML</link> program:</simpara>
20810 <programlisting language="sml" linenumbering="unnumbered">datatype t1 = T1 of int
20811 datatype t2 = T2 of int * int
20812 fun f1 (x: int) = T1 x
20813 fun f2 (x: int * int) = T2 x
20814 val a = f1 1
20815 val b = f1 2
20816 val z = f2 (3, 4)</programlisting>
20817 </section>
20818 <section id="_implementation_41">
20819 <title>Implementation</title>
20820 <itemizedlist>
20821 <listitem>
20822 <simpara>
20823 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/monomorphise.sig"><literal>monomorphise.sig</literal></ulink>
20824 </simpara>
20825 </listitem>
20826 <listitem>
20827 <simpara>
20828 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/monomorphise.fun"><literal>monomorphise.fun</literal></ulink>
20829 </simpara>
20830 </listitem>
20831 </itemizedlist>
20832 </section>
20833 <section id="_details_and_notes_41">
20834 <title>Details and Notes</title>
20835 <simpara>The monomorphiser works by making one pass over the entire program.
20836 On the way down, it creates a cache for each variable declared in a
20837 polymorphic declaration that maps a lists of type arguments to a new
20838 variable name. At a variable reference, it consults the cache (based
20839 on the types the variable is applied to). If there is already an
20840 entry in the cache, it is used. If not, a new entry is created. On
20841 the way up, the monomorphiser duplicates a variable declaration for
20842 each entry in the cache.</simpara>
20843 <simpara>As with variables, the monomorphiser records all of the type at which
20844 constructors are used. After the entire program is processed, the
20845 monomorphiser duplicates each datatype declaration and its associated
20846 constructors.</simpara>
20847 <simpara>The monomorphiser duplicates all of the functions declared in a
20848 <literal>fun</literal> declaration as a unit. Consider the following program</simpara>
20849 <programlisting language="sml" linenumbering="unnumbered">fun 'a f (x: 'a) = g x
20850 and g (y: 'a) = f y
20851 val a = f 13
20852 val b = g 14
20853 val c = f (1, 2)</programlisting>
20854 <simpara>and its monomorphisation</simpara>
20855 <programlisting language="sml" linenumbering="unnumbered">fun f1 (x: int) = g1 x
20856 and g1 (y: int) = f1 y
20857 fun f2 (x : int * int) = g2 x
20858 and g2 (y : int * int) = f2 y
20859 val a = f1 13
20860 val b = g1 14
20861 val c = f2 (1, 2)</programlisting>
20862 </section>
20863 <section id="_pathological_datatype_declarations">
20864 <title>Pathological datatype declarations</title>
20865 <simpara>SML allows a pathological polymorphic datatype declaration in which
20866 recursive uses of the defined type constructor are applied to
20867 different type arguments than the definition. This has been
20868 disallowed by others on type theoretic grounds. A canonical example
20869 is the following.</simpara>
20870 <programlisting language="sml" linenumbering="unnumbered">datatype 'a t = A of 'a | B of ('a * 'a) t
20871 val z : int t = B (B (A ((1, 2), (3, 4))))</programlisting>
20872 <simpara>The presence of the recursion in the datatype declaration might appear
20873 to cause the need for the monomorphiser to create an infinite number
20874 of types. However, due to the absence of polymorphic recursion in
20875 SML, there are in fact only a finite number of instances of such types
20876 in any given program. The monomorphiser translates the above program
20877 to the following one.</simpara>
20878 <programlisting language="sml" linenumbering="unnumbered">datatype t1 = B1 of t2
20879 datatype t2 = B2 of t3
20880 datatype t3 = A3 of (int * int) * (int * int)
20881 val z : int t = B1 (B2 (A3 ((1, 2), (3, 4))))</programlisting>
20882 <simpara>It is crucial that the monomorphiser be allowed to drop unused
20883 constructors from datatype declarations in order for the translation
20884 to terminate.</simpara>
20885 <simpara><?asciidoc-pagebreak?></simpara>
20886 </section>
20887 </section>
20888 <section id="MoscowML">
20889 <title>MoscowML</title>
20890 <simpara><ulink url="http://mosml.org">Moscow ML</ulink> is a
20891 <link linkend="StandardMLImplementations">Standard ML implementation</link>. It is a
20892 byte-code compiler, so it compiles code quickly, but the code runs
20893 slowly. See <link linkend="Performance">Performance</link>.</simpara>
20894 <simpara><?asciidoc-pagebreak?></simpara>
20895 </section>
20896 <section id="Multi">
20897 <title>Multi</title>
20898 <simpara><link linkend="Multi">Multi</link> is an analysis pass for the <link linkend="SSA">SSA</link>
20899 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="ConstantPropagation">ConstantPropagation</link> and
20900 <link linkend="LocalRef">LocalRef</link>.</simpara>
20901 <section id="_description_39">
20902 <title>Description</title>
20903 <simpara>This pass analyzes the control flow of a <link linkend="SSA">SSA</link> program to determine
20904 which <link linkend="SSA">SSA</link> functions and blocks might be executed more than once or
20905 by more than one thread. It also determines when a program uses
20906 threads and when functions and blocks directly or indirectly invoke
20907 <literal>Thread_copyCurrent</literal>.</simpara>
20908 </section>
20909 <section id="_implementation_42">
20910 <title>Implementation</title>
20911 <itemizedlist>
20912 <listitem>
20913 <simpara>
20914 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/multi.sig"><literal>multi.sig</literal></ulink>
20915 </simpara>
20916 </listitem>
20917 <listitem>
20918 <simpara>
20919 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/multi.fun"><literal>multi.fun</literal></ulink>
20920 </simpara>
20921 </listitem>
20922 </itemizedlist>
20923 </section>
20924 <section id="_details_and_notes_42">
20925 <title>Details and Notes</title>
20926 <simpara></simpara>
20927 <simpara><?asciidoc-pagebreak?></simpara>
20928 </section>
20929 </section>
20930 <section id="Mutable">
20931 <title>Mutable</title>
20932 <simpara>Mutable is an adjective meaning "can be modified". In
20933 <link linkend="StandardML">Standard ML</link>, ref cells and arrays are mutable, while all
20934 other values are <link linkend="Immutable">immutable</link>.</simpara>
20935 <simpara><?asciidoc-pagebreak?></simpara>
20936 </section>
20937 <section id="NeedsReview">
20938 <title>NeedsReview</title>
20939 <simpara>This page documents some patches and bug fixes that need additional review by experienced developers:</simpara>
20940 <itemizedlist>
20941 <listitem>
20942 <simpara>
20943 Bug in transparent signature match:
20944 </simpara>
20945 <itemizedlist>
20946 <listitem>
20947 <simpara>
20948 What is an <emphasis>original</emphasis> interface and why does the equivalence of original interfaces implies the equivalence of the actual interfaces?
20949 </simpara>
20950 </listitem>
20951 <listitem>
20952 <simpara>
20953 <ulink url="http://www.mlton.org/pipermail/mlton/2007-September/029991.html">http://www.mlton.org/pipermail/mlton/2007-September/029991.html</ulink>
20954 </simpara>
20955 </listitem>
20956 <listitem>
20957 <simpara>
20958 <ulink url="http://www.mlton.org/pipermail/mlton/2007-September/029995.html">http://www.mlton.org/pipermail/mlton/2007-September/029995.html</ulink>
20959 </simpara>
20960 </listitem>
20961 <listitem>
20962 <simpara>
20963 SVN Revision: <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6046"><literal>r6046</literal></ulink>
20964 </simpara>
20965 </listitem>
20966 </itemizedlist>
20967 </listitem>
20968 <listitem>
20969 <simpara>
20970 Bug in <link linkend="DeepFlatten">DeepFlatten</link> pass:
20971 </simpara>
20972 <itemizedlist>
20973 <listitem>
20974 <simpara>
20975 Should we allow argument to <literal>Weak_new</literal> to be flattened?
20976 </simpara>
20977 </listitem>
20978 <listitem>
20979 <simpara>
20980 SVN Revision: <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6189"><literal>r6189</literal></ulink> (regression test demonstrating bug)
20981 </simpara>
20982 </listitem>
20983 <listitem>
20984 <simpara>
20985 SVN Revision: <ulink url="https://github.com/MLton/mlton/commit/%3A%2FSVN%20r6191"><literal>r6191</literal></ulink>
20986 </simpara>
20987 </listitem>
20988 </itemizedlist>
20989 </listitem>
20990 </itemizedlist>
20991 <simpara><?asciidoc-pagebreak?></simpara>
20992 </section>
20993 <section id="NumericLiteral">
20994 <title>NumericLiteral</title>
20995 <simpara>Numeric literals in <link linkend="StandardML">Standard ML</link> can be written in either
20996 decimal or hexadecimal notation. Sometimes it can be convenient to
20997 write numbers down in other bases. Fortunately, using <link linkend="Fold">Fold</link>, it is
20998 possible to define a concise syntax for numeric literals that allows
20999 one to write numeric constants in any base and of various types
21000 (<literal>int</literal>, <literal>IntInf.int</literal>, <literal>word</literal>, and more).</simpara>
21001 <simpara>We will define constants <literal>I</literal>, <literal>II</literal>, <literal>W</literal>, and <literal>`</literal> so
21002 that, for example,</simpara>
21003 <programlisting language="sml" linenumbering="unnumbered">I 10 `1`2`3 $</programlisting>
21004 <simpara>denotes <literal>123:int</literal> in base 10, while</simpara>
21005 <programlisting language="sml" linenumbering="unnumbered">II 8 `2`3 $</programlisting>
21006 <simpara>denotes <literal>19:IntInf.int</literal> in base 8, and</simpara>
21007 <programlisting language="sml" linenumbering="unnumbered">W 2 `1`1`0`1 $</programlisting>
21008 <simpara>denotes <literal>0w13: word</literal>.</simpara>
21009 <simpara>Here is the code.</simpara>
21010 <programlisting language="sml" linenumbering="unnumbered">structure Num =
21011 struct
21012 fun make (op *, op +, i2x) iBase =
21013 let
21014 val xBase = i2x iBase
21015 in
21016 Fold.fold
21017 ((i2x 0,
21018 fn (i, x) =&gt;
21019 if 0 &lt;= i andalso i &lt; iBase then
21020 x * xBase + i2x i
21021 else
21022 raise Fail (concat
21023 ["Num: ", Int.toString i,
21024 " is not a valid\
21025 \ digit in base ",
21026 Int.toString iBase])),
21027 fst)
21028 end
21029
21030 fun I ? = make (op *, op +, id) ?
21031 fun II ? = make (op *, op +, IntInf.fromInt) ?
21032 fun W ? = make (op *, op +, Word.fromInt) ?
21033
21034 fun ` ? = Fold.step1 (fn (i, (x, step)) =&gt;
21035 (step (i, x), step)) ?
21036
21037 val a = 10
21038 val b = 11
21039 val c = 12
21040 val d = 13
21041 val e = 14
21042 val f = 15
21043 end</programlisting>
21044 <simpara>where</simpara>
21045 <programlisting language="sml" linenumbering="unnumbered">fun fst (x, _) = x</programlisting>
21046 <simpara>The idea is for the fold to start with zero and to construct the
21047 result one digit at a time, with each stepper multiplying the previous
21048 result by the base and adding the next digit. The code is abstracted
21049 in two different ways for extra generality. First, the <literal>make</literal>
21050 function abstracts over the various primitive operations (addition,
21051 multiplication, etc) that are needed to construct a number. This
21052 allows the same code to be shared for constants <literal>I</literal>, <literal>II</literal>, <literal>W</literal> used to
21053 write down the various numeric types. It also allows users to add new
21054 constants for additional numeric types, by supplying the necessary
21055 arguments to make.</simpara>
21056 <simpara>Second, the step function, <literal>&grave;</literal>, is abstracted over the actual
21057 construction operation, which is created by make, and passed along the
21058 fold. This allows the same constant, <literal>&grave;</literal>, to be used for all
21059 numeric types. The alternative approach, having a different step
21060 function for each numeric type, would be more painful to use.</simpara>
21061 <simpara>On the surface, it appears that the code checks the digits dynamically
21062 to ensure they are valid for the base. However, MLton will simplify
21063 everything away at compile time, leaving just the final numeric
21064 constant.</simpara>
21065 <simpara><?asciidoc-pagebreak?></simpara>
21066 </section>
21067 <section id="ObjectOrientedProgramming">
21068 <title>ObjectOrientedProgramming</title>
21069 <simpara><link linkend="StandardML">Standard ML</link> does not have explicit support for
21070 object-oriented programming. Here are some papers that show how to
21071 express certain object-oriented concepts in SML.</simpara>
21072 <itemizedlist>
21073 <listitem>
21074 <simpara>
21075 <link linkend="References_Berthomieu00">OO Programming styles in ML</link>
21076 </simpara>
21077 </listitem>
21078 <listitem>
21079 <simpara>
21080 <link linkend="References_ThorupTofte94">Object-oriented programming and Standard ML</link>
21081 </simpara>
21082 </listitem>
21083 <listitem>
21084 <simpara>
21085 <link linkend="References_LarsenNiss04">mGTK: An SML binding of Gtk+</link>
21086 </simpara>
21087 </listitem>
21088 <listitem>
21089 <simpara>
21090 <link linkend="References_FluetPucella06">Phantom Types and Subtyping</link>
21091 </simpara>
21092 </listitem>
21093 </itemizedlist>
21094 <simpara>The question of OO programming in SML comes up every now and then.
21095 The following discusses a simple object-oriented (OO) programming
21096 technique in Standard ML. The reader is assumed to be able to read
21097 Java and SML code.</simpara>
21098 <section id="_motivation">
21099 <title>Motivation</title>
21100 <simpara>SML doesn&#8217;t provide subtyping, but it does provide parametric
21101 polymorphism, which can be used to encode some forms of subtyping.
21102 Most articles on OO programming in SML concentrate on such encoding
21103 techniques. While those techniques are interesting&#8201;&#8212;&#8201;and it is
21104 recommended to read such articles&#8201;&#8212;&#8201;and sometimes useful, it seems
21105 that basically all OO gurus agree that (deep) subtyping (or
21106 inheritance) hierarchies aren&#8217;t as practical as they were thought to
21107 be in the early OO days. "Good", flexible, "OO" designs tend to have
21108 a flat structure</simpara>
21109 <screen> Interface
21110 ^
21111 |
21112 - - -+-------+-------+- - -
21113 | | |
21114 ImplA ImplB ImplC</screen>
21115 <simpara>and deep inheritance hierarchies</simpara>
21116 <screen>ClassA
21117 ^
21118 |
21119 ClassB
21120 ^
21121 |
21122 ClassC
21123 ^
21124 |</screen>
21125 <simpara>tend to be signs of design mistakes. There are good underlying
21126 reasons for this, but a thorough discussion is not in the scope of
21127 this article. However, the point is that perhaps the encoding of
21128 subtyping is not as important as one might believe. In the following
21129 we ignore subtyping and rather concentrate on a very simple and basic
21130 dynamic dispatch technique.</simpara>
21131 </section>
21132 <section id="_dynamic_dispatch_using_a_recursive_record_of_functions">
21133 <title>Dynamic Dispatch Using a Recursive Record of Functions</title>
21134 <simpara>Quite simply, the basic idea is to implement a "virtual function
21135 table" using a record that is wrapped inside a (possibly recursive)
21136 datatype. Let&#8217;s first take a look at a simple concrete example.</simpara>
21137 <simpara>Consider the following Java interface:</simpara>
21138 <screen>public interface Counter {
21139 public void inc();
21140 public int get();
21141 }</screen>
21142 <simpara>We can translate the <literal>Counter</literal> interface to SML as follows:</simpara>
21143 <programlisting language="sml" linenumbering="unnumbered">datatype counter = Counter of {inc : unit -&gt; unit, get : unit -&gt; int}</programlisting>
21144 <simpara>Each value of type <literal>counter</literal> can be thought of as an object that
21145 responds to two messages <literal>inc</literal> and <literal>get</literal>. To actually send messages
21146 to a counter, it is useful to define auxiliary functions</simpara>
21147 <programlisting language="sml" linenumbering="unnumbered">local
21148 fun mk m (Counter t) = m t ()
21149 in
21150 val cGet = mk#get
21151 val cInc = mk#inc
21152 end</programlisting>
21153 <simpara>that basically extract the "function table" <literal>t</literal> from a counter object
21154 and then select the specified method <literal>m</literal> from the table.</simpara>
21155 <simpara>Let&#8217;s then implement a simple function that increments a counter until a
21156 given maximum is reached:</simpara>
21157 <programlisting language="sml" linenumbering="unnumbered">fun incUpto counter max = while cGet counter &lt; max do cInc counter</programlisting>
21158 <simpara>You can easily verify that the above code compiles even without any
21159 concrete implementation of a counter, thus it is clear that it doesn&#8217;t
21160 depend on a particular counter implementation.</simpara>
21161 <simpara>Let&#8217;s then implement a couple of counters. First consider the
21162 following Java class implementing the <literal>Counter</literal> interface given earlier.</simpara>
21163 <screen>public class BasicCounter implements Counter {
21164 private int cnt;
21165 public BasicCounter(int initialCnt) { this.cnt = initialCnt; }
21166 public void inc() { this.cnt += 1; }
21167 public int get() { return this.cnt; }
21168 }</screen>
21169 <simpara>We can translate the above to SML as follows:</simpara>
21170 <programlisting language="sml" linenumbering="unnumbered">fun newBasicCounter initialCnt = let
21171 val cnt = ref initialCnt
21172 in
21173 Counter {inc = fn () =&gt; cnt := !cnt + 1,
21174 get = fn () =&gt; !cnt}
21175 end</programlisting>
21176 <simpara>The SML function <literal>newBasicCounter</literal> can be described as a constructor
21177 function for counter objects of the <literal>BasicCounter</literal> "class". We can
21178 also have other counter implementations. Here is the constructor for
21179 a counter decorator that logs messages:</simpara>
21180 <programlisting language="sml" linenumbering="unnumbered">fun newLoggedCounter counter =
21181 Counter {inc = fn () =&gt; (print "inc\n" ; cInc counter),
21182 get = fn () =&gt; (print "get\n" ; cGet counter)}</programlisting>
21183 <simpara>The <literal>incUpto</literal> function works just as well with objects of either
21184 class:</simpara>
21185 <programlisting language="sml" linenumbering="unnumbered">val aCounter = newBasicCounter 0
21186 val () = incUpto aCounter 5
21187 val () = print (Int.toString (cGet aCounter) ^"\n")
21188
21189 val aCounter = newLoggedCounter (newBasicCounter 0)
21190 val () = incUpto aCounter 5
21191 val () = print (Int.toString (cGet aCounter) ^"\n")</programlisting>
21192 <simpara>In general, a dynamic dispatch interface is represented as a record
21193 type wrapped inside a datatype. Each field of the record corresponds
21194 to a public method or field of the object:</simpara>
21195 <programlisting language="sml" linenumbering="unnumbered">datatype interface =
21196 Interface of {method : t1 -&gt; t2,
21197 immutableField : t,
21198 mutableField : t ref}</programlisting>
21199 <simpara>The reason for wrapping the record inside a datatype is that records,
21200 in SML, can not be recursive. However, SML datatypes can be
21201 recursive. A record wrapped in a datatype can contain fields that
21202 contain the datatype. For example, an interface such as <literal>Cloneable</literal></simpara>
21203 <programlisting language="sml" linenumbering="unnumbered">datatype cloneable = Cloneable of {clone : unit -&gt; cloneable}</programlisting>
21204 <simpara>can be represented using recursive datatypes.</simpara>
21205 <simpara>Like in OO languages, interfaces are abstract and can not be
21206 instantiated to produce objects. To be able to instantiate objects,
21207 the constructors of a concrete class are needed. In SML, we can
21208 implement constructors as simple functions from arbitrary arguments to
21209 values of the interface type. Such a constructor function can
21210 encapsulate arbitrary private state and functions using lexical
21211 closure. It is also easy to share implementations of methods between
21212 two or more constructors.</simpara>
21213 <simpara>While the <literal>Counter</literal> example is rather trivial, it should not be
21214 difficult to see that this technique quite simply doesn&#8217;t require a huge
21215 amount of extra verbiage and is more than usable in practice.</simpara>
21216 </section>
21217 <section id="_sml_modules_and_dynamic_dispatch">
21218 <title>SML Modules and Dynamic Dispatch</title>
21219 <simpara>One might wonder about how SML modules and the dynamic dispatch
21220 technique work together. Let&#8217;s investigate! Let&#8217;s use a simple
21221 dispenser framework as a concrete example. (Note that this isn&#8217;t
21222 intended to be an introduction to the SML module system.)</simpara>
21223 <section id="_programming_with_sml_modules">
21224 <title>Programming with SML Modules</title>
21225 <simpara>Using SML signatures we can specify abstract data types (ADTs) such as
21226 dispensers. Here is a signature for an "abstract" functional (as
21227 opposed to imperative) dispenser:</simpara>
21228 <programlisting language="sml" linenumbering="unnumbered">signature ABSTRACT_DISPENSER = sig
21229 type 'a t
21230 val isEmpty : 'a t -&gt; bool
21231 val push : 'a * 'a t -&gt; 'a t
21232 val pop : 'a t -&gt; ('a * 'a t) option
21233 end</programlisting>
21234 <simpara>The term "abstract" in the name of the signature refers to the fact that
21235 the signature gives no way to instantiate a dispenser. It has nothing to
21236 do with the concept of abstract data types.</simpara>
21237 <simpara>Using SML functors we can write "generic" algorithms that manipulate
21238 dispensers of an unknown type. Here are a couple of very simple
21239 algorithms:</simpara>
21240 <programlisting language="sml" linenumbering="unnumbered">functor DispenserAlgs (D : ABSTRACT_DISPENSER) = struct
21241 open D
21242
21243 fun pushAll (xs, d) = foldl push d xs
21244
21245 fun popAll d = let
21246 fun lp (xs, NONE) = rev xs
21247 | lp (xs, SOME (x, d)) = lp (x::xs, pop d)
21248 in
21249 lp ([], pop d)
21250 end
21251
21252 fun cp (from, to) = pushAll (popAll from, to)
21253 end</programlisting>
21254 <simpara>As one can easily verify, the above compiles even without any concrete
21255 dispenser structure. Functors essentially provide a form a static
21256 dispatch that one can use to break compile-time dependencies.</simpara>
21257 <simpara>We can also give a signature for a concrete dispenser</simpara>
21258 <programlisting language="sml" linenumbering="unnumbered">signature DISPENSER = sig
21259 include ABSTRACT_DISPENSER
21260 val empty : 'a t
21261 end</programlisting>
21262 <simpara>and write any number of concrete structures implementing the signature.
21263 For example, we could implement stacks</simpara>
21264 <programlisting language="sml" linenumbering="unnumbered">structure Stack :&gt; DISPENSER = struct
21265 type 'a t = 'a list
21266 val empty = []
21267 val isEmpty = null
21268 val push = op ::
21269 val pop = List.getItem
21270 end</programlisting>
21271 <simpara>and queues</simpara>
21272 <programlisting language="sml" linenumbering="unnumbered">structure Queue :&gt; DISPENSER = struct
21273 datatype 'a t = T of 'a list * 'a list
21274 val empty = T ([], [])
21275 val isEmpty = fn T ([], _) =&gt; true | _ =&gt; false
21276 val normalize = fn ([], ys) =&gt; (rev ys, []) | q =&gt; q
21277 fun push (y, T (xs, ys)) = T (normalize (xs, y::ys))
21278 val pop = fn (T (x::xs, ys)) =&gt; SOME (x, T (normalize (xs, ys))) | _ =&gt; NONE
21279 end</programlisting>
21280 <simpara>One can now write code that uses either the <literal>Stack</literal> or the <literal>Queue</literal>
21281 dispenser. One can also instantiate the previously defined functor to
21282 create functions for manipulating dispensers of a type:</simpara>
21283 <programlisting language="sml" linenumbering="unnumbered">structure S = DispenserAlgs (Stack)
21284 val [4,3,2,1] = S.popAll (S.pushAll ([1,2,3,4], Stack.empty))
21285
21286 structure Q = DispenserAlgs (Queue)
21287 val [1,2,3,4] = Q.popAll (Q.pushAll ([1,2,3,4], Queue.empty))</programlisting>
21288 <simpara>There is no dynamic dispatch involved at the module level in SML. An
21289 attempt to do dynamic dispatch</simpara>
21290 <programlisting language="sml" linenumbering="unnumbered">val q = Q.push (1, Stack.empty)</programlisting>
21291 <simpara>will give a type error.</simpara>
21292 </section>
21293 <section id="_combining_sml_modules_and_dynamic_dispatch">
21294 <title>Combining SML Modules and Dynamic Dispatch</title>
21295 <simpara>Let&#8217;s then combine SML modules and the dynamic dispatch technique
21296 introduced in this article. First we define an interface for
21297 dispensers:</simpara>
21298 <programlisting language="sml" linenumbering="unnumbered">structure Dispenser = struct
21299 datatype 'a t =
21300 I of {isEmpty : unit -&gt; bool,
21301 push : 'a -&gt; 'a t,
21302 pop : unit -&gt; ('a * 'a t) option}
21303
21304 fun O m (I t) = m t
21305
21306 fun isEmpty t = O#isEmpty t ()
21307 fun push (v, t) = O#push t v
21308 fun pop t = O#pop t ()
21309 end</programlisting>
21310 <simpara>The <literal>Dispenser</literal> module, which we can think of as an interface for
21311 dispensers, implements the <literal>ABSTRACT_DISPENSER</literal> signature using
21312 the dynamic dispatch technique, but we leave the signature ascription
21313 until later.</simpara>
21314 <simpara>Then we define a <literal>DispenserClass</literal> functor that makes a "class" out of
21315 a given dispenser module:</simpara>
21316 <programlisting language="sml" linenumbering="unnumbered">functor DispenserClass (D : DISPENSER) : DISPENSER = struct
21317 open Dispenser
21318
21319 fun make d =
21320 I {isEmpty = fn () =&gt; D.isEmpty d,
21321 push = fn x =&gt; make (D.push (x, d)),
21322 pop = fn () =&gt;
21323 case D.pop d of
21324 NONE =&gt; NONE
21325 | SOME (x, d) =&gt; SOME (x, make d)}
21326
21327 val empty =
21328 I {isEmpty = fn () =&gt; true,
21329 push = fn x =&gt; make (D.push (x, D.empty)),
21330 pop = fn () =&gt; NONE}
21331 end</programlisting>
21332 <simpara>Finally we seal the <literal>Dispenser</literal> module:</simpara>
21333 <programlisting language="sml" linenumbering="unnumbered">structure Dispenser : ABSTRACT_DISPENSER = Dispenser</programlisting>
21334 <simpara>This isn&#8217;t necessary for type safety, because the unsealed <literal>Dispenser</literal>
21335 module does not allow one to break encapsulation, but makes sure that
21336 only the <literal>DispenserClass</literal> functor can create dispenser classes
21337 (because the constructor <literal>Dispenser.I</literal> is no longer accessible).</simpara>
21338 <simpara>Using the <literal>DispenserClass</literal> functor we can turn any concrete dispenser
21339 module into a dispenser class:</simpara>
21340 <programlisting language="sml" linenumbering="unnumbered">structure StackClass = DispenserClass (Stack)
21341 structure QueueClass = DispenserClass (Queue)</programlisting>
21342 <simpara>Each dispenser class implements the same dynamic dispatch interface
21343 and the <literal>ABSTRACT_DISPENSER</literal> -signature.</simpara>
21344 <simpara>Because the dynamic dispatch <literal>Dispenser</literal> module implements the
21345 <literal>ABSTRACT_DISPENSER</literal>-signature, we can use it to instantiate the
21346 <literal>DispenserAlgs</literal>-functor:</simpara>
21347 <programlisting language="sml" linenumbering="unnumbered">structure D = DispenserAlgs (Dispenser)</programlisting>
21348 <simpara>The resulting <literal>D</literal> module, like the <literal>Dispenser</literal> module, works with
21349 any dispenser class and uses dynamic dispatch:</simpara>
21350 <programlisting language="sml" linenumbering="unnumbered">val [4, 3, 2, 1] = D.popAll (D.pushAll ([1, 2, 3, 4], StackClass.empty))
21351 val [1, 2, 3, 4] = D.popAll (D.pushAll ([1, 2, 3, 4], QueueClass.empty))</programlisting>
21352 <simpara><?asciidoc-pagebreak?></simpara>
21353 </section>
21354 </section>
21355 </section>
21356 <section id="OCaml">
21357 <title>OCaml</title>
21358 <simpara><ulink url="http://caml.inria.fr/">OCaml</ulink> is a variant of <link linkend="ML">ML</link> and is similar to
21359 <link linkend="StandardML">Standard ML</link>.</simpara>
21360 <section id="_ocaml_and_sml">
21361 <title>OCaml and SML</title>
21362 <simpara>Here&#8217;s a comparison of some aspects of the OCaml and SML languages.</simpara>
21363 <itemizedlist>
21364 <listitem>
21365 <simpara>
21366 Standard ML has a formal <link linkend="DefinitionOfStandardML">Definition</link>, while
21367 OCaml is specified by its lone implementation and informal
21368 documentation.
21369 </simpara>
21370 </listitem>
21371 <listitem>
21372 <simpara>
21373 Standard ML has a number of <link linkend="StandardMLImplementations">compilers</link>,
21374 while OCaml has only one.
21375 </simpara>
21376 </listitem>
21377 <listitem>
21378 <simpara>
21379 OCaml has built-in support for object-oriented programming, while
21380 Standard ML does not (however, see <link linkend="ObjectOrientedProgramming">ObjectOrientedProgramming</link>).
21381 </simpara>
21382 </listitem>
21383 <listitem>
21384 <simpara>
21385 Andreas Rossberg has a
21386 <ulink url="http://www.mpi-sws.org/%7Erossberg/sml-vs-ocaml.html">side-by-side
21387 comparison</ulink> of the syntax of SML and OCaml.
21388 </simpara>
21389 </listitem>
21390 <listitem>
21391 <simpara>
21392 Adam Chlipala has a
21393 <ulink url="http://adam.chlipala.net/mlcomp">point-by-point comparison</ulink> of OCaml
21394 and SML.
21395 </simpara>
21396 </listitem>
21397 </itemizedlist>
21398 </section>
21399 <section id="_ocaml_and_mlton">
21400 <title>OCaml and MLton</title>
21401 <simpara>Here&#8217;s a comparison of some aspects of OCaml and MLton.</simpara>
21402 <itemizedlist>
21403 <listitem>
21404 <simpara>
21405 Performance
21406 </simpara>
21407 <itemizedlist>
21408 <listitem>
21409 <simpara>
21410 Both OCaml and MLton have excellent performance.
21411 </simpara>
21412 </listitem>
21413 <listitem>
21414 <simpara>
21415 MLton performs extensive <link linkend="WholeProgramOptimization">WholeProgramOptimization</link>, which can
21416 provide substantial improvements in large, modular programs.
21417 </simpara>
21418 </listitem>
21419 <listitem>
21420 <simpara>
21421 MLton uses native types, like 32-bit integers, without any penalty
21422 due to tagging or boxing. OCaml uses 31-bit integers with a penalty
21423 due to tagging, and 32-bit integers with a penalty due to boxing.
21424 </simpara>
21425 </listitem>
21426 <listitem>
21427 <simpara>
21428 MLton uses native types, like 64-bit floats, without any penalty
21429 due to boxing. OCaml, in some situations, boxes 64-bit floats.
21430 </simpara>
21431 </listitem>
21432 <listitem>
21433 <simpara>
21434 MLton represents arrays of all types unboxed. In OCaml, only
21435 arrays of 64-bit floats are unboxed, and then only when it is
21436 syntactically apparent.
21437 </simpara>
21438 </listitem>
21439 <listitem>
21440 <simpara>
21441 MLton represents records compactly by reordering and packing the
21442 fields.
21443 </simpara>
21444 </listitem>
21445 <listitem>
21446 <simpara>
21447 In MLton, polymorphic and monomorphic code have the same
21448 performance. In OCaml, polymorphism can introduce a performance
21449 penalty.
21450 </simpara>
21451 </listitem>
21452 <listitem>
21453 <simpara>
21454 In MLton, module boundaries have no impact on performance. In
21455 OCaml, moving code between modules can cause a performance penalty.
21456 </simpara>
21457 </listitem>
21458 <listitem>
21459 <simpara>
21460 MLton&#8217;s <link linkend="ForeignFunctionInterface">ForeignFunctionInterface</link> is simpler than OCaml&#8217;s.
21461 </simpara>
21462 </listitem>
21463 </itemizedlist>
21464 </listitem>
21465 <listitem>
21466 <simpara>
21467 Tools
21468 </simpara>
21469 <itemizedlist>
21470 <listitem>
21471 <simpara>
21472 OCaml has a debugger, while MLton does not.
21473 </simpara>
21474 </listitem>
21475 <listitem>
21476 <simpara>
21477 OCaml supports separate compilation, while MLton does not.
21478 </simpara>
21479 </listitem>
21480 <listitem>
21481 <simpara>
21482 OCaml compiles faster than MLton.
21483 </simpara>
21484 </listitem>
21485 <listitem>
21486 <simpara>
21487 MLton supports profiling of both time and allocation.
21488 </simpara>
21489 </listitem>
21490 </itemizedlist>
21491 </listitem>
21492 <listitem>
21493 <simpara>
21494 Libraries
21495 </simpara>
21496 <itemizedlist>
21497 <listitem>
21498 <simpara>
21499 OCaml has more available libraries.
21500 </simpara>
21501 </listitem>
21502 </itemizedlist>
21503 </listitem>
21504 <listitem>
21505 <simpara>
21506 Community
21507 </simpara>
21508 <itemizedlist>
21509 <listitem>
21510 <simpara>
21511 OCaml has a larger community than MLton.
21512 </simpara>
21513 </listitem>
21514 <listitem>
21515 <simpara>
21516 MLton has a very responsive
21517 <ulink url="http://www.mlton.org/mailman/listinfo/mlton">developer list</ulink>.
21518 </simpara>
21519 </listitem>
21520 </itemizedlist>
21521 </listitem>
21522 </itemizedlist>
21523 <simpara><?asciidoc-pagebreak?></simpara>
21524 </section>
21525 </section>
21526 <section id="OpenGL">
21527 <title>OpenGL</title>
21528 <simpara>There are at least two interfaces to OpenGL for MLton/SML, both of
21529 which should be considered alpha quality.</simpara>
21530 <itemizedlist>
21531 <listitem>
21532 <simpara>
21533 <link linkend="MikeThomas">MikeThomas</link> built a low-level interface, directly translating
21534 many of the functions, covering GL, GLU, and GLUT. This is available
21535 in the MLton <link linkend="Sources">Sources</link>:
21536 <ulink url="https://github.com/MLton/mltonlib/tree/master/org/mlton/mike/opengl"><literal>opengl</literal></ulink>. The code
21537 contains a number of small, standard OpenGL examples translated to
21538 SML.
21539 </simpara>
21540 </listitem>
21541 <listitem>
21542 <simpara>
21543 <link linkend="ChrisClearwater">ChrisClearwater</link> has written at least an interface to GL, and
21544 possibly more. See
21545 </simpara>
21546 <itemizedlist>
21547 <listitem>
21548 <simpara>
21549 <ulink url="http://mlton.org/pipermail/mlton/2005-January/026669.html">http://mlton.org/pipermail/mlton/2005-January/026669.html</ulink>
21550 </simpara>
21551 </listitem>
21552 </itemizedlist>
21553 </listitem>
21554 </itemizedlist>
21555 <simpara><link linkend="Contact">Contact</link> us for more information or an update on the status of
21556 these projects.</simpara>
21557 <simpara><?asciidoc-pagebreak?></simpara>
21558 </section>
21559 <section id="OperatorPrecedence">
21560 <title>OperatorPrecedence</title>
21561 <simpara><link linkend="StandardML">Standard ML</link> has a built in notion of precedence for
21562 certain symbols. Every program that includes the
21563 <link linkend="BasisLibrary">Basis Library</link> automatically gets the following infix
21564 declarations. Higher number indicates higher precedence.</simpara>
21565 <programlisting language="sml" linenumbering="unnumbered">infix 7 * / mod div
21566 infix 6 + - ^
21567 infixr 5 :: @
21568 infix 4 = &lt;&gt; &gt; &gt;= &lt; &lt;=
21569 infix 3 := o
21570 infix 0 before</programlisting>
21571 <simpara><?asciidoc-pagebreak?></simpara>
21572 </section>
21573 <section id="OptionalArguments">
21574 <title>OptionalArguments</title>
21575 <simpara><link linkend="StandardML">Standard ML</link> does not have built-in support for optional
21576 arguments. Nevertheless, using <link linkend="Fold">Fold</link>, it is easy to define
21577 functions that take optional arguments.</simpara>
21578 <simpara>For example, suppose that we have the following definition of a
21579 function <literal>f</literal>.</simpara>
21580 <programlisting language="sml" linenumbering="unnumbered">fun f (i, r, s) =
21581 concat [Int.toString i, ", ", Real.toString r, ", ", s]</programlisting>
21582 <simpara>Using the <literal>OptionalArg</literal> structure described below, we can define a
21583 function <literal>f'</literal>, an optionalized version of <literal>f</literal>, that takes 0, 1, 2, or
21584 3 arguments. Embedded within <literal>f'</literal> will be default values for <literal>i</literal>,
21585 <literal>r</literal>, and <literal>s</literal>. If <literal>f'</literal> gets no arguments, then all the defaults are
21586 used. If <literal>f'</literal> gets one argument, then that will be used for <literal>i</literal>. Two
21587 arguments will be used for <literal>i</literal> and <literal>r</literal> respectively. Three arguments
21588 will override all default values. Calls to <literal>f'</literal> will look like the
21589 following.</simpara>
21590 <programlisting language="sml" linenumbering="unnumbered">f' $
21591 f' `2 $
21592 f' `2 `3.0 $
21593 f' `2 `3.0 `"four" $</programlisting>
21594 <simpara>The optional argument indicator, <literal>&grave;</literal>, is not special syntax ---
21595 it is a normal SML value, defined in the <literal>OptionalArg</literal> structure
21596 below.</simpara>
21597 <simpara>Here is the definition of <literal>f'</literal> using the <literal>OptionalArg</literal> structure, in
21598 particular, <literal>OptionalArg.make</literal> and <literal>OptionalArg.D</literal>.</simpara>
21599 <programlisting language="sml" linenumbering="unnumbered">val f' =
21600 fn z =&gt;
21601 let open OptionalArg in
21602 make (D 1) (D 2.0) (D "three") $
21603 end (fn i &amp; r &amp; s =&gt; f (i, r, s))
21604 z</programlisting>
21605 <simpara>The definition of <literal>f'</literal> is eta expanded as with all uses of fold. A
21606 call to <literal>OptionalArg.make</literal> is supplied with a variable number of
21607 defaults (in this case, three), the end-of-arguments terminator, <literal>$</literal>,
21608 and the function to run, taking its arguments as an n-ary
21609 <link linkend="ProductType">product</link>. In this case, the function simply converts
21610 the product to an ordinary tuple and calls <literal>f</literal>. Often, the function
21611 body will simply be written directly.</simpara>
21612 <simpara>In general, the definition of an optional-argument function looks like
21613 the following.</simpara>
21614 <programlisting language="sml" linenumbering="unnumbered">val f =
21615 fn z =&gt;
21616 let open OptionalArg in
21617 make (D &lt;default1&gt;) (D &lt;default2&gt;) ... (D &lt;defaultn&gt;) $
21618 end (fn x1 &amp; x2 &amp; ... &amp; xn =&gt;
21619 &lt;function code goes here&gt;)
21620 z</programlisting>
21621 <simpara>Here is the definition of <literal>OptionalArg</literal>.</simpara>
21622 <programlisting language="sml" linenumbering="unnumbered">structure OptionalArg =
21623 struct
21624 val make =
21625 fn z =&gt;
21626 Fold.fold
21627 ((id, fn (f, x) =&gt; f x),
21628 fn (d, r) =&gt; fn func =&gt;
21629 Fold.fold ((id, d ()), fn (f, d) =&gt;
21630 let
21631 val d &amp; () = r (id, f d)
21632 in
21633 func d
21634 end))
21635 z
21636
21637 fun D d = Fold.step0 (fn (f, r) =&gt;
21638 (fn ds =&gt; f (d &amp; ds),
21639 fn (f, a &amp; b) =&gt; r (fn x =&gt; f a &amp; x, b)))
21640
21641 val ` =
21642 fn z =&gt;
21643 Fold.step1 (fn (x, (f, _ &amp; d)) =&gt; (fn d =&gt; f (x &amp; d), d))
21644 z
21645 end</programlisting>
21646 <simpara><literal>OptionalArg.make</literal> uses a nested fold. The first <literal>fold</literal> accumulates
21647 the default values in a product, associated to the right, and a
21648 reversal function that converts a product (of the same arity as the
21649 number of defaults) from right associativity to left associativity.
21650 The accumulated defaults are used by the second fold, which recurs
21651 over the product, replacing the appropriate component as it encounters
21652 optional arguments. The second fold also constructs a "fill"
21653 function, <literal>f</literal>, that is used to reconstruct the product once the
21654 end-of-arguments is reached. Finally, the finisher reconstructs the
21655 product and uses the reversal function to convert the product from
21656 right associative to left associative, at which point it is passed to
21657 the user-supplied function.</simpara>
21658 <simpara>Much of the complexity comes from the fact that while recurring over a
21659 product from left to right, one wants it to be right-associative,
21660 e.g., look like</simpara>
21661 <programlisting language="sml" linenumbering="unnumbered">a &amp; (b &amp; (c &amp; d))</programlisting>
21662 <simpara>but the user function in the end wants the product to be left
21663 associative, so that the product argument pattern can be written
21664 without parentheses (since <literal>&amp;</literal> is left associative).</simpara>
21665 <section id="_labelled_optional_arguments">
21666 <title>Labelled optional arguments</title>
21667 <simpara>In addition to the positional optional arguments described above, it
21668 is sometimes useful to have labelled optional arguments. These allow
21669 one to define a function, <literal>f</literal>, with defaults, say <literal>a</literal> and <literal>b</literal>. Then,
21670 a caller of <literal>f</literal> can supply values for <literal>a</literal> and <literal>b</literal> by name. If no
21671 value is supplied then the default is used.</simpara>
21672 <simpara>Labelled optional arguments are a simple extension of
21673 <link linkend="FunctionalRecordUpdate">FunctionalRecordUpdate</link> using post composition. Suppose, for
21674 example, that one wants a function <literal>f</literal> with labelled optional
21675 arguments <literal>a</literal> and <literal>b</literal> with default values <literal>0</literal> and <literal>0.0</literal> respectively.
21676 If one has a functional-record-update function <literal>updateAB</literal> for records
21677 with <literal>a</literal> and <literal>b</literal> fields, then one can define <literal>f</literal> in the following way.</simpara>
21678 <programlisting language="sml" linenumbering="unnumbered">val f =
21679 fn z =&gt;
21680 Fold.post
21681 (updateAB {a = 0, b = 0.0},
21682 fn {a, b} =&gt; print (concat [Int.toString a, " ",
21683 Real.toString b, "\n"]))
21684 z</programlisting>
21685 <simpara>The idea is that <literal>f</literal> is the post composition (using <literal>Fold.post</literal>) of
21686 the actual code for the function with a functional-record updater that
21687 starts with the defaults.</simpara>
21688 <simpara>Here are some example calls to <literal>f</literal>.</simpara>
21689 <programlisting language="sml" linenumbering="unnumbered">val () = f $
21690 val () = f (U#a 13) $
21691 val () = f (U#a 13) (U#b 17.5) $
21692 val () = f (U#b 17.5) (U#a 13) $</programlisting>
21693 <simpara>Notice that a caller can supply neither of the arguments, either of
21694 the arguments, or both of the arguments, and in either order. All
21695 that matter is that the arguments be labelled correctly (and of the
21696 right type, of course).</simpara>
21697 <simpara>Here is another example.</simpara>
21698 <programlisting language="sml" linenumbering="unnumbered">val f =
21699 fn z =&gt;
21700 Fold.post
21701 (updateBCD {b = 0, c = 0.0, d = "&lt;&gt;"},
21702 fn {b, c, d} =&gt;
21703 print (concat [Int.toString b, " ",
21704 Real.toString c, " ",
21705 d, "\n"]))
21706 z</programlisting>
21707 <simpara>Here are some example calls.</simpara>
21708 <programlisting language="sml" linenumbering="unnumbered">val () = f $
21709 val () = f (U#d "goodbye") $
21710 val () = f (U#d "hello") (U#b 17) (U#c 19.3) $</programlisting>
21711 <simpara><?asciidoc-pagebreak?></simpara>
21712 </section>
21713 </section>
21714 <section id="Overloading">
21715 <title>Overloading</title>
21716 <simpara>In <link linkend="StandardML">Standard ML</link>, constants (like <literal>13</literal>, <literal>0w13</literal>, <literal>13.0</literal>)
21717 are overloaded, meaning that they can denote a constant of the
21718 appropriate type as determined by context. SML defines the
21719 overloading classes <emphasis>Int</emphasis>, <emphasis>Real</emphasis>, and <emphasis>Word</emphasis>, which denote the sets
21720 of types that integer, real, and word constants may take on. In
21721 MLton, these are defined as follows.</simpara>
21722 <informaltable
21723 frame="all"
21724 rowsep="1" colsep="1"
21725 >
21726 <tgroup cols="2">
21727 <colspec colname="col_1" colwidth="25*"/>
21728 <colspec colname="col_2" colwidth="75*"/>
21729 <tbody>
21730 <row>
21731 <entry align="center" valign="top"><simpara><emphasis>Int</emphasis></simpara></entry>
21732 <entry align="left" valign="top"><simpara><literal>Int2.int</literal>, <literal>Int3.int</literal>, &#8230; <literal>Int32.int</literal>, <literal>Int64.int</literal>, <literal>Int.int</literal>, <literal>IntInf.int</literal>, <literal>LargeInt.int</literal>, <literal>FixedInt.int</literal>, <literal>Position.int</literal></simpara></entry>
21733 </row>
21734 <row>
21735 <entry align="center" valign="top"><simpara><emphasis>Real</emphasis></simpara></entry>
21736 <entry align="left" valign="top"><simpara><literal>Real32.real</literal>, <literal>Real64.real</literal>, <literal>Real.real</literal>, <literal>LargeReal.real</literal></simpara></entry>
21737 </row>
21738 <row>
21739 <entry align="center" valign="top"><simpara><emphasis>Word</emphasis></simpara></entry>
21740 <entry align="left" valign="top"><simpara><literal>Word2.word</literal>, <literal>Word3.word</literal>, &#8230; <literal>Word32.word</literal>, <literal>Word64.word</literal>, <literal>Word.word</literal>, <literal>LargeWord.word</literal>, <literal>SysWord.word</literal></simpara></entry>
21741 </row>
21742 </tbody>
21743 </tgroup>
21744 </informaltable>
21745 <simpara>The <link linkend="DefinitionOfStandardML">Definition</link> allows flexibility in how
21746 much context is used to resolve overloading. It says that the context
21747 is <emphasis>no larger than the smallest enclosing structure-level
21748 declaration</emphasis>, but that <emphasis>an implementation may require that a smaller
21749 context determines the type</emphasis>. MLton uses the largest possible context
21750 allowed by SML in resolving overloading. If the type of a constant is
21751 not determined by context, then it takes on a default type. In MLton,
21752 these are defined as follows.</simpara>
21753 <informaltable
21754 frame="all"
21755 rowsep="1" colsep="1"
21756 >
21757 <tgroup cols="2">
21758 <colspec colname="col_1" colwidth="25*"/>
21759 <colspec colname="col_2" colwidth="75*"/>
21760 <tbody>
21761 <row>
21762 <entry align="center" valign="top"><simpara><emphasis>Int</emphasis></simpara></entry>
21763 <entry align="left" valign="top"><simpara><literal>Int.int</literal></simpara></entry>
21764 </row>
21765 <row>
21766 <entry align="center" valign="top"><simpara><emphasis>Real</emphasis></simpara></entry>
21767 <entry align="left" valign="top"><simpara><literal>Real.real</literal></simpara></entry>
21768 </row>
21769 <row>
21770 <entry align="center" valign="top"><simpara><emphasis>Word</emphasis></simpara></entry>
21771 <entry align="left" valign="top"><simpara><literal>Word.word</literal></simpara></entry>
21772 </row>
21773 </tbody>
21774 </tgroup>
21775 </informaltable>
21776 <simpara>Other implementations may use a smaller context or different default
21777 types.</simpara>
21778 <section id="_also_see_19">
21779 <title>Also see</title>
21780 <itemizedlist>
21781 <listitem>
21782 <simpara>
21783 <ulink url="http://www.standardml.org/Basis/top-level-chapter.html">discussion of overloading in the Basis Library</ulink>
21784 </simpara>
21785 </listitem>
21786 </itemizedlist>
21787 </section>
21788 <section id="_examples_3">
21789 <title>Examples</title>
21790 <itemizedlist>
21791 <listitem>
21792 <simpara>
21793 The following program is rejected.
21794 </simpara>
21795 <programlisting language="sml" linenumbering="unnumbered">structure S:
21796 sig
21797 val x: Word8.word
21798 end =
21799 struct
21800 val x = 0w0
21801 end</programlisting>
21802 <simpara>The smallest enclosing structure declaration for <literal>0w0</literal> is
21803 <literal>val x = 0w0</literal>. Hence, <literal>0w0</literal> receives the default type for words,
21804 which is <literal>Word.word</literal>.</simpara>
21805 </listitem>
21806 </itemizedlist>
21807 <simpara><?asciidoc-pagebreak?></simpara>
21808 </section>
21809 </section>
21810 <section id="PackedRepresentation">
21811 <title>PackedRepresentation</title>
21812 <simpara><link linkend="PackedRepresentation">PackedRepresentation</link> is an analysis pass for the <link linkend="SSA2">SSA2</link>
21813 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="ToRSSA">ToRSSA</link>.</simpara>
21814 <section id="_description_40">
21815 <title>Description</title>
21816 <simpara>This pass analyzes a <link linkend="SSA2">SSA2</link> program to compute a packed
21817 representation for each object.</simpara>
21818 </section>
21819 <section id="_implementation_43">
21820 <title>Implementation</title>
21821 <itemizedlist>
21822 <listitem>
21823 <simpara>
21824 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/representation.sig"><literal>representation.sig</literal></ulink>
21825 </simpara>
21826 </listitem>
21827 <listitem>
21828 <simpara>
21829 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/packed-representation.fun"><literal>packed-representation.fun</literal></ulink>
21830 </simpara>
21831 </listitem>
21832 </itemizedlist>
21833 </section>
21834 <section id="_details_and_notes_43">
21835 <title>Details and Notes</title>
21836 <simpara>Has a special case to make sure that <literal>true</literal> is represented as <literal>1</literal> and
21837 <literal>false</literal> is represented as <literal>0</literal>.</simpara>
21838 <simpara><?asciidoc-pagebreak?></simpara>
21839 </section>
21840 </section>
21841 <section id="ParallelMove">
21842 <title>ParallelMove</title>
21843 <simpara><link linkend="ParallelMove">ParallelMove</link> is a rewrite pass, agnostic in the
21844 <link linkend="IntermediateLanguage">IntermediateLanguage</link> which it produces.</simpara>
21845 <section id="_description_41">
21846 <title>Description</title>
21847 <simpara>This function computes a sequence of individual moves to effect a
21848 parallel move (with possibly overlapping froms and tos).</simpara>
21849 </section>
21850 <section id="_implementation_44">
21851 <title>Implementation</title>
21852 <itemizedlist>
21853 <listitem>
21854 <simpara>
21855 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/parallel-move.sig"><literal>parallel-move.sig</literal></ulink>
21856 </simpara>
21857 </listitem>
21858 <listitem>
21859 <simpara>
21860 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/parallel-move.fun"><literal>parallel-move.fun</literal></ulink>
21861 </simpara>
21862 </listitem>
21863 </itemizedlist>
21864 </section>
21865 <section id="_details_and_notes_44">
21866 <title>Details and Notes</title>
21867 <simpara></simpara>
21868 <simpara><?asciidoc-pagebreak?></simpara>
21869 </section>
21870 </section>
21871 <section id="Performance">
21872 <title>Performance</title>
21873 <simpara>This page compares the performance of a number of SML compilers on a
21874 range of benchmarks.</simpara>
21875 <simpara>This page compares the following SML compiler versions.</simpara>
21876 <itemizedlist>
21877 <listitem>
21878 <simpara>
21879 <link linkend="Home">MLton</link> 20171211 (git 79d4a623c)
21880 </simpara>
21881 </listitem>
21882 <listitem>
21883 <simpara>
21884 <link linkend="MLKit">ML Kit</link> 4.3.12 (20171210)
21885 </simpara>
21886 </listitem>
21887 <listitem>
21888 <simpara>
21889 <link linkend="MoscowML">Moscow ML</link> 2.10.1 ++ (git f529b33bb, 20170711)
21890 </simpara>
21891 </listitem>
21892 <listitem>
21893 <simpara>
21894 <link linkend="PolyML">Poly/ML</link> 5.7.2 Testing (git 5.7.1-35-gcb73407a)
21895 </simpara>
21896 </listitem>
21897 <listitem>
21898 <simpara>
21899 <link linkend="SMLNJ">SML/NJ</link> 110.81 (20170501)
21900 </simpara>
21901 </listitem>
21902 </itemizedlist>
21903 <simpara>There are tables for <link linkend="Performance_RunTime">run time</link>, <link linkend="Performance_CodeSize">code size</link>, and
21904 <link linkend="Performance_CompileTime">compile time</link>.</simpara>
21905 <section id="_setup_3">
21906 <title>Setup</title>
21907 <simpara>All benchmarks were compiled and run on a 2.6 GHz Core i7-5600U with 16G of
21908 RAM. The benchmarks were compiled with the default settings for all
21909 the compilers, except for Moscow ML, which was passed the
21910 <literal>-orthodox -standalone -toplevel</literal> switches. The Poly/ML executables
21911 were produced using <literal>polyc</literal>.
21912 The SML/NJ executables were produced by wrapping the entire program in
21913 a <literal>local</literal> declaration whose body performs an <literal>SMLofNJ.exportFn</literal>.</simpara>
21914 <simpara>For more details, or if you want to run the benchmarks yourself,
21915 please see the <ulink url="https://github.com/MLton/mlton/tree/master/benchmark"><literal>benchmark</literal></ulink> directory of our
21916 <link linkend="Sources">Sources</link>.</simpara>
21917 <simpara>All of the benchmarks are available for download from this page. Some
21918 of the benchmarks were obtained from the SML/NJ benchmark suite. Some
21919 of the benchmarks expect certain input files to exist in the
21920 <ulink url="https://github.com/MLton/mlton/tree/master/benchmark/tests/DATA"><literal>DATA</literal></ulink> subdirectory.</simpara>
21921 <itemizedlist>
21922 <listitem>
21923 <simpara>
21924 <ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/hamlet.sml"><literal>hamlet.sml</literal></ulink> <ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/DATA/hamlet-input.sml"><literal>hamlet-input.sml</literal></ulink>
21925 </simpara>
21926 </listitem>
21927 <listitem>
21928 <simpara>
21929 <ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/ray.sml"><literal>ray.sml</literal></ulink> <ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/DATA/ray"><literal>ray</literal></ulink>
21930 </simpara>
21931 </listitem>
21932 <listitem>
21933 <simpara>
21934 <ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/raytrace.sml"><literal>raytrace.sml</literal></ulink> <ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/DATA/chess.gml"><literal>chess.gml</literal></ulink>
21935 </simpara>
21936 </listitem>
21937 <listitem>
21938 <simpara>
21939 <ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vliw.sml"><literal>vliw.sml</literal></ulink> <ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/DATA/ndotprod.s"><literal>ndotprod.s</literal></ulink>
21940 </simpara>
21941 </listitem>
21942 </itemizedlist>
21943 </section>
21944 <section id="_anchor_id_performance_runtime_xreflabel_performance_runtime_run_time_ratio">
21945 <title><anchor id="Performance_RunTime" xreflabel="[Performance_RunTime]"/>Run-time ratio</title>
21946 <simpara>The following table gives the ratio of the run time of each benchmark
21947 when compiled by another compiler to the run time when compiled by
21948 MLton. That is, the larger the number, the slower the generated code
21949 runs. A number larger than one indicates that the corresponding
21950 compiler produces code that runs more slowly than MLton. A * in an
21951 entry means the compiler failed to compile the benchmark or that the
21952 benchmark failed to run.</simpara>
21953 <informaltable
21954 frame="all"
21955 rowsep="1" colsep="1"
21956 >
21957 <tgroup cols="6">
21958 <colspec colname="col_1" colwidth="28*"/>
21959 <colspec colname="col_2" colwidth="14*"/>
21960 <colspec colname="col_3" colwidth="14*"/>
21961 <colspec colname="col_4" colwidth="14*"/>
21962 <colspec colname="col_5" colwidth="14*"/>
21963 <colspec colname="col_6" colwidth="14*"/>
21964 <thead>
21965 <row>
21966 <entry align="left" valign="top">benchmark</entry>
21967 <entry align="left" valign="top">MLton</entry>
21968 <entry align="left" valign="top">ML-Kit</entry>
21969 <entry align="left" valign="top">MosML</entry>
21970 <entry align="left" valign="top">Poly/ML</entry>
21971 <entry align="left" valign="top">SML/NJ</entry>
21972 </row>
21973 </thead>
21974 <tbody>
21975 <row>
21976 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/barnes-hut.sml"><literal>barnes-hut.sml</literal></ulink></simpara></entry>
21977 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
21978 <entry align="left" valign="top"><simpara>10.11</simpara></entry>
21979 <entry align="left" valign="top"><simpara>19.36</simpara></entry>
21980 <entry align="left" valign="top"><simpara>2.98</simpara></entry>
21981 <entry align="left" valign="top"><simpara>1.24</simpara></entry>
21982 </row>
21983 <row>
21984 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/boyer.sml"><literal>boyer.sml</literal></ulink></simpara></entry>
21985 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
21986 <entry align="left" valign="top"><simpara>*</simpara></entry>
21987 <entry align="left" valign="top"><simpara>7.87</simpara></entry>
21988 <entry align="left" valign="top"><simpara>1.22</simpara></entry>
21989 <entry align="left" valign="top"><simpara>1.75</simpara></entry>
21990 </row>
21991 <row>
21992 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/checksum.sml"><literal>checksum.sml</literal></ulink></simpara></entry>
21993 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
21994 <entry align="left" valign="top"><simpara>30.79</simpara></entry>
21995 <entry align="left" valign="top"><simpara>*</simpara></entry>
21996 <entry align="left" valign="top"><simpara>10.94</simpara></entry>
21997 <entry align="left" valign="top"><simpara>9.08</simpara></entry>
21998 </row>
21999 <row>
22000 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/count-graphs.sml"><literal>count-graphs.sml</literal></ulink></simpara></entry>
22001 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22002 <entry align="left" valign="top"><simpara>6.51</simpara></entry>
22003 <entry align="left" valign="top"><simpara>40.42</simpara></entry>
22004 <entry align="left" valign="top"><simpara>2.34</simpara></entry>
22005 <entry align="left" valign="top"><simpara>2.32</simpara></entry>
22006 </row>
22007 <row>
22008 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/DLXSimulator.sml"><literal>DLXSimulator.sml</literal></ulink></simpara></entry>
22009 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22010 <entry align="left" valign="top"><simpara>0.97</simpara></entry>
22011 <entry align="left" valign="top"><simpara>*</simpara></entry>
22012 <entry align="left" valign="top"><simpara>0.60</simpara></entry>
22013 <entry align="left" valign="top"><simpara>*</simpara></entry>
22014 </row>
22015 <row>
22016 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/even-odd.sml"><literal>even-odd.sml</literal></ulink></simpara></entry>
22017 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22018 <entry align="left" valign="top"><simpara>0.50</simpara></entry>
22019 <entry align="left" valign="top"><simpara>11.50</simpara></entry>
22020 <entry align="left" valign="top"><simpara>0.42</simpara></entry>
22021 <entry align="left" valign="top"><simpara>0.42</simpara></entry>
22022 </row>
22023 <row>
22024 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/fft.sml"><literal>fft.sml</literal></ulink></simpara></entry>
22025 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22026 <entry align="left" valign="top"><simpara>7.35</simpara></entry>
22027 <entry align="left" valign="top"><simpara>81.51</simpara></entry>
22028 <entry align="left" valign="top"><simpara>4.03</simpara></entry>
22029 <entry align="left" valign="top"><simpara>1.19</simpara></entry>
22030 </row>
22031 <row>
22032 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/fib.sml"><literal>fib.sml</literal></ulink></simpara></entry>
22033 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22034 <entry align="left" valign="top"><simpara>1.41</simpara></entry>
22035 <entry align="left" valign="top"><simpara>10.94</simpara></entry>
22036 <entry align="left" valign="top"><simpara>1.25</simpara></entry>
22037 <entry align="left" valign="top"><simpara>1.17</simpara></entry>
22038 </row>
22039 <row>
22040 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/flat-array.sml"><literal>flat-array.sml</literal></ulink></simpara></entry>
22041 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22042 <entry align="left" valign="top"><simpara>7.19</simpara></entry>
22043 <entry align="left" valign="top"><simpara>68.33</simpara></entry>
22044 <entry align="left" valign="top"><simpara>5.28</simpara></entry>
22045 <entry align="left" valign="top"><simpara>13.16</simpara></entry>
22046 </row>
22047 <row>
22048 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/hamlet.sml"><literal>hamlet.sml</literal></ulink></simpara></entry>
22049 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22050 <entry align="left" valign="top"><simpara>4.97</simpara></entry>
22051 <entry align="left" valign="top"><simpara>22.85</simpara></entry>
22052 <entry align="left" valign="top"><simpara>1.58</simpara></entry>
22053 <entry align="left" valign="top"><simpara>*</simpara></entry>
22054 </row>
22055 <row>
22056 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/imp-for.sml"><literal>imp-for.sml</literal></ulink></simpara></entry>
22057 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22058 <entry align="left" valign="top"><simpara>4.99</simpara></entry>
22059 <entry align="left" valign="top"><simpara>57.84</simpara></entry>
22060 <entry align="left" valign="top"><simpara>3.34</simpara></entry>
22061 <entry align="left" valign="top"><simpara>4.67</simpara></entry>
22062 </row>
22063 <row>
22064 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/knuth-bendix.sml"><literal>knuth-bendix.sml</literal></ulink></simpara></entry>
22065 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22066 <entry align="left" valign="top"><simpara>*</simpara></entry>
22067 <entry align="left" valign="top"><simpara>18.43</simpara></entry>
22068 <entry align="left" valign="top"><simpara>3.18</simpara></entry>
22069 <entry align="left" valign="top"><simpara>3.06</simpara></entry>
22070 </row>
22071 <row>
22072 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/lexgen.sml"><literal>lexgen.sml</literal></ulink></simpara></entry>
22073 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22074 <entry align="left" valign="top"><simpara>2.76</simpara></entry>
22075 <entry align="left" valign="top"><simpara>7.94</simpara></entry>
22076 <entry align="left" valign="top"><simpara>3.19</simpara></entry>
22077 <entry align="left" valign="top"><simpara>*</simpara></entry>
22078 </row>
22079 <row>
22080 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/life.sml"><literal>life.sml</literal></ulink></simpara></entry>
22081 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22082 <entry align="left" valign="top"><simpara>1.80</simpara></entry>
22083 <entry align="left" valign="top"><simpara>20.19</simpara></entry>
22084 <entry align="left" valign="top"><simpara>0.89</simpara></entry>
22085 <entry align="left" valign="top"><simpara>1.50</simpara></entry>
22086 </row>
22087 <row>
22088 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/logic.sml"><literal>logic.sml</literal></ulink></simpara></entry>
22089 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22090 <entry align="left" valign="top"><simpara>5.10</simpara></entry>
22091 <entry align="left" valign="top"><simpara>11.06</simpara></entry>
22092 <entry align="left" valign="top"><simpara>1.15</simpara></entry>
22093 <entry align="left" valign="top"><simpara>1.27</simpara></entry>
22094 </row>
22095 <row>
22096 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/mandelbrot.sml"><literal>mandelbrot.sml</literal></ulink></simpara></entry>
22097 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22098 <entry align="left" valign="top"><simpara>3.50</simpara></entry>
22099 <entry align="left" valign="top"><simpara>25.52</simpara></entry>
22100 <entry align="left" valign="top"><simpara>1.33</simpara></entry>
22101 <entry align="left" valign="top"><simpara>1.28</simpara></entry>
22102 </row>
22103 <row>
22104 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/matrix-multiply.sml"><literal>matrix-multiply.sml</literal></ulink></simpara></entry>
22105 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22106 <entry align="left" valign="top"><simpara>29.40</simpara></entry>
22107 <entry align="left" valign="top"><simpara>183.02</simpara></entry>
22108 <entry align="left" valign="top"><simpara>7.41</simpara></entry>
22109 <entry align="left" valign="top"><simpara>15.19</simpara></entry>
22110 </row>
22111 <row>
22112 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/md5.sml"><literal>md5.sml</literal></ulink></simpara></entry>
22113 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22114 <entry align="left" valign="top"><simpara>95.18</simpara></entry>
22115 <entry align="left" valign="top"><simpara>*</simpara></entry>
22116 <entry align="left" valign="top"><simpara>32.61</simpara></entry>
22117 <entry align="left" valign="top"><simpara>47.47</simpara></entry>
22118 </row>
22119 <row>
22120 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/merge.sml"><literal>merge.sml</literal></ulink></simpara></entry>
22121 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22122 <entry align="left" valign="top"><simpara>1.42</simpara></entry>
22123 <entry align="left" valign="top"><simpara>*</simpara></entry>
22124 <entry align="left" valign="top"><simpara>0.74</simpara></entry>
22125 <entry align="left" valign="top"><simpara>3.24</simpara></entry>
22126 </row>
22127 <row>
22128 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/mlyacc.sml"><literal>mlyacc.sml</literal></ulink></simpara></entry>
22129 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22130 <entry align="left" valign="top"><simpara>1.83</simpara></entry>
22131 <entry align="left" valign="top"><simpara>8.45</simpara></entry>
22132 <entry align="left" valign="top"><simpara>0.84</simpara></entry>
22133 <entry align="left" valign="top"><simpara>*</simpara></entry>
22134 </row>
22135 <row>
22136 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/model-elimination.sml"><literal>model-elimination.sml</literal></ulink></simpara></entry>
22137 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22138 <entry align="left" valign="top"><simpara>4.03</simpara></entry>
22139 <entry align="left" valign="top"><simpara>12.42</simpara></entry>
22140 <entry align="left" valign="top"><simpara>1.70</simpara></entry>
22141 <entry align="left" valign="top"><simpara>2.25</simpara></entry>
22142 </row>
22143 <row>
22144 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/mpuz.sml"><literal>mpuz.sml</literal></ulink></simpara></entry>
22145 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22146 <entry align="left" valign="top"><simpara>3.73</simpara></entry>
22147 <entry align="left" valign="top"><simpara>57.44</simpara></entry>
22148 <entry align="left" valign="top"><simpara>2.05</simpara></entry>
22149 <entry align="left" valign="top"><simpara>3.22</simpara></entry>
22150 </row>
22151 <row>
22152 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/nucleic.sml"><literal>nucleic.sml</literal></ulink></simpara></entry>
22153 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22154 <entry align="left" valign="top"><simpara>3.96</simpara></entry>
22155 <entry align="left" valign="top"><simpara>*</simpara></entry>
22156 <entry align="left" valign="top"><simpara>1.73</simpara></entry>
22157 <entry align="left" valign="top"><simpara>1.20</simpara></entry>
22158 </row>
22159 <row>
22160 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/output1.sml"><literal>output1.sml</literal></ulink></simpara></entry>
22161 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22162 <entry align="left" valign="top"><simpara>6.26</simpara></entry>
22163 <entry align="left" valign="top"><simpara>30.85</simpara></entry>
22164 <entry align="left" valign="top"><simpara>7.82</simpara></entry>
22165 <entry align="left" valign="top"><simpara>5.99</simpara></entry>
22166 </row>
22167 <row>
22168 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/peek.sml"><literal>peek.sml</literal></ulink></simpara></entry>
22169 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22170 <entry align="left" valign="top"><simpara>9.37</simpara></entry>
22171 <entry align="left" valign="top"><simpara>44.78</simpara></entry>
22172 <entry align="left" valign="top"><simpara>2.18</simpara></entry>
22173 <entry align="left" valign="top"><simpara>2.15</simpara></entry>
22174 </row>
22175 <row>
22176 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/psdes-random.sml"><literal>psdes-random.sml</literal></ulink></simpara></entry>
22177 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22178 <entry align="left" valign="top"><simpara>*</simpara></entry>
22179 <entry align="left" valign="top"><simpara>*</simpara></entry>
22180 <entry align="left" valign="top"><simpara>2.79</simpara></entry>
22181 <entry align="left" valign="top"><simpara>3.59</simpara></entry>
22182 </row>
22183 <row>
22184 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/ratio-regions.sml"><literal>ratio-regions.sml</literal></ulink></simpara></entry>
22185 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22186 <entry align="left" valign="top"><simpara>5.68</simpara></entry>
22187 <entry align="left" valign="top"><simpara>165.56</simpara></entry>
22188 <entry align="left" valign="top"><simpara>3.92</simpara></entry>
22189 <entry align="left" valign="top"><simpara>37.52</simpara></entry>
22190 </row>
22191 <row>
22192 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/ray.sml"><literal>ray.sml</literal></ulink></simpara></entry>
22193 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22194 <entry align="left" valign="top"><simpara>12.05</simpara></entry>
22195 <entry align="left" valign="top"><simpara>25.08</simpara></entry>
22196 <entry align="left" valign="top"><simpara>8.73</simpara></entry>
22197 <entry align="left" valign="top"><simpara>1.75</simpara></entry>
22198 </row>
22199 <row>
22200 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/raytrace.sml"><literal>raytrace.sml</literal></ulink></simpara></entry>
22201 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22202 <entry align="left" valign="top"><simpara>*</simpara></entry>
22203 <entry align="left" valign="top"><simpara>*</simpara></entry>
22204 <entry align="left" valign="top"><simpara>2.11</simpara></entry>
22205 <entry align="left" valign="top"><simpara>3.33</simpara></entry>
22206 </row>
22207 <row>
22208 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/simple.sml"><literal>simple.sml</literal></ulink></simpara></entry>
22209 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22210 <entry align="left" valign="top"><simpara>2.95</simpara></entry>
22211 <entry align="left" valign="top"><simpara>24.03</simpara></entry>
22212 <entry align="left" valign="top"><simpara>3.67</simpara></entry>
22213 <entry align="left" valign="top"><simpara>1.93</simpara></entry>
22214 </row>
22215 <row>
22216 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/smith-normal-form.sml"><literal>smith-normal-form.sml</literal></ulink></simpara></entry>
22217 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22218 <entry align="left" valign="top"><simpara>*</simpara></entry>
22219 <entry align="left" valign="top"><simpara>*</simpara></entry>
22220 <entry align="left" valign="top"><simpara>1.04</simpara></entry>
22221 <entry align="left" valign="top"><simpara>*</simpara></entry>
22222 </row>
22223 <row>
22224 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/string-concat.sml"><literal>string-concat.sml</literal></ulink></simpara></entry>
22225 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22226 <entry align="left" valign="top"><simpara>1.88</simpara></entry>
22227 <entry align="left" valign="top"><simpara>28.01</simpara></entry>
22228 <entry align="left" valign="top"><simpara>0.70</simpara></entry>
22229 <entry align="left" valign="top"><simpara>2.67</simpara></entry>
22230 </row>
22231 <row>
22232 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tailfib.sml"><literal>tailfib.sml</literal></ulink></simpara></entry>
22233 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22234 <entry align="left" valign="top"><simpara>1.58</simpara></entry>
22235 <entry align="left" valign="top"><simpara>23.57</simpara></entry>
22236 <entry align="left" valign="top"><simpara>0.90</simpara></entry>
22237 <entry align="left" valign="top"><simpara>1.04</simpara></entry>
22238 </row>
22239 <row>
22240 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tak.sml"><literal>tak.sml</literal></ulink></simpara></entry>
22241 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22242 <entry align="left" valign="top"><simpara>1.69</simpara></entry>
22243 <entry align="left" valign="top"><simpara>15.90</simpara></entry>
22244 <entry align="left" valign="top"><simpara>1.57</simpara></entry>
22245 <entry align="left" valign="top"><simpara>2.01</simpara></entry>
22246 </row>
22247 <row>
22248 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tensor.sml"><literal>tensor.sml</literal></ulink></simpara></entry>
22249 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22250 <entry align="left" valign="top"><simpara>*</simpara></entry>
22251 <entry align="left" valign="top"><simpara>*</simpara></entry>
22252 <entry align="left" valign="top"><simpara>*</simpara></entry>
22253 <entry align="left" valign="top"><simpara>2.07</simpara></entry>
22254 </row>
22255 <row>
22256 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tsp.sml"><literal>tsp.sml</literal></ulink></simpara></entry>
22257 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22258 <entry align="left" valign="top"><simpara>2.19</simpara></entry>
22259 <entry align="left" valign="top"><simpara>66.76</simpara></entry>
22260 <entry align="left" valign="top"><simpara>3.27</simpara></entry>
22261 <entry align="left" valign="top"><simpara>1.48</simpara></entry>
22262 </row>
22263 <row>
22264 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tyan.sml"><literal>tyan.sml</literal></ulink></simpara></entry>
22265 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22266 <entry align="left" valign="top"><simpara>*</simpara></entry>
22267 <entry align="left" valign="top"><simpara>19.43</simpara></entry>
22268 <entry align="left" valign="top"><simpara>1.08</simpara></entry>
22269 <entry align="left" valign="top"><simpara>1.03</simpara></entry>
22270 </row>
22271 <row>
22272 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vector32-concat.sml"><literal>vector32-concat.sml</literal></ulink></simpara></entry>
22273 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22274 <entry align="left" valign="top"><simpara>13.85</simpara></entry>
22275 <entry align="left" valign="top"><simpara>*</simpara></entry>
22276 <entry align="left" valign="top"><simpara>1.80</simpara></entry>
22277 <entry align="left" valign="top"><simpara>12.48</simpara></entry>
22278 </row>
22279 <row>
22280 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vector64-concat.sml"><literal>vector64-concat.sml</literal></ulink></simpara></entry>
22281 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22282 <entry align="left" valign="top"><simpara>*</simpara></entry>
22283 <entry align="left" valign="top"><simpara>*</simpara></entry>
22284 <entry align="left" valign="top"><simpara>*</simpara></entry>
22285 <entry align="left" valign="top"><simpara>13.92</simpara></entry>
22286 </row>
22287 <row>
22288 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vector-rev.sml"><literal>vector-rev.sml</literal></ulink></simpara></entry>
22289 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22290 <entry align="left" valign="top"><simpara>7.88</simpara></entry>
22291 <entry align="left" valign="top"><simpara>68.85</simpara></entry>
22292 <entry align="left" valign="top"><simpara>9.39</simpara></entry>
22293 <entry align="left" valign="top"><simpara>68.80</simpara></entry>
22294 </row>
22295 <row>
22296 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vliw.sml"><literal>vliw.sml</literal></ulink></simpara></entry>
22297 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22298 <entry align="left" valign="top"><simpara>2.46</simpara></entry>
22299 <entry align="left" valign="top"><simpara>15.39</simpara></entry>
22300 <entry align="left" valign="top"><simpara>1.43</simpara></entry>
22301 <entry align="left" valign="top"><simpara>1.55</simpara></entry>
22302 </row>
22303 <row>
22304 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/wc-input1.sml"><literal>wc-input1.sml</literal></ulink></simpara></entry>
22305 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22306 <entry align="left" valign="top"><simpara>6.00</simpara></entry>
22307 <entry align="left" valign="top"><simpara>*</simpara></entry>
22308 <entry align="left" valign="top"><simpara>29.25</simpara></entry>
22309 <entry align="left" valign="top"><simpara>9.54</simpara></entry>
22310 </row>
22311 <row>
22312 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/wc-scanStream.sml"><literal>wc-scanStream.sml</literal></ulink></simpara></entry>
22313 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22314 <entry align="left" valign="top"><simpara>80.43</simpara></entry>
22315 <entry align="left" valign="top"><simpara>*</simpara></entry>
22316 <entry align="left" valign="top"><simpara>19.45</simpara></entry>
22317 <entry align="left" valign="top"><simpara>8.71</simpara></entry>
22318 </row>
22319 <row>
22320 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/zebra.sml"><literal>zebra.sml</literal></ulink></simpara></entry>
22321 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22322 <entry align="left" valign="top"><simpara>4.62</simpara></entry>
22323 <entry align="left" valign="top"><simpara>35.56</simpara></entry>
22324 <entry align="left" valign="top"><simpara>1.68</simpara></entry>
22325 <entry align="left" valign="top"><simpara>9.97</simpara></entry>
22326 </row>
22327 <row>
22328 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/zern.sml"><literal>zern.sml</literal></ulink></simpara></entry>
22329 <entry align="left" valign="top"><simpara>1.00</simpara></entry>
22330 <entry align="left" valign="top"><simpara>*</simpara></entry>
22331 <entry align="left" valign="top"><simpara>*</simpara></entry>
22332 <entry align="left" valign="top"><simpara>*</simpara></entry>
22333 <entry align="left" valign="top"><simpara>1.60</simpara></entry>
22334 </row>
22335 </tbody>
22336 </tgroup>
22337 </informaltable>
22338 <simpara><anchor id="Performance_SNFNote" xreflabel="[Performance_SNFNote]"/>
22339 Note: for SML/NJ, the
22340 <ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/smith-normal-form.sml"><literal>smith-normal-form.sml</literal></ulink>
22341 benchmark was killed after running for over 51,000 seconds.</simpara>
22342 </section>
22343 <section id="_anchor_id_performance_codesize_xreflabel_performance_codesize_code_size">
22344 <title><anchor id="Performance_CodeSize" xreflabel="[Performance_CodeSize]"/>Code size</title>
22345 <simpara>The following table gives the code size of each benchmark in bytes.
22346 The size for MLton and the ML Kit is the sum of text and data for the
22347 standalone executable as reported by <literal>size</literal>. The size for Moscow
22348 ML is the size in bytes of the executable <literal>a.out</literal>. The size for
22349 Poly/ML is the difference in size of the database before the session
22350 start and after the commit. The size for SML/NJ is the size of the
22351 heap file created by <literal>exportFn</literal> and does not include the size of
22352 the SML/NJ runtime system (approximately 100K). A * in an entry means
22353 that the compiler failed to compile the benchmark.</simpara>
22354 <informaltable
22355 frame="all"
22356 rowsep="1" colsep="1"
22357 >
22358 <tgroup cols="6">
22359 <colspec colname="col_1" colwidth="28*"/>
22360 <colspec colname="col_2" colwidth="14*"/>
22361 <colspec colname="col_3" colwidth="14*"/>
22362 <colspec colname="col_4" colwidth="14*"/>
22363 <colspec colname="col_5" colwidth="14*"/>
22364 <colspec colname="col_6" colwidth="14*"/>
22365 <thead>
22366 <row>
22367 <entry align="left" valign="top">benchmark</entry>
22368 <entry align="left" valign="top">MLton</entry>
22369 <entry align="left" valign="top">ML-Kit</entry>
22370 <entry align="left" valign="top">MosML</entry>
22371 <entry align="left" valign="top">Poly/ML</entry>
22372 <entry align="left" valign="top">SML/NJ</entry>
22373 </row>
22374 </thead>
22375 <tbody>
22376 <row>
22377 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/barnes-hut.sml"><literal>barnes-hut.sml</literal></ulink></simpara></entry>
22378 <entry align="left" valign="top"><simpara>180,788</simpara></entry>
22379 <entry align="left" valign="top"><simpara>810,267</simpara></entry>
22380 <entry align="left" valign="top"><simpara>199,503</simpara></entry>
22381 <entry align="left" valign="top"><simpara>148,120</simpara></entry>
22382 <entry align="left" valign="top"><simpara>402,480</simpara></entry>
22383 </row>
22384 <row>
22385 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/boyer.sml"><literal>boyer.sml</literal></ulink></simpara></entry>
22386 <entry align="left" valign="top"><simpara>250,246</simpara></entry>
22387 <entry align="left" valign="top"><simpara>*</simpara></entry>
22388 <entry align="left" valign="top"><simpara>248,018</simpara></entry>
22389 <entry align="left" valign="top"><simpara>196,984</simpara></entry>
22390 <entry align="left" valign="top"><simpara>496,664</simpara></entry>
22391 </row>
22392 <row>
22393 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/checksum.sml"><literal>checksum.sml</literal></ulink></simpara></entry>
22394 <entry align="left" valign="top"><simpara>122,422</simpara></entry>
22395 <entry align="left" valign="top"><simpara>225,274</simpara></entry>
22396 <entry align="left" valign="top"><simpara>*</simpara></entry>
22397 <entry align="left" valign="top"><simpara>106,088</simpara></entry>
22398 <entry align="left" valign="top"><simpara>406,560</simpara></entry>
22399 </row>
22400 <row>
22401 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/count-graphs.sml"><literal>count-graphs.sml</literal></ulink></simpara></entry>
22402 <entry align="left" valign="top"><simpara>151,878</simpara></entry>
22403 <entry align="left" valign="top"><simpara>250,126</simpara></entry>
22404 <entry align="left" valign="top"><simpara>187,048</simpara></entry>
22405 <entry align="left" valign="top"><simpara>144,032</simpara></entry>
22406 <entry align="left" valign="top"><simpara>428,136</simpara></entry>
22407 </row>
22408 <row>
22409 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/DLXSimulator.sml"><literal>DLXSimulator.sml</literal></ulink></simpara></entry>
22410 <entry align="left" valign="top"><simpara>223,073</simpara></entry>
22411 <entry align="left" valign="top"><simpara>827,483</simpara></entry>
22412 <entry align="left" valign="top"><simpara>*</simpara></entry>
22413 <entry align="left" valign="top"><simpara>272,664</simpara></entry>
22414 <entry align="left" valign="top"><simpara>*</simpara></entry>
22415 </row>
22416 <row>
22417 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/even-odd.sml"><literal>even-odd.sml</literal></ulink></simpara></entry>
22418 <entry align="left" valign="top"><simpara>122,350</simpara></entry>
22419 <entry align="left" valign="top"><simpara>87,586</simpara></entry>
22420 <entry align="left" valign="top"><simpara>181,415</simpara></entry>
22421 <entry align="left" valign="top"><simpara>106,072</simpara></entry>
22422 <entry align="left" valign="top"><simpara>380,928</simpara></entry>
22423 </row>
22424 <row>
22425 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/fft.sml"><literal>fft.sml</literal></ulink></simpara></entry>
22426 <entry align="left" valign="top"><simpara>145,008</simpara></entry>
22427 <entry align="left" valign="top"><simpara>237,230</simpara></entry>
22428 <entry align="left" valign="top"><simpara>186,228</simpara></entry>
22429 <entry align="left" valign="top"><simpara>131,400</simpara></entry>
22430 <entry align="left" valign="top"><simpara>418,896</simpara></entry>
22431 </row>
22432 <row>
22433 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/fib.sml"><literal>fib.sml</literal></ulink></simpara></entry>
22434 <entry align="left" valign="top"><simpara>122,310</simpara></entry>
22435 <entry align="left" valign="top"><simpara>87,402</simpara></entry>
22436 <entry align="left" valign="top"><simpara>181,312</simpara></entry>
22437 <entry align="left" valign="top"><simpara>106,088</simpara></entry>
22438 <entry align="left" valign="top"><simpara>380,928</simpara></entry>
22439 </row>
22440 <row>
22441 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/flat-array.sml"><literal>flat-array.sml</literal></ulink></simpara></entry>
22442 <entry align="left" valign="top"><simpara>121,958</simpara></entry>
22443 <entry align="left" valign="top"><simpara>104,102</simpara></entry>
22444 <entry align="left" valign="top"><simpara>181,464</simpara></entry>
22445 <entry align="left" valign="top"><simpara>106,072</simpara></entry>
22446 <entry align="left" valign="top"><simpara>394,256</simpara></entry>
22447 </row>
22448 <row>
22449 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/hamlet.sml"><literal>hamlet.sml</literal></ulink></simpara></entry>
22450 <entry align="left" valign="top"><simpara>1,503,849</simpara></entry>
22451 <entry align="left" valign="top"><simpara>2,280,691</simpara></entry>
22452 <entry align="left" valign="top"><simpara>407,219</simpara></entry>
22453 <entry align="left" valign="top"><simpara>2,249,504</simpara></entry>
22454 <entry align="left" valign="top"><simpara>*</simpara></entry>
22455 </row>
22456 <row>
22457 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/imp-for.sml"><literal>imp-for.sml</literal></ulink></simpara></entry>
22458 <entry align="left" valign="top"><simpara>122,078</simpara></entry>
22459 <entry align="left" valign="top"><simpara>89,346</simpara></entry>
22460 <entry align="left" valign="top"><simpara>181,470</simpara></entry>
22461 <entry align="left" valign="top"><simpara>106,088</simpara></entry>
22462 <entry align="left" valign="top"><simpara>381,952</simpara></entry>
22463 </row>
22464 <row>
22465 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/knuth-bendix.sml"><literal>knuth-bendix.sml</literal></ulink></simpara></entry>
22466 <entry align="left" valign="top"><simpara>193,145</simpara></entry>
22467 <entry align="left" valign="top"><simpara>*</simpara></entry>
22468 <entry align="left" valign="top"><simpara>192,659</simpara></entry>
22469 <entry align="left" valign="top"><simpara>161,080</simpara></entry>
22470 <entry align="left" valign="top"><simpara>400,408</simpara></entry>
22471 </row>
22472 <row>
22473 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/lexgen.sml"><literal>lexgen.sml</literal></ulink></simpara></entry>
22474 <entry align="left" valign="top"><simpara>308,296</simpara></entry>
22475 <entry align="left" valign="top"><simpara>826,819</simpara></entry>
22476 <entry align="left" valign="top"><simpara>213,128</simpara></entry>
22477 <entry align="left" valign="top"><simpara>268,272</simpara></entry>
22478 <entry align="left" valign="top"><simpara>*</simpara></entry>
22479 </row>
22480 <row>
22481 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/life.sml"><literal>life.sml</literal></ulink></simpara></entry>
22482 <entry align="left" valign="top"><simpara>141,862</simpara></entry>
22483 <entry align="left" valign="top"><simpara>721,419</simpara></entry>
22484 <entry align="left" valign="top"><simpara>186,463</simpara></entry>
22485 <entry align="left" valign="top"><simpara>118,552</simpara></entry>
22486 <entry align="left" valign="top"><simpara>384,024</simpara></entry>
22487 </row>
22488 <row>
22489 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/logic.sml"><literal>logic.sml</literal></ulink></simpara></entry>
22490 <entry align="left" valign="top"><simpara>211,086</simpara></entry>
22491 <entry align="left" valign="top"><simpara>782,667</simpara></entry>
22492 <entry align="left" valign="top"><simpara>188,908</simpara></entry>
22493 <entry align="left" valign="top"><simpara>198,408</simpara></entry>
22494 <entry align="left" valign="top"><simpara>409,624</simpara></entry>
22495 </row>
22496 <row>
22497 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/mandelbrot.sml"><literal>mandelbrot.sml</literal></ulink></simpara></entry>
22498 <entry align="left" valign="top"><simpara>122,086</simpara></entry>
22499 <entry align="left" valign="top"><simpara>700,075</simpara></entry>
22500 <entry align="left" valign="top"><simpara>183,037</simpara></entry>
22501 <entry align="left" valign="top"><simpara>106,104</simpara></entry>
22502 <entry align="left" valign="top"><simpara>386,048</simpara></entry>
22503 </row>
22504 <row>
22505 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/matrix-multiply.sml"><literal>matrix-multiply.sml</literal></ulink></simpara></entry>
22506 <entry align="left" valign="top"><simpara>124,398</simpara></entry>
22507 <entry align="left" valign="top"><simpara>280,006</simpara></entry>
22508 <entry align="left" valign="top"><simpara>184,328</simpara></entry>
22509 <entry align="left" valign="top"><simpara>110,232</simpara></entry>
22510 <entry align="left" valign="top"><simpara>416,784</simpara></entry>
22511 </row>
22512 <row>
22513 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/md5.sml"><literal>md5.sml</literal></ulink></simpara></entry>
22514 <entry align="left" valign="top"><simpara>150,497</simpara></entry>
22515 <entry align="left" valign="top"><simpara>271,794</simpara></entry>
22516 <entry align="left" valign="top"><simpara>*</simpara></entry>
22517 <entry align="left" valign="top"><simpara>122,624</simpara></entry>
22518 <entry align="left" valign="top"><simpara>399,416</simpara></entry>
22519 </row>
22520 <row>
22521 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/merge.sml"><literal>merge.sml</literal></ulink></simpara></entry>
22522 <entry align="left" valign="top"><simpara>123,846</simpara></entry>
22523 <entry align="left" valign="top"><simpara>100,858</simpara></entry>
22524 <entry align="left" valign="top"><simpara>181,542</simpara></entry>
22525 <entry align="left" valign="top"><simpara>106,136</simpara></entry>
22526 <entry align="left" valign="top"><simpara>381,960</simpara></entry>
22527 </row>
22528 <row>
22529 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/mlyacc.sml"><literal>mlyacc.sml</literal></ulink></simpara></entry>
22530 <entry align="left" valign="top"><simpara>678,920</simpara></entry>
22531 <entry align="left" valign="top"><simpara>1,233,587</simpara></entry>
22532 <entry align="left" valign="top"><simpara>263,721</simpara></entry>
22533 <entry align="left" valign="top"><simpara>576,728</simpara></entry>
22534 <entry align="left" valign="top"><simpara>*</simpara></entry>
22535 </row>
22536 <row>
22537 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/model-elimination.sml"><literal>model-elimination.sml</literal></ulink></simpara></entry>
22538 <entry align="left" valign="top"><simpara>846,779</simpara></entry>
22539 <entry align="left" valign="top"><simpara>1,432,283</simpara></entry>
22540 <entry align="left" valign="top"><simpara>297,108</simpara></entry>
22541 <entry align="left" valign="top"><simpara>777,664</simpara></entry>
22542 <entry align="left" valign="top"><simpara>985,304</simpara></entry>
22543 </row>
22544 <row>
22545 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/mpuz.sml"><literal>mpuz.sml</literal></ulink></simpara></entry>
22546 <entry align="left" valign="top"><simpara>124,126</simpara></entry>
22547 <entry align="left" valign="top"><simpara>229,078</simpara></entry>
22548 <entry align="left" valign="top"><simpara>184,440</simpara></entry>
22549 <entry align="left" valign="top"><simpara>114,584</simpara></entry>
22550 <entry align="left" valign="top"><simpara>392,232</simpara></entry>
22551 </row>
22552 <row>
22553 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/nucleic.sml"><literal>nucleic.sml</literal></ulink></simpara></entry>
22554 <entry align="left" valign="top"><simpara>298,038</simpara></entry>
22555 <entry align="left" valign="top"><simpara>507,186</simpara></entry>
22556 <entry align="left" valign="top"><simpara>*</simpara></entry>
22557 <entry align="left" valign="top"><simpara>475,808</simpara></entry>
22558 <entry align="left" valign="top"><simpara>456,744</simpara></entry>
22559 </row>
22560 <row>
22561 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/output1.sml"><literal>output1.sml</literal></ulink></simpara></entry>
22562 <entry align="left" valign="top"><simpara>157,973</simpara></entry>
22563 <entry align="left" valign="top"><simpara>699,003</simpara></entry>
22564 <entry align="left" valign="top"><simpara>181,680</simpara></entry>
22565 <entry align="left" valign="top"><simpara>118,800</simpara></entry>
22566 <entry align="left" valign="top"><simpara>380,928</simpara></entry>
22567 </row>
22568 <row>
22569 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/peek.sml"><literal>peek.sml</literal></ulink></simpara></entry>
22570 <entry align="left" valign="top"><simpara>156,401</simpara></entry>
22571 <entry align="left" valign="top"><simpara>201,138</simpara></entry>
22572 <entry align="left" valign="top"><simpara>183,438</simpara></entry>
22573 <entry align="left" valign="top"><simpara>110,456</simpara></entry>
22574 <entry align="left" valign="top"><simpara>385,072</simpara></entry>
22575 </row>
22576 <row>
22577 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/psdes-random.sml"><literal>psdes-random.sml</literal></ulink></simpara></entry>
22578 <entry align="left" valign="top"><simpara>126,486</simpara></entry>
22579 <entry align="left" valign="top"><simpara>106,166</simpara></entry>
22580 <entry align="left" valign="top"><simpara>*</simpara></entry>
22581 <entry align="left" valign="top"><simpara>106,088</simpara></entry>
22582 <entry align="left" valign="top"><simpara>393,256</simpara></entry>
22583 </row>
22584 <row>
22585 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/ratio-regions.sml"><literal>ratio-regions.sml</literal></ulink></simpara></entry>
22586 <entry align="left" valign="top"><simpara>150,174</simpara></entry>
22587 <entry align="left" valign="top"><simpara>265,694</simpara></entry>
22588 <entry align="left" valign="top"><simpara>190,088</simpara></entry>
22589 <entry align="left" valign="top"><simpara>184,536</simpara></entry>
22590 <entry align="left" valign="top"><simpara>414,760</simpara></entry>
22591 </row>
22592 <row>
22593 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/ray.sml"><literal>ray.sml</literal></ulink></simpara></entry>
22594 <entry align="left" valign="top"><simpara>260,863</simpara></entry>
22595 <entry align="left" valign="top"><simpara>736,795</simpara></entry>
22596 <entry align="left" valign="top"><simpara>195,064</simpara></entry>
22597 <entry align="left" valign="top"><simpara>198,976</simpara></entry>
22598 <entry align="left" valign="top"><simpara>512,160</simpara></entry>
22599 </row>
22600 <row>
22601 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/raytrace.sml"><literal>raytrace.sml</literal></ulink></simpara></entry>
22602 <entry align="left" valign="top"><simpara>384,905</simpara></entry>
22603 <entry align="left" valign="top"><simpara>*</simpara></entry>
22604 <entry align="left" valign="top"><simpara>*</simpara></entry>
22605 <entry align="left" valign="top"><simpara>446,424</simpara></entry>
22606 <entry align="left" valign="top"><simpara>623,824</simpara></entry>
22607 </row>
22608 <row>
22609 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/simple.sml"><literal>simple.sml</literal></ulink></simpara></entry>
22610 <entry align="left" valign="top"><simpara>365,578</simpara></entry>
22611 <entry align="left" valign="top"><simpara>895,139</simpara></entry>
22612 <entry align="left" valign="top"><simpara>197,765</simpara></entry>
22613 <entry align="left" valign="top"><simpara>1,051,952</simpara></entry>
22614 <entry align="left" valign="top"><simpara>708,696</simpara></entry>
22615 </row>
22616 <row>
22617 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/smith-normal-form.sml"><literal>smith-normal-form.sml</literal></ulink></simpara></entry>
22618 <entry align="left" valign="top"><simpara>286,474</simpara></entry>
22619 <entry align="left" valign="top"><simpara>*</simpara></entry>
22620 <entry align="left" valign="top"><simpara>*</simpara></entry>
22621 <entry align="left" valign="top"><simpara>262,616</simpara></entry>
22622 <entry align="left" valign="top"><simpara>547,984</simpara></entry>
22623 </row>
22624 <row>
22625 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/string-concat.sml"><literal>string-concat.sml</literal></ulink></simpara></entry>
22626 <entry align="left" valign="top"><simpara>119,102</simpara></entry>
22627 <entry align="left" valign="top"><simpara>140,626</simpara></entry>
22628 <entry align="left" valign="top"><simpara>183,249</simpara></entry>
22629 <entry align="left" valign="top"><simpara>106,088</simpara></entry>
22630 <entry align="left" valign="top"><simpara>390,160</simpara></entry>
22631 </row>
22632 <row>
22633 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tailfib.sml"><literal>tailfib.sml</literal></ulink></simpara></entry>
22634 <entry align="left" valign="top"><simpara>122,110</simpara></entry>
22635 <entry align="left" valign="top"><simpara>87,890</simpara></entry>
22636 <entry align="left" valign="top"><simpara>181,369</simpara></entry>
22637 <entry align="left" valign="top"><simpara>106,072</simpara></entry>
22638 <entry align="left" valign="top"><simpara>381,952</simpara></entry>
22639 </row>
22640 <row>
22641 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tak.sml"><literal>tak.sml</literal></ulink></simpara></entry>
22642 <entry align="left" valign="top"><simpara>122,246</simpara></entry>
22643 <entry align="left" valign="top"><simpara>87,402</simpara></entry>
22644 <entry align="left" valign="top"><simpara>181,349</simpara></entry>
22645 <entry align="left" valign="top"><simpara>106,088</simpara></entry>
22646 <entry align="left" valign="top"><simpara>376,832</simpara></entry>
22647 </row>
22648 <row>
22649 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tensor.sml"><literal>tensor.sml</literal></ulink></simpara></entry>
22650 <entry align="left" valign="top"><simpara>186,545</simpara></entry>
22651 <entry align="left" valign="top"><simpara>*</simpara></entry>
22652 <entry align="left" valign="top"><simpara>*</simpara></entry>
22653 <entry align="left" valign="top"><simpara>*</simpara></entry>
22654 <entry align="left" valign="top"><simpara>421,984</simpara></entry>
22655 </row>
22656 <row>
22657 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tsp.sml"><literal>tsp.sml</literal></ulink></simpara></entry>
22658 <entry align="left" valign="top"><simpara>163,033</simpara></entry>
22659 <entry align="left" valign="top"><simpara>722,571</simpara></entry>
22660 <entry align="left" valign="top"><simpara>188,634</simpara></entry>
22661 <entry align="left" valign="top"><simpara>126,984</simpara></entry>
22662 <entry align="left" valign="top"><simpara>393,264</simpara></entry>
22663 </row>
22664 <row>
22665 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tyan.sml"><literal>tyan.sml</literal></ulink></simpara></entry>
22666 <entry align="left" valign="top"><simpara>235,449</simpara></entry>
22667 <entry align="left" valign="top"><simpara>*</simpara></entry>
22668 <entry align="left" valign="top"><simpara>195,401</simpara></entry>
22669 <entry align="left" valign="top"><simpara>184,816</simpara></entry>
22670 <entry align="left" valign="top"><simpara>478,296</simpara></entry>
22671 </row>
22672 <row>
22673 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vector32-concat.sml"><literal>vector32-concat.sml</literal></ulink></simpara></entry>
22674 <entry align="left" valign="top"><simpara>123,790</simpara></entry>
22675 <entry align="left" valign="top"><simpara>104,398</simpara></entry>
22676 <entry align="left" valign="top"><simpara>*</simpara></entry>
22677 <entry align="left" valign="top"><simpara>106,200</simpara></entry>
22678 <entry align="left" valign="top"><simpara>394,256</simpara></entry>
22679 </row>
22680 <row>
22681 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vector64-concat.sml"><literal>vector64-concat.sml</literal></ulink></simpara></entry>
22682 <entry align="left" valign="top"><simpara>123,846</simpara></entry>
22683 <entry align="left" valign="top"><simpara>*</simpara></entry>
22684 <entry align="left" valign="top"><simpara>*</simpara></entry>
22685 <entry align="left" valign="top"><simpara>*</simpara></entry>
22686 <entry align="left" valign="top"><simpara>405,552</simpara></entry>
22687 </row>
22688 <row>
22689 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vector-rev.sml"><literal>vector-rev.sml</literal></ulink></simpara></entry>
22690 <entry align="left" valign="top"><simpara>122,982</simpara></entry>
22691 <entry align="left" valign="top"><simpara>104,614</simpara></entry>
22692 <entry align="left" valign="top"><simpara>181,534</simpara></entry>
22693 <entry align="left" valign="top"><simpara>106,072</simpara></entry>
22694 <entry align="left" valign="top"><simpara>394,256</simpara></entry>
22695 </row>
22696 <row>
22697 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vliw.sml"><literal>vliw.sml</literal></ulink></simpara></entry>
22698 <entry align="left" valign="top"><simpara>538,074</simpara></entry>
22699 <entry align="left" valign="top"><simpara>1,182,851</simpara></entry>
22700 <entry align="left" valign="top"><simpara>249,884</simpara></entry>
22701 <entry align="left" valign="top"><simpara>580,792</simpara></entry>
22702 <entry align="left" valign="top"><simpara>749,752</simpara></entry>
22703 </row>
22704 <row>
22705 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/wc-input1.sml"><literal>wc-input1.sml</literal></ulink></simpara></entry>
22706 <entry align="left" valign="top"><simpara>186,152</simpara></entry>
22707 <entry align="left" valign="top"><simpara>699,459</simpara></entry>
22708 <entry align="left" valign="top"><simpara>191,347</simpara></entry>
22709 <entry align="left" valign="top"><simpara>127,200</simpara></entry>
22710 <entry align="left" valign="top"><simpara>386,048</simpara></entry>
22711 </row>
22712 <row>
22713 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/wc-scanStream.sml"><literal>wc-scanStream.sml</literal></ulink></simpara></entry>
22714 <entry align="left" valign="top"><simpara>196,232</simpara></entry>
22715 <entry align="left" valign="top"><simpara>700,131</simpara></entry>
22716 <entry align="left" valign="top"><simpara>191,539</simpara></entry>
22717 <entry align="left" valign="top"><simpara>127,232</simpara></entry>
22718 <entry align="left" valign="top"><simpara>387,072</simpara></entry>
22719 </row>
22720 <row>
22721 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/zebra.sml"><literal>zebra.sml</literal></ulink></simpara></entry>
22722 <entry align="left" valign="top"><simpara>230,433</simpara></entry>
22723 <entry align="left" valign="top"><simpara>128,354</simpara></entry>
22724 <entry align="left" valign="top"><simpara>186,322</simpara></entry>
22725 <entry align="left" valign="top"><simpara>127,048</simpara></entry>
22726 <entry align="left" valign="top"><simpara>390,184</simpara></entry>
22727 </row>
22728 <row>
22729 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/zern.sml"><literal>zern.sml</literal></ulink></simpara></entry>
22730 <entry align="left" valign="top"><simpara>156,902</simpara></entry>
22731 <entry align="left" valign="top"><simpara>*</simpara></entry>
22732 <entry align="left" valign="top"><simpara>*</simpara></entry>
22733 <entry align="left" valign="top"><simpara>*</simpara></entry>
22734 <entry align="left" valign="top"><simpara>453,768</simpara></entry>
22735 </row>
22736 </tbody>
22737 </tgroup>
22738 </informaltable>
22739 </section>
22740 <section id="_anchor_id_performance_compiletime_xreflabel_performance_compiletime_compile_time">
22741 <title><anchor id="Performance_CompileTime" xreflabel="[Performance_CompileTime]"/>Compile time</title>
22742 <simpara>The following table gives the compile time of each benchmark in
22743 seconds. A * in an entry means that the compiler failed to compile
22744 the benchmark.</simpara>
22745 <informaltable
22746 frame="all"
22747 rowsep="1" colsep="1"
22748 >
22749 <tgroup cols="6">
22750 <colspec colname="col_1" colwidth="28*"/>
22751 <colspec colname="col_2" colwidth="14*"/>
22752 <colspec colname="col_3" colwidth="14*"/>
22753 <colspec colname="col_4" colwidth="14*"/>
22754 <colspec colname="col_5" colwidth="14*"/>
22755 <colspec colname="col_6" colwidth="14*"/>
22756 <thead>
22757 <row>
22758 <entry align="left" valign="top">benchmark</entry>
22759 <entry align="left" valign="top">MLton</entry>
22760 <entry align="left" valign="top">ML-Kit</entry>
22761 <entry align="left" valign="top">MosML</entry>
22762 <entry align="left" valign="top">Poly/ML</entry>
22763 <entry align="left" valign="top">SML/NJ</entry>
22764 </row>
22765 </thead>
22766 <tbody>
22767 <row>
22768 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/barnes-hut.sml"><literal>barnes-hut.sml</literal></ulink></simpara></entry>
22769 <entry align="left" valign="top"><simpara>2.70</simpara></entry>
22770 <entry align="left" valign="top"><simpara>0.89</simpara></entry>
22771 <entry align="left" valign="top"><simpara>0.15</simpara></entry>
22772 <entry align="left" valign="top"><simpara>0.29</simpara></entry>
22773 <entry align="left" valign="top"><simpara>0.20</simpara></entry>
22774 </row>
22775 <row>
22776 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/boyer.sml"><literal>boyer.sml</literal></ulink></simpara></entry>
22777 <entry align="left" valign="top"><simpara>2.87</simpara></entry>
22778 <entry align="left" valign="top"><simpara>*</simpara></entry>
22779 <entry align="left" valign="top"><simpara>0.14</simpara></entry>
22780 <entry align="left" valign="top"><simpara>0.20</simpara></entry>
22781 <entry align="left" valign="top"><simpara>0.41</simpara></entry>
22782 </row>
22783 <row>
22784 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/checksum.sml"><literal>checksum.sml</literal></ulink></simpara></entry>
22785 <entry align="left" valign="top"><simpara>2.21</simpara></entry>
22786 <entry align="left" valign="top"><simpara>0.24</simpara></entry>
22787 <entry align="left" valign="top"><simpara>*</simpara></entry>
22788 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22789 <entry align="left" valign="top"><simpara>0.05</simpara></entry>
22790 </row>
22791 <row>
22792 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/count-graphs.sml"><literal>count-graphs.sml</literal></ulink></simpara></entry>
22793 <entry align="left" valign="top"><simpara>2.28</simpara></entry>
22794 <entry align="left" valign="top"><simpara>0.34</simpara></entry>
22795 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
22796 <entry align="left" valign="top"><simpara>0.11</simpara></entry>
22797 <entry align="left" valign="top"><simpara>0.21</simpara></entry>
22798 </row>
22799 <row>
22800 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/DLXSimulator.sml"><literal>DLXSimulator.sml</literal></ulink></simpara></entry>
22801 <entry align="left" valign="top"><simpara>2.93</simpara></entry>
22802 <entry align="left" valign="top"><simpara>1.01</simpara></entry>
22803 <entry align="left" valign="top"><simpara>*</simpara></entry>
22804 <entry align="left" valign="top"><simpara>0.27</simpara></entry>
22805 <entry align="left" valign="top"><simpara>*</simpara></entry>
22806 </row>
22807 <row>
22808 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/even-odd.sml"><literal>even-odd.sml</literal></ulink></simpara></entry>
22809 <entry align="left" valign="top"><simpara>2.23</simpara></entry>
22810 <entry align="left" valign="top"><simpara>0.20</simpara></entry>
22811 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
22812 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22813 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
22814 </row>
22815 <row>
22816 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/fft.sml"><literal>fft.sml</literal></ulink></simpara></entry>
22817 <entry align="left" valign="top"><simpara>2.35</simpara></entry>
22818 <entry align="left" valign="top"><simpara>0.28</simpara></entry>
22819 <entry align="left" valign="top"><simpara>0.03</simpara></entry>
22820 <entry align="left" valign="top"><simpara>0.09</simpara></entry>
22821 <entry align="left" valign="top"><simpara>0.10</simpara></entry>
22822 </row>
22823 <row>
22824 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/fib.sml"><literal>fib.sml</literal></ulink></simpara></entry>
22825 <entry align="left" valign="top"><simpara>2.16</simpara></entry>
22826 <entry align="left" valign="top"><simpara>0.19</simpara></entry>
22827 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
22828 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22829 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
22830 </row>
22831 <row>
22832 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/flat-array.sml"><literal>flat-array.sml</literal></ulink></simpara></entry>
22833 <entry align="left" valign="top"><simpara>2.16</simpara></entry>
22834 <entry align="left" valign="top"><simpara>0.20</simpara></entry>
22835 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
22836 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22837 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
22838 </row>
22839 <row>
22840 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/hamlet.sml"><literal>hamlet.sml</literal></ulink></simpara></entry>
22841 <entry align="left" valign="top"><simpara>12.28</simpara></entry>
22842 <entry align="left" valign="top"><simpara>19.25</simpara></entry>
22843 <entry align="left" valign="top"><simpara>23.75</simpara></entry>
22844 <entry align="left" valign="top"><simpara>6.44</simpara></entry>
22845 <entry align="left" valign="top"><simpara>*</simpara></entry>
22846 </row>
22847 <row>
22848 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/imp-for.sml"><literal>imp-for.sml</literal></ulink></simpara></entry>
22849 <entry align="left" valign="top"><simpara>2.14</simpara></entry>
22850 <entry align="left" valign="top"><simpara>0.20</simpara></entry>
22851 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
22852 <entry align="left" valign="top"><simpara>0.08</simpara></entry>
22853 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
22854 </row>
22855 <row>
22856 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/knuth-bendix.sml"><literal>knuth-bendix.sml</literal></ulink></simpara></entry>
22857 <entry align="left" valign="top"><simpara>2.48</simpara></entry>
22858 <entry align="left" valign="top"><simpara>*</simpara></entry>
22859 <entry align="left" valign="top"><simpara>0.08</simpara></entry>
22860 <entry align="left" valign="top"><simpara>0.14</simpara></entry>
22861 <entry align="left" valign="top"><simpara>0.23</simpara></entry>
22862 </row>
22863 <row>
22864 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/lexgen.sml"><literal>lexgen.sml</literal></ulink></simpara></entry>
22865 <entry align="left" valign="top"><simpara>3.31</simpara></entry>
22866 <entry align="left" valign="top"><simpara>0.75</simpara></entry>
22867 <entry align="left" valign="top"><simpara>0.15</simpara></entry>
22868 <entry align="left" valign="top"><simpara>0.22</simpara></entry>
22869 <entry align="left" valign="top"><simpara>*</simpara></entry>
22870 </row>
22871 <row>
22872 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/life.sml"><literal>life.sml</literal></ulink></simpara></entry>
22873 <entry align="left" valign="top"><simpara>2.25</simpara></entry>
22874 <entry align="left" valign="top"><simpara>0.32</simpara></entry>
22875 <entry align="left" valign="top"><simpara>0.03</simpara></entry>
22876 <entry align="left" valign="top"><simpara>0.09</simpara></entry>
22877 <entry align="left" valign="top"><simpara>0.10</simpara></entry>
22878 </row>
22879 <row>
22880 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/logic.sml"><literal>logic.sml</literal></ulink></simpara></entry>
22881 <entry align="left" valign="top"><simpara>2.72</simpara></entry>
22882 <entry align="left" valign="top"><simpara>0.57</simpara></entry>
22883 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22884 <entry align="left" valign="top"><simpara>0.17</simpara></entry>
22885 <entry align="left" valign="top"><simpara>0.21</simpara></entry>
22886 </row>
22887 <row>
22888 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/mandelbrot.sml"><literal>mandelbrot.sml</literal></ulink></simpara></entry>
22889 <entry align="left" valign="top"><simpara>2.14</simpara></entry>
22890 <entry align="left" valign="top"><simpara>0.24</simpara></entry>
22891 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
22892 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22893 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
22894 </row>
22895 <row>
22896 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/matrix-multiply.sml"><literal>matrix-multiply.sml</literal></ulink></simpara></entry>
22897 <entry align="left" valign="top"><simpara>2.14</simpara></entry>
22898 <entry align="left" valign="top"><simpara>0.24</simpara></entry>
22899 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
22900 <entry align="left" valign="top"><simpara>0.08</simpara></entry>
22901 <entry align="left" valign="top"><simpara>0.05</simpara></entry>
22902 </row>
22903 <row>
22904 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/md5.sml"><literal>md5.sml</literal></ulink></simpara></entry>
22905 <entry align="left" valign="top"><simpara>2.31</simpara></entry>
22906 <entry align="left" valign="top"><simpara>0.39</simpara></entry>
22907 <entry align="left" valign="top"><simpara>*</simpara></entry>
22908 <entry align="left" valign="top"><simpara>0.12</simpara></entry>
22909 <entry align="left" valign="top"><simpara>0.27</simpara></entry>
22910 </row>
22911 <row>
22912 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/merge.sml"><literal>merge.sml</literal></ulink></simpara></entry>
22913 <entry align="left" valign="top"><simpara>2.15</simpara></entry>
22914 <entry align="left" valign="top"><simpara>0.21</simpara></entry>
22915 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
22916 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22917 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
22918 </row>
22919 <row>
22920 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/mlyacc.sml"><literal>mlyacc.sml</literal></ulink></simpara></entry>
22921 <entry align="left" valign="top"><simpara>7.07</simpara></entry>
22922 <entry align="left" valign="top"><simpara>4.53</simpara></entry>
22923 <entry align="left" valign="top"><simpara>2.05</simpara></entry>
22924 <entry align="left" valign="top"><simpara>0.80</simpara></entry>
22925 <entry align="left" valign="top"><simpara>*</simpara></entry>
22926 </row>
22927 <row>
22928 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/model-elimination.sml"><literal>model-elimination.sml</literal></ulink></simpara></entry>
22929 <entry align="left" valign="top"><simpara>6.78</simpara></entry>
22930 <entry align="left" valign="top"><simpara>4.76</simpara></entry>
22931 <entry align="left" valign="top"><simpara>1.20</simpara></entry>
22932 <entry align="left" valign="top"><simpara>1.65</simpara></entry>
22933 <entry align="left" valign="top"><simpara>4.78</simpara></entry>
22934 </row>
22935 <row>
22936 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/mpuz.sml"><literal>mpuz.sml</literal></ulink></simpara></entry>
22937 <entry align="left" valign="top"><simpara>2.14</simpara></entry>
22938 <entry align="left" valign="top"><simpara>0.28</simpara></entry>
22939 <entry align="left" valign="top"><simpara>0.02</simpara></entry>
22940 <entry align="left" valign="top"><simpara>0.08</simpara></entry>
22941 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22942 </row>
22943 <row>
22944 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/nucleic.sml"><literal>nucleic.sml</literal></ulink></simpara></entry>
22945 <entry align="left" valign="top"><simpara>3.96</simpara></entry>
22946 <entry align="left" valign="top"><simpara>2.12</simpara></entry>
22947 <entry align="left" valign="top"><simpara>*</simpara></entry>
22948 <entry align="left" valign="top"><simpara>0.37</simpara></entry>
22949 <entry align="left" valign="top"><simpara>0.49</simpara></entry>
22950 </row>
22951 <row>
22952 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/output1.sml"><literal>output1.sml</literal></ulink></simpara></entry>
22953 <entry align="left" valign="top"><simpara>2.30</simpara></entry>
22954 <entry align="left" valign="top"><simpara>0.22</simpara></entry>
22955 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
22956 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22957 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
22958 </row>
22959 <row>
22960 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/peek.sml"><literal>peek.sml</literal></ulink></simpara></entry>
22961 <entry align="left" valign="top"><simpara>2.26</simpara></entry>
22962 <entry align="left" valign="top"><simpara>0.20</simpara></entry>
22963 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
22964 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22965 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
22966 </row>
22967 <row>
22968 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/psdes-random.sml"><literal>psdes-random.sml</literal></ulink></simpara></entry>
22969 <entry align="left" valign="top"><simpara>2.12</simpara></entry>
22970 <entry align="left" valign="top"><simpara>0.22</simpara></entry>
22971 <entry align="left" valign="top"><simpara>*</simpara></entry>
22972 <entry align="left" valign="top"><simpara>9.83</simpara></entry>
22973 <entry align="left" valign="top"><simpara>12.55</simpara></entry>
22974 </row>
22975 <row>
22976 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/ratio-regions.sml"><literal>ratio-regions.sml</literal></ulink></simpara></entry>
22977 <entry align="left" valign="top"><simpara>2.59</simpara></entry>
22978 <entry align="left" valign="top"><simpara>0.47</simpara></entry>
22979 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
22980 <entry align="left" valign="top"><simpara>0.16</simpara></entry>
22981 <entry align="left" valign="top"><simpara>0.24</simpara></entry>
22982 </row>
22983 <row>
22984 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/ray.sml"><literal>ray.sml</literal></ulink></simpara></entry>
22985 <entry align="left" valign="top"><simpara>2.95</simpara></entry>
22986 <entry align="left" valign="top"><simpara>0.46</simpara></entry>
22987 <entry align="left" valign="top"><simpara>0.05</simpara></entry>
22988 <entry align="left" valign="top"><simpara>0.17</simpara></entry>
22989 <entry align="left" valign="top"><simpara>0.14</simpara></entry>
22990 </row>
22991 <row>
22992 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/raytrace.sml"><literal>raytrace.sml</literal></ulink></simpara></entry>
22993 <entry align="left" valign="top"><simpara>3.93</simpara></entry>
22994 <entry align="left" valign="top"><simpara>*</simpara></entry>
22995 <entry align="left" valign="top"><simpara>*</simpara></entry>
22996 <entry align="left" valign="top"><simpara>0.45</simpara></entry>
22997 <entry align="left" valign="top"><simpara>0.74</simpara></entry>
22998 </row>
22999 <row>
23000 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/simple.sml"><literal>simple.sml</literal></ulink></simpara></entry>
23001 <entry align="left" valign="top"><simpara>3.42</simpara></entry>
23002 <entry align="left" valign="top"><simpara>1.23</simpara></entry>
23003 <entry align="left" valign="top"><simpara>0.30</simpara></entry>
23004 <entry align="left" valign="top"><simpara>0.32</simpara></entry>
23005 <entry align="left" valign="top"><simpara>0.53</simpara></entry>
23006 </row>
23007 <row>
23008 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/smith-normal-form.sml"><literal>smith-normal-form.sml</literal></ulink></simpara></entry>
23009 <entry align="left" valign="top"><simpara>3.23</simpara></entry>
23010 <entry align="left" valign="top"><simpara>*</simpara></entry>
23011 <entry align="left" valign="top"><simpara>*</simpara></entry>
23012 <entry align="left" valign="top"><simpara>0.15</simpara></entry>
23013 <entry align="left" valign="top"><simpara>0.32</simpara></entry>
23014 </row>
23015 <row>
23016 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/string-concat.sml"><literal>string-concat.sml</literal></ulink></simpara></entry>
23017 <entry align="left" valign="top"><simpara>2.25</simpara></entry>
23018 <entry align="left" valign="top"><simpara>0.28</simpara></entry>
23019 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
23020 <entry align="left" valign="top"><simpara>0.08</simpara></entry>
23021 <entry align="left" valign="top"><simpara>0.05</simpara></entry>
23022 </row>
23023 <row>
23024 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tailfib.sml"><literal>tailfib.sml</literal></ulink></simpara></entry>
23025 <entry align="left" valign="top"><simpara>2.24</simpara></entry>
23026 <entry align="left" valign="top"><simpara>0.21</simpara></entry>
23027 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
23028 <entry align="left" valign="top"><simpara>0.08</simpara></entry>
23029 <entry align="left" valign="top"><simpara>0.05</simpara></entry>
23030 </row>
23031 <row>
23032 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tak.sml"><literal>tak.sml</literal></ulink></simpara></entry>
23033 <entry align="left" valign="top"><simpara>2.23</simpara></entry>
23034 <entry align="left" valign="top"><simpara>0.20</simpara></entry>
23035 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
23036 <entry align="left" valign="top"><simpara>0.08</simpara></entry>
23037 <entry align="left" valign="top"><simpara>0.05</simpara></entry>
23038 </row>
23039 <row>
23040 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tensor.sml"><literal>tensor.sml</literal></ulink></simpara></entry>
23041 <entry align="left" valign="top"><simpara>2.73</simpara></entry>
23042 <entry align="left" valign="top"><simpara>*</simpara></entry>
23043 <entry align="left" valign="top"><simpara>*</simpara></entry>
23044 <entry align="left" valign="top"><simpara>*</simpara></entry>
23045 <entry align="left" valign="top"><simpara>0.44</simpara></entry>
23046 </row>
23047 <row>
23048 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tsp.sml"><literal>tsp.sml</literal></ulink></simpara></entry>
23049 <entry align="left" valign="top"><simpara>2.42</simpara></entry>
23050 <entry align="left" valign="top"><simpara>0.38</simpara></entry>
23051 <entry align="left" valign="top"><simpara>0.05</simpara></entry>
23052 <entry align="left" valign="top"><simpara>0.11</simpara></entry>
23053 <entry align="left" valign="top"><simpara>0.11</simpara></entry>
23054 </row>
23055 <row>
23056 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/tyan.sml"><literal>tyan.sml</literal></ulink></simpara></entry>
23057 <entry align="left" valign="top"><simpara>2.93</simpara></entry>
23058 <entry align="left" valign="top"><simpara>*</simpara></entry>
23059 <entry align="left" valign="top"><simpara>0.10</simpara></entry>
23060 <entry align="left" valign="top"><simpara>0.27</simpara></entry>
23061 <entry align="left" valign="top"><simpara>0.31</simpara></entry>
23062 </row>
23063 <row>
23064 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vector32-concat.sml"><literal>vector32-concat.sml</literal></ulink></simpara></entry>
23065 <entry align="left" valign="top"><simpara>2.23</simpara></entry>
23066 <entry align="left" valign="top"><simpara>0.22</simpara></entry>
23067 <entry align="left" valign="top"><simpara>*</simpara></entry>
23068 <entry align="left" valign="top"><simpara>0.07</simpara></entry>
23069 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
23070 </row>
23071 <row>
23072 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vector64-concat.sml"><literal>vector64-concat.sml</literal></ulink></simpara></entry>
23073 <entry align="left" valign="top"><simpara>2.18</simpara></entry>
23074 <entry align="left" valign="top"><simpara>*</simpara></entry>
23075 <entry align="left" valign="top"><simpara>*</simpara></entry>
23076 <entry align="left" valign="top"><simpara>*</simpara></entry>
23077 <entry align="left" valign="top"><simpara>0.04</simpara></entry>
23078 </row>
23079 <row>
23080 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vector-rev.sml"><literal>vector-rev.sml</literal></ulink></simpara></entry>
23081 <entry align="left" valign="top"><simpara>2.23</simpara></entry>
23082 <entry align="left" valign="top"><simpara>0.22</simpara></entry>
23083 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
23084 <entry align="left" valign="top"><simpara>0.08</simpara></entry>
23085 <entry align="left" valign="top"><simpara>0.05</simpara></entry>
23086 </row>
23087 <row>
23088 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/vliw.sml"><literal>vliw.sml</literal></ulink></simpara></entry>
23089 <entry align="left" valign="top"><simpara>5.25</simpara></entry>
23090 <entry align="left" valign="top"><simpara>2.93</simpara></entry>
23091 <entry align="left" valign="top"><simpara>0.63</simpara></entry>
23092 <entry align="left" valign="top"><simpara>0.94</simpara></entry>
23093 <entry align="left" valign="top"><simpara>1.85</simpara></entry>
23094 </row>
23095 <row>
23096 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/wc-input1.sml"><literal>wc-input1.sml</literal></ulink></simpara></entry>
23097 <entry align="left" valign="top"><simpara>2.46</simpara></entry>
23098 <entry align="left" valign="top"><simpara>0.24</simpara></entry>
23099 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
23100 <entry align="left" valign="top"><simpara>0.08</simpara></entry>
23101 <entry align="left" valign="top"><simpara>0.05</simpara></entry>
23102 </row>
23103 <row>
23104 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/wc-scanStream.sml"><literal>wc-scanStream.sml</literal></ulink></simpara></entry>
23105 <entry align="left" valign="top"><simpara>2.61</simpara></entry>
23106 <entry align="left" valign="top"><simpara>0.25</simpara></entry>
23107 <entry align="left" valign="top"><simpara>0.01</simpara></entry>
23108 <entry align="left" valign="top"><simpara>0.08</simpara></entry>
23109 <entry align="left" valign="top"><simpara>0.05</simpara></entry>
23110 </row>
23111 <row>
23112 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/zebra.sml"><literal>zebra.sml</literal></ulink></simpara></entry>
23113 <entry align="left" valign="top"><simpara>2.99</simpara></entry>
23114 <entry align="left" valign="top"><simpara>0.35</simpara></entry>
23115 <entry align="left" valign="top"><simpara>0.03</simpara></entry>
23116 <entry align="left" valign="top"><simpara>0.09</simpara></entry>
23117 <entry align="left" valign="top"><simpara>0.11</simpara></entry>
23118 </row>
23119 <row>
23120 <entry align="left" valign="top"><simpara><ulink url="https://raw.github.com/MLton/mlton/master/benchmark/tests/zern.sml"><literal>zern.sml</literal></ulink></simpara></entry>
23121 <entry align="left" valign="top"><simpara>2.31</simpara></entry>
23122 <entry align="left" valign="top"><simpara>*</simpara></entry>
23123 <entry align="left" valign="top"><simpara>*</simpara></entry>
23124 <entry align="left" valign="top"><simpara>*</simpara></entry>
23125 <entry align="left" valign="top"><simpara>0.11</simpara></entry>
23126 </row>
23127 </tbody>
23128 </tgroup>
23129 </informaltable>
23130 <simpara><?asciidoc-pagebreak?></simpara>
23131 </section>
23132 </section>
23133 <section id="PhantomType">
23134 <title>PhantomType</title>
23135 <simpara>A phantom type is a type that has no run-time representation, but is
23136 used to force the type checker to ensure invariants at compile time.
23137 This is done by augmenting a type with additional arguments (phantom
23138 type variables) and expressing constraints by choosing phantom types
23139 to stand for the phantom types in the types of values.</simpara>
23140 <section id="_also_see_20">
23141 <title>Also see</title>
23142 <itemizedlist>
23143 <listitem>
23144 <simpara>
23145 <link linkend="References_Blume01">Blume01</link>
23146 </simpara>
23147 <itemizedlist>
23148 <listitem>
23149 <simpara>
23150 dimensions
23151 </simpara>
23152 </listitem>
23153 <listitem>
23154 <simpara>
23155 C type system
23156 </simpara>
23157 </listitem>
23158 </itemizedlist>
23159 </listitem>
23160 <listitem>
23161 <simpara>
23162 <link linkend="References_FluetPucella06">FluetPucella06</link>
23163 </simpara>
23164 <itemizedlist>
23165 <listitem>
23166 <simpara>
23167 subtyping
23168 </simpara>
23169 </listitem>
23170 </itemizedlist>
23171 </listitem>
23172 <listitem>
23173 <simpara>
23174 socket module in <link linkend="BasisLibrary">Basis Library</link>
23175 </simpara>
23176 </listitem>
23177 </itemizedlist>
23178 <simpara><?asciidoc-pagebreak?></simpara>
23179 </section>
23180 </section>
23181 <section id="PlatformSpecificNotes">
23182 <title>PlatformSpecificNotes</title>
23183 <simpara>Here are notes about using MLton on the following platforms.</simpara>
23184 <section id="_operating_systems">
23185 <title>Operating Systems</title>
23186 <itemizedlist>
23187 <listitem>
23188 <simpara>
23189 <link linkend="RunningOnAIX">AIX</link>
23190 </simpara>
23191 </listitem>
23192 <listitem>
23193 <simpara>
23194 <link linkend="RunningOnCygwin">Cygwin</link>
23195 </simpara>
23196 </listitem>
23197 <listitem>
23198 <simpara>
23199 <link linkend="RunningOnDarwin">Darwin</link>
23200 </simpara>
23201 </listitem>
23202 <listitem>
23203 <simpara>
23204 <link linkend="RunningOnFreeBSD">FreeBSD</link>
23205 </simpara>
23206 </listitem>
23207 <listitem>
23208 <simpara>
23209 <link linkend="RunningOnHPUX">HPUX</link>
23210 </simpara>
23211 </listitem>
23212 <listitem>
23213 <simpara>
23214 <link linkend="RunningOnLinux">Linux</link>
23215 </simpara>
23216 </listitem>
23217 <listitem>
23218 <simpara>
23219 <link linkend="RunningOnMinGW">MinGW</link>
23220 </simpara>
23221 </listitem>
23222 <listitem>
23223 <simpara>
23224 <link linkend="RunningOnNetBSD">NetBSD</link>
23225 </simpara>
23226 </listitem>
23227 <listitem>
23228 <simpara>
23229 <link linkend="RunningOnOpenBSD">OpenBSD</link>
23230 </simpara>
23231 </listitem>
23232 <listitem>
23233 <simpara>
23234 <link linkend="RunningOnSolaris">Solaris</link>
23235 </simpara>
23236 </listitem>
23237 </itemizedlist>
23238 </section>
23239 <section id="_architectures">
23240 <title>Architectures</title>
23241 <itemizedlist>
23242 <listitem>
23243 <simpara>
23244 <link linkend="RunningOnAMD64">AMD64</link>
23245 </simpara>
23246 </listitem>
23247 <listitem>
23248 <simpara>
23249 <link linkend="RunningOnHPPA">HPPA</link>
23250 </simpara>
23251 </listitem>
23252 <listitem>
23253 <simpara>
23254 <link linkend="RunningOnPowerPC">PowerPC</link>
23255 </simpara>
23256 </listitem>
23257 <listitem>
23258 <simpara>
23259 <link linkend="RunningOnPowerPC64">PowerPC64</link>
23260 </simpara>
23261 </listitem>
23262 <listitem>
23263 <simpara>
23264 <link linkend="RunningOnSparc">Sparc</link>
23265 </simpara>
23266 </listitem>
23267 <listitem>
23268 <simpara>
23269 <link linkend="RunningOnX86">X86</link>
23270 </simpara>
23271 </listitem>
23272 </itemizedlist>
23273 </section>
23274 <section id="_also_see_21">
23275 <title>Also see</title>
23276 <itemizedlist>
23277 <listitem>
23278 <simpara>
23279 <link linkend="PortingMLton">PortingMLton</link>
23280 </simpara>
23281 </listitem>
23282 </itemizedlist>
23283 <simpara><?asciidoc-pagebreak?></simpara>
23284 </section>
23285 </section>
23286 <section id="PolyEqual">
23287 <title>PolyEqual</title>
23288 <simpara><link linkend="PolyEqual">PolyEqual</link> is an optimization pass for the <link linkend="SSA">SSA</link>
23289 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
23290 <section id="_description_42">
23291 <title>Description</title>
23292 <simpara>This pass implements polymorphic equality.</simpara>
23293 </section>
23294 <section id="_implementation_45">
23295 <title>Implementation</title>
23296 <itemizedlist>
23297 <listitem>
23298 <simpara>
23299 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/poly-equal.fun"><literal>poly-equal.fun</literal></ulink>
23300 </simpara>
23301 </listitem>
23302 </itemizedlist>
23303 </section>
23304 <section id="_details_and_notes_45">
23305 <title>Details and Notes</title>
23306 <simpara>For each datatype, tycon, and vector type, it builds and equality
23307 function and translates calls to <literal>MLton_equal</literal> into calls to that
23308 function.</simpara>
23309 <simpara>Also generates calls to <literal>Word_equal</literal>.</simpara>
23310 <simpara>For tuples, it does the equality test inline; i.e., it does not create
23311 a separate equality function for each tuple type.</simpara>
23312 <simpara>All equality functions are created only if necessary, i.e., if
23313 equality is actually used at a type.</simpara>
23314 <simpara>Optimizations:</simpara>
23315 <itemizedlist>
23316 <listitem>
23317 <simpara>
23318 for datatypes that are enumerations, do not build a case dispatch,
23319 just use <literal>MLton_eq</literal>, as the backend will represent these as ints
23320 </simpara>
23321 </listitem>
23322 <listitem>
23323 <simpara>
23324 deep equality always does an <literal>MLton_eq</literal> test first
23325 </simpara>
23326 </listitem>
23327 <listitem>
23328 <simpara>
23329 If one argument to <literal>=</literal> is a constant and the type will get
23330 translated to an <literal>IntOrPointer</literal>, then just use <literal>eq</literal> instead of the
23331 full equality. This is important for implementing code like the
23332 following efficiently:
23333 </simpara>
23334 <screen>if x = 0 ... (* where x is of type IntInf.int *)</screen>
23335 </listitem>
23336 <listitem>
23337 <simpara>
23338 Also convert pointer equality on scalar types to type specific
23339 primitives.
23340 </simpara>
23341 </listitem>
23342 </itemizedlist>
23343 <simpara><?asciidoc-pagebreak?></simpara>
23344 </section>
23345 </section>
23346 <section id="PolyHash">
23347 <title>PolyHash</title>
23348 <simpara><link linkend="PolyHash">PolyHash</link> is an optimization pass for the <link linkend="SSA">SSA</link>
23349 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
23350 <section id="_description_43">
23351 <title>Description</title>
23352 <simpara>This pass implements polymorphic, structural hashing.</simpara>
23353 </section>
23354 <section id="_implementation_46">
23355 <title>Implementation</title>
23356 <itemizedlist>
23357 <listitem>
23358 <simpara>
23359 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/poly-hash.fun"><literal>poly-hash.fun</literal></ulink>
23360 </simpara>
23361 </listitem>
23362 </itemizedlist>
23363 </section>
23364 <section id="_details_and_notes_46">
23365 <title>Details and Notes</title>
23366 <simpara>For each datatype, tycon, and vector type, it builds and equality
23367 function and translates calls to <literal>MLton_hash</literal> into calls to that
23368 function.</simpara>
23369 <simpara>For tuples, it does the equality test inline; i.e., it does not create
23370 a separate equality function for each tuple type.</simpara>
23371 <simpara>All equality functions are created only if necessary, i.e., if
23372 equality is actually used at a type.</simpara>
23373 <simpara><?asciidoc-pagebreak?></simpara>
23374 </section>
23375 </section>
23376 <section id="PolyML">
23377 <title>PolyML</title>
23378 <simpara><ulink url="http://www.polyml.org/">Poly/ML</ulink> is a
23379 <link linkend="StandardMLImplementations">Standard ML implementation</link>.</simpara>
23380 <section id="_also_see_22">
23381 <title>Also see</title>
23382 <itemizedlist>
23383 <listitem>
23384 <simpara>
23385 <link linkend="References_Matthews95">Matthews95</link>
23386 </simpara>
23387 </listitem>
23388 </itemizedlist>
23389 <simpara><?asciidoc-pagebreak?></simpara>
23390 </section>
23391 </section>
23392 <section id="PolymorphicEquality">
23393 <title>PolymorphicEquality</title>
23394 <simpara>Polymorphic equality is a built-in function in
23395 <link linkend="StandardML">Standard ML</link> that compares two values of the same type
23396 for equality. It is specified as</simpara>
23397 <programlisting language="sml" linenumbering="unnumbered">val = : ''a * ''a -&gt; bool</programlisting>
23398 <simpara>The <literal>''a</literal> in the specification are
23399 <link linkend="EqualityTypeVariable">equality type variables</link>, and indicate that
23400 polymorphic equality can only be applied to values of an
23401 <link linkend="EqualityType">equality type</link>. It is not allowed in SML to rebind
23402 <literal>=</literal>, so a programmer is guaranteed that <literal>=</literal> always denotes polymorphic
23403 equality.</simpara>
23404 <section id="_equality_of_ground_types">
23405 <title>Equality of ground types</title>
23406 <simpara>Ground types like <literal>char</literal>, <literal>int</literal>, and <literal>word</literal> may be compared (to values
23407 of the same type). For example, <literal>13 = 14</literal> is type correct and yields
23408 <literal>false</literal>.</simpara>
23409 </section>
23410 <section id="_equality_of_reals">
23411 <title>Equality of reals</title>
23412 <simpara>The one ground type that can not be compared is <literal>real</literal>. So,
23413 <literal>13.0 = 14.0</literal> is not type correct. One can use <literal>Real.==</literal> to compare
23414 reals for equality, but beware that this has different algebraic
23415 properties than polymorphic equality.</simpara>
23416 <simpara>See <ulink url="http://standardml.org/Basis/real.html">http://standardml.org/Basis/real.html</ulink> for a discussion of why
23417 <literal>real</literal> is not an equality type.</simpara>
23418 </section>
23419 <section id="_equality_of_functions">
23420 <title>Equality of functions</title>
23421 <simpara>Comparison of functions is not allowed.</simpara>
23422 </section>
23423 <section id="_equality_of_immutable_types">
23424 <title>Equality of immutable types</title>
23425 <simpara>Polymorphic equality can be used on <link linkend="Immutable">immutable</link> values like
23426 tuples, records, lists, and vectors. For example,</simpara>
23427 <screen>(1, 2, 3) = (4, 5, 6)</screen>
23428 <simpara>is a type-correct expression yielding <literal>false</literal>, while</simpara>
23429 <screen>[1, 2, 3] = [1, 2, 3]</screen>
23430 <simpara>is type correct and yields <literal>true</literal>.</simpara>
23431 <simpara>Equality on immutable values is computed by structure, which means
23432 that values are compared by recursively descending the data structure
23433 until ground types are reached, at which point the ground types are
23434 compared with primitive equality tests (like comparison of
23435 characters). So, the expression</simpara>
23436 <screen>[1, 2, 3] = [1, 1 + 1, 1 + 1 + 1]</screen>
23437 <simpara>is guaranteed to yield <literal>true</literal>, even though the lists may occupy
23438 different locations in memory.</simpara>
23439 <simpara>Because of structural equality, immutable values can only be compared
23440 if their components can be compared. For example, <literal>[1, 2, 3]</literal> can be
23441 compared, but <literal>[1.0, 2.0, 3.0]</literal> can not. The SML type system uses
23442 <link linkend="EqualityType">equality types</link> to ensure that structural equality is
23443 only applied to valid values.</simpara>
23444 </section>
23445 <section id="_equality_of_mutable_values">
23446 <title>Equality of mutable values</title>
23447 <simpara>In contrast to immutable values, polymorphic equality of
23448 <link linkend="Mutable">mutable</link> values (like ref cells and arrays) is performed by
23449 pointer comparison, not by structure. So, the expression</simpara>
23450 <screen>ref 13 = ref 13</screen>
23451 <simpara>is guaranteed to yield <literal>false</literal>, even though the ref cells hold the
23452 same contents.</simpara>
23453 <simpara>Because equality of mutable values is not structural, arrays and refs
23454 can be compared <emphasis>even if their components are not equality types</emphasis>.
23455 Hence, the following expression is type correct (and yields true).</simpara>
23456 <programlisting language="sml" linenumbering="unnumbered">let
23457 val r = ref 13.0
23458 in
23459 r = r
23460 end</programlisting>
23461 </section>
23462 <section id="_equality_of_datatypes">
23463 <title>Equality of datatypes</title>
23464 <simpara>Polymorphic equality of datatypes is structural. Two values of the
23465 same datatype are equal if they are of the same <link linkend="Variant">variant</link> and
23466 if the <link linkend="Variant">variant</link>'s arguments are equal (recursively). So,
23467 with the datatype</simpara>
23468 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B of t</programlisting>
23469 <simpara>then <literal>B (B A) = B A</literal> is type correct and yields <literal>false</literal>, while <literal>A = A</literal>
23470 and <literal>B A = B A</literal> yield <literal>true</literal>.</simpara>
23471 <simpara>As polymorphic equality descends two values to compare them, it uses
23472 pointer equality whenever it reaches a mutable value. So, with the
23473 datatype</simpara>
23474 <programlisting language="sml" linenumbering="unnumbered">datatype t = A of int ref | ...</programlisting>
23475 <simpara>then <literal>A (ref 13) = A (ref 13)</literal> is type correct and yields <literal>false</literal>,
23476 because the pointer equality on the two ref cells yields <literal>false</literal>.</simpara>
23477 <simpara>One weakness of the SML type system is that datatypes do not inherit
23478 the special property of the <literal>ref</literal> and <literal>array</literal> type constructors that
23479 allows them to be compared regardless of their component type. For
23480 example, after declaring</simpara>
23481 <programlisting language="sml" linenumbering="unnumbered">datatype 'a t = A of 'a ref</programlisting>
23482 <simpara>one might expect to be able to compare two values of type <literal>real t</literal>,
23483 because pointer comparison on a ref cell would suffice.
23484 Unfortunately, the type system can only express that a user-defined
23485 datatype <link linkend="AdmitsEquality">admits equality</link> or not. In this case, <literal>t</literal>
23486 admits equality, which means that <literal>int t</literal> can be compared but that
23487 <literal>real t</literal> can not. We can confirm this with the program</simpara>
23488 <programlisting language="sml" linenumbering="unnumbered">datatype 'a t = A of 'a ref
23489 fun f (x: real t, y: real t) = x = y</programlisting>
23490 <simpara>on which MLton reports the following error.</simpara>
23491 <screen>Error: z.sml 2.32-2.36.
23492 Function applied to incorrect argument.
23493 expects: [&lt;equality&gt;] t * [&lt;equality&gt;] t
23494 but got: [real] t * [real] t
23495 in: = (x, y)</screen>
23496 </section>
23497 <section id="_implementation_47">
23498 <title>Implementation</title>
23499 <simpara>Polymorphic equality is implemented by recursively descending the two
23500 values being compared, stopping as soon as they are determined to be
23501 unequal, or exploring the entire values to determine that they are
23502 equal. Hence, polymorphic equality can take time proportional to the
23503 size of the smaller value.</simpara>
23504 <simpara>MLton uses some optimizations to improve performance.</simpara>
23505 <itemizedlist>
23506 <listitem>
23507 <simpara>
23508 When computing structural equality, first do a pointer comparison.
23509 If the comparison yields <literal>true</literal>, then stop and return <literal>true</literal>, since
23510 the structural comparison is guaranteed to do so. If the pointer
23511 comparison fails, then recursively descend the values.
23512 </simpara>
23513 </listitem>
23514 <listitem>
23515 <simpara>
23516 If a datatype is an enum (e.g. <literal>datatype t = A | B | C</literal>), then a
23517 single comparison suffices to compare values of the datatype. No case
23518 dispatch is required to determine whether the two values are of the
23519 same <link linkend="Variant">variant</link>.
23520 </simpara>
23521 </listitem>
23522 <listitem>
23523 <simpara>
23524 When comparing a known constant non-value-carrying
23525 <link linkend="Variant">variant</link>, use a single comparison. For example, the
23526 following code will compile into a single comparison for <literal>A = x</literal>.
23527 </simpara>
23528 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B | C of ...
23529 fun f x = ... if A = x then ...</programlisting>
23530 </listitem>
23531 <listitem>
23532 <simpara>
23533 When comparing a small constant <literal>IntInf.int</literal> to another
23534 <literal>IntInf.int</literal>, use a single comparison against the constant. No case
23535 dispatch is required.
23536 </simpara>
23537 </listitem>
23538 </itemizedlist>
23539 </section>
23540 <section id="_also_see_23">
23541 <title>Also see</title>
23542 <itemizedlist>
23543 <listitem>
23544 <simpara>
23545 <link linkend="AdmitsEquality">AdmitsEquality</link>
23546 </simpara>
23547 </listitem>
23548 <listitem>
23549 <simpara>
23550 <link linkend="EqualityType">EqualityType</link>
23551 </simpara>
23552 </listitem>
23553 <listitem>
23554 <simpara>
23555 <link linkend="EqualityTypeVariable">EqualityTypeVariable</link>
23556 </simpara>
23557 </listitem>
23558 </itemizedlist>
23559 <simpara><?asciidoc-pagebreak?></simpara>
23560 </section>
23561 </section>
23562 <section id="Polyvariance">
23563 <title>Polyvariance</title>
23564 <simpara>Polyvariance is an optimization pass for the <link linkend="SXML">SXML</link>
23565 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SXMLSimplify">SXMLSimplify</link>.</simpara>
23566 <section id="_description_44">
23567 <title>Description</title>
23568 <simpara>This pass duplicates a higher-order, <literal>let</literal> bound function at each
23569 variable reference, if the cost is smaller than some threshold.</simpara>
23570 </section>
23571 <section id="_implementation_48">
23572 <title>Implementation</title>
23573 <itemizedlist>
23574 <listitem>
23575 <simpara>
23576 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/polyvariance.fun"><literal>polyvariance.fun</literal></ulink>
23577 </simpara>
23578 </listitem>
23579 </itemizedlist>
23580 </section>
23581 <section id="_details_and_notes_47">
23582 <title>Details and Notes</title>
23583 <simpara></simpara>
23584 <simpara><?asciidoc-pagebreak?></simpara>
23585 </section>
23586 </section>
23587 <section id="Poplog">
23588 <title>Poplog</title>
23589 <simpara><ulink url="http://www.cs.bham.ac.uk/research/poplog/poplog.info.html">POPLOG</ulink> is a
23590 development environment that includes implementations of a number of
23591 languages, including <link linkend="StandardML">Standard ML</link>.</simpara>
23592 <simpara>While POPLOG is actively developed, the <link linkend="ML">ML</link> support predates
23593 <link linkend="DefinitionOfStandardML">SML&#8217;97</link>, and there is no support for the
23594 <link linkend="BasisLibrary">Basis Library</link>
23595 <ulink url="http://www.standardml.org/Basis">specification</ulink>.</simpara>
23596 <section id="_also_see_24">
23597 <title>Also see</title>
23598 <itemizedlist>
23599 <listitem>
23600 <simpara>
23601 <ulink url="http://www.cs.bham.ac.uk/research/poplog/doc/pmlhelp/mlinpop">Mixed-language programming in ML and Pop-11</ulink>.
23602 </simpara>
23603 </listitem>
23604 </itemizedlist>
23605 <simpara><?asciidoc-pagebreak?></simpara>
23606 </section>
23607 </section>
23608 <section id="PortingMLton">
23609 <title>PortingMLton</title>
23610 <simpara>Porting MLton to a new target platform (architecture or OS) involves
23611 the following steps.</simpara>
23612 <orderedlist numeration="arabic">
23613 <listitem>
23614 <simpara>
23615 Make the necessary changes to the scripts, runtime system,
23616 <link linkend="BasisLibrary">Basis Library</link> implementation, and compiler.
23617 </simpara>
23618 </listitem>
23619 <listitem>
23620 <simpara>
23621 Get the regressions working using a cross compiler.
23622 </simpara>
23623 </listitem>
23624 <listitem>
23625 <simpara>
23626 <link linkend="CrossCompiling">Cross compile</link> MLton and bootstrap on the target.
23627 </simpara>
23628 </listitem>
23629 </orderedlist>
23630 <simpara>MLton has a native code generator only for AMD64 and X86, so, if you
23631 are porting to another architecture, you must use the C code
23632 generator. These notes do not cover building a new native code
23633 generator.</simpara>
23634 <simpara>Some of the following steps will not be necessary if MLton already
23635 supports the architecture or operating system you are porting to.</simpara>
23636 <section id="_what_code_to_change">
23637 <title>What code to change</title>
23638 <itemizedlist>
23639 <listitem>
23640 <simpara>
23641 Scripts.
23642 </simpara>
23643 <itemizedlist>
23644 <listitem>
23645 <simpara>
23646 In <literal>bin/platform</literal>, add new cases to define <literal>$HOST_OS</literal> and <literal>$HOST_ARCH</literal>.
23647 </simpara>
23648 </listitem>
23649 </itemizedlist>
23650 </listitem>
23651 <listitem>
23652 <simpara>
23653 Runtime system.
23654 </simpara>
23655 <simpara>The goal of this step is to be able to successfully run <literal>make</literal> in the
23656 <literal>runtime</literal> directory on the target machine.</simpara>
23657 <itemizedlist>
23658 <listitem>
23659 <simpara>
23660 In <literal>platform.h</literal>, add a new case to include <literal>platform/&lt;arch&gt;.h</literal> and <literal>platform/&lt;os&gt;.h</literal>.
23661 </simpara>
23662 </listitem>
23663 <listitem>
23664 <simpara>
23665 In <literal>platform/&lt;arch&gt;.h</literal>:
23666 </simpara>
23667 <itemizedlist>
23668 <listitem>
23669 <simpara>
23670 define <literal>MLton_Platform_Arch_host</literal>.
23671 </simpara>
23672 </listitem>
23673 </itemizedlist>
23674 </listitem>
23675 <listitem>
23676 <simpara>
23677 In <literal>platform/&lt;os&gt;.h</literal>:
23678 </simpara>
23679 <itemizedlist>
23680 <listitem>
23681 <simpara>
23682 include platform-specific includes.
23683 </simpara>
23684 </listitem>
23685 <listitem>
23686 <simpara>
23687 define <literal>MLton_Platform_OS_host</literal>.
23688 </simpara>
23689 </listitem>
23690 <listitem>
23691 <simpara>
23692 define all of the <literal>HAS_*</literal> macros.
23693 </simpara>
23694 </listitem>
23695 </itemizedlist>
23696 </listitem>
23697 <listitem>
23698 <simpara>
23699 In <literal>platform/&lt;os&gt;.c</literal> implement any platform-dependent functions that the runtime needs.
23700 </simpara>
23701 </listitem>
23702 <listitem>
23703 <simpara>
23704 Add rounding mode control to <literal>basis/Real/IEEEReal.c</literal> for the new arch (if not <literal>HAS_FEROUND</literal>)
23705 </simpara>
23706 </listitem>
23707 <listitem>
23708 <simpara>
23709 Compile and install the <link linkend="GnuMP">GnuMP</link>. This varies from platform to platform. In <literal>platform/&lt;os&gt;.h</literal>, you need to include the appropriate <literal>gmp.h</literal>.
23710 </simpara>
23711 </listitem>
23712 </itemizedlist>
23713 </listitem>
23714 <listitem>
23715 <simpara>
23716 Basis Library implementation (<literal>basis-library/*</literal>)
23717 </simpara>
23718 <itemizedlist>
23719 <listitem>
23720 <simpara>
23721 In <literal>primitive/prim-mlton.sml</literal>:
23722 </simpara>
23723 <itemizedlist>
23724 <listitem>
23725 <simpara>
23726 Add a new variant to the <literal>MLton.Platform.Arch.t</literal> datatype.
23727 </simpara>
23728 </listitem>
23729 <listitem>
23730 <simpara>
23731 modify the constants that define <literal>MLton.Platform.Arch.host</literal> to match with <literal>MLton_Platform_Arch_host</literal>, as set in <literal>runtime/platform/&lt;arch&gt;.h</literal>.
23732 </simpara>
23733 </listitem>
23734 <listitem>
23735 <simpara>
23736 Add a new variant to the <literal>MLton.Platform.OS.t</literal> datatype.
23737 </simpara>
23738 </listitem>
23739 <listitem>
23740 <simpara>
23741 modify the constants that define <literal>MLton.Platform.OS.host</literal> to match with <literal>MLton_Platform_OS_host</literal>, as set in <literal>runtime/platform/&lt;os&gt;.h</literal>.
23742 </simpara>
23743 </listitem>
23744 </itemizedlist>
23745 </listitem>
23746 <listitem>
23747 <simpara>
23748 In <literal>mlton/platform.{sig,sml}</literal> add a new variant.
23749 </simpara>
23750 </listitem>
23751 <listitem>
23752 <simpara>
23753 In <literal>sml-nj/sml-nj.sml</literal>, modify <literal>getOSKind</literal>.
23754 </simpara>
23755 </listitem>
23756 <listitem>
23757 <simpara>
23758 Look at all the uses of <literal>MLton.Platform</literal> in the Basis Library implementation and see if you need to do anything special. You might use the following command to see where to look.
23759 </simpara>
23760 <screen>find basis-library -type f | xargs grep 'MLton\.Platform'</screen>
23761 <simpara>If in doubt, leave the code alone and wait to see what happens when you run the regression tests.</simpara>
23762 </listitem>
23763 </itemizedlist>
23764 </listitem>
23765 <listitem>
23766 <simpara>
23767 Compiler.
23768 </simpara>
23769 <itemizedlist>
23770 <listitem>
23771 <simpara>
23772 In <literal>lib/stubs/mlton-stubs/platform.sig</literal> add any new variants, as was done in the Basis Library.
23773 </simpara>
23774 </listitem>
23775 <listitem>
23776 <simpara>
23777 In <literal>lib/stubs/mlton-stubs/mlton.sml</literal> add any new variants in <literal>MLton.Platform</literal>, as was done in the Basis Library.
23778 </simpara>
23779 </listitem>
23780 </itemizedlist>
23781 </listitem>
23782 </itemizedlist>
23783 <simpara>The string used to identify a particular architecture or operating
23784 system must be the same (except for possibly case of letters) in the
23785 scripts, runtime, Basis Library implementation, and compiler (stubs).
23786 In <literal>mlton/main/main.fun</literal>, MLton itself uses the conversions to and
23787 from strings:</simpara>
23788 <screen>MLton.Platform.{Arch,OS}.{from,to}String</screen>
23789 <simpara>If the there is a mismatch, you may see the error message
23790 <literal>strange arch</literal> or <literal>strange os</literal>.</simpara>
23791 </section>
23792 <section id="_running_the_regressions_with_a_cross_compiler">
23793 <title>Running the regressions with a cross compiler</title>
23794 <simpara>When porting to a new platform, it is always best to get all (or as
23795 many as possible) of the regressions working before moving to a self
23796 compile. It is easiest to do this by modifying and rebuilding the
23797 compiler on a working machine and then running the regressions with a
23798 cross compiler. It is not easy to build a gcc cross compiler, so we
23799 recommend generating the C and assembly on a working machine (using
23800 MLton&#8217;s <literal>-target</literal> and <literal>-stop g</literal> flags, copying the generated files to
23801 the target machine, then compiling and linking there.</simpara>
23802 <orderedlist numeration="arabic">
23803 <listitem>
23804 <simpara>
23805 Remake the compiler on a working machine.
23806 </simpara>
23807 </listitem>
23808 <listitem>
23809 <simpara>
23810 Use <literal>bin/add-cross</literal> to add support for the new target. In particular, this should create <literal>build/lib/mlton/targets/&lt;target&gt;/</literal> with the platform-specific necessary cross-compilation information.
23811 </simpara>
23812 </listitem>
23813 <listitem>
23814 <simpara>
23815 Run the regression tests with the cross-compiler. To cross-compile all the tests, do
23816 </simpara>
23817 <screen>bin/regression -cross &lt;target&gt;</screen>
23818 <simpara>This will create all the executables. Then, copy <literal>bin/regression</literal> and
23819 the <literal>regression</literal> directory to the target machine, and do</simpara>
23820 <screen>bin/regression -run-only &lt;target&gt;</screen>
23821 <simpara>This should run all the tests.</simpara>
23822 </listitem>
23823 </orderedlist>
23824 <simpara>Repeat this step, interleaved with appropriate compiler modifications,
23825 until all the regressions pass.</simpara>
23826 </section>
23827 <section id="_bootstrap">
23828 <title>Bootstrap</title>
23829 <simpara>Once you&#8217;ve got all the regressions working, you can build MLton for
23830 the new target. As with the regressions, the idea for bootstrapping
23831 is to generate the C and assembly on a working machine, copy it to the
23832 target machine, and then compile and link there. Here&#8217;s the sequence
23833 of steps.</simpara>
23834 <orderedlist numeration="arabic">
23835 <listitem>
23836 <simpara>
23837 On a working machine, with the newly rebuilt compiler, in the <literal>mlton</literal> directory, do:
23838 </simpara>
23839 <screen>mlton -stop g -target &lt;target&gt; mlton.mlb</screen>
23840 </listitem>
23841 <listitem>
23842 <simpara>
23843 Copy to the target machine.
23844 </simpara>
23845 </listitem>
23846 <listitem>
23847 <simpara>
23848 On the target machine, move the libraries to the right place. That is, in <literal>build/lib/mlton/targets</literal>, do:
23849 </simpara>
23850 <screen>rm -rf self
23851 mv &lt;target&gt; self</screen>
23852 <simpara>Also make sure you have all the header files in build/lib/mlton/include. You can copy them from a host machine that has run <literal>make runtime</literal>.</simpara>
23853 </listitem>
23854 <listitem>
23855 <simpara>
23856 On the target machine, compile and link MLton. That is, in the mlton directory, do something like:
23857 </simpara>
23858 <screen>gcc -c -Ibuild/lib/mlton/include -Ibuild/lib/mlton/targets/self/include -O1 -w mlton/mlton.*.[cs]
23859 gcc -o build/lib/mlton/mlton-compile \
23860 -Lbuild/lib/mlton/targets/self \
23861 -L/usr/local/lib \
23862 mlton.*.o \
23863 -lmlton -lgmp -lgdtoa -lm</screen>
23864 </listitem>
23865 <listitem>
23866 <simpara>
23867 At this point, MLton should be working and you can finish the rest of a usual make on the target machine.
23868 </simpara>
23869 <screen>make basis-no-check script mlbpathmap constants libraries tools</screen>
23870 </listitem>
23871 <listitem>
23872 <simpara>
23873 Making the last tool, mlyacc, will fail, because mlyacc cannot bootstrap its own yacc.grm.* files. On the host machine, run <literal>make -C mlyacc src/yacc.grm.sml</literal>. Then copy both files to the target machine, and compile mlyacc, making sure to supply the path to your newly compile mllex: <literal>make -C mlyacc MLLEX=mllex/mllex</literal>.
23874 </simpara>
23875 </listitem>
23876 </orderedlist>
23877 <simpara>There are other details to get right, like making sure that the tools
23878 directories were clean so that the tools are rebuilt on the new
23879 platform, but hopefully this structure works. Once you&#8217;ve got a
23880 compiler on the target machine, you should test it by running all the
23881 regressions normally (i.e. without the <literal>-cross</literal> flag) and by running a
23882 couple rounds of self compiles.</simpara>
23883 </section>
23884 <section id="_also_see_25">
23885 <title>Also see</title>
23886 <simpara>The above description is based on the following emails sent to the
23887 MLton list.</simpara>
23888 <itemizedlist>
23889 <listitem>
23890 <simpara>
23891 <ulink url="http://www.mlton.org/pipermail/mlton/2002-October/013110.html">http://www.mlton.org/pipermail/mlton/2002-October/013110.html</ulink>
23892 </simpara>
23893 </listitem>
23894 <listitem>
23895 <simpara>
23896 <ulink url="http://www.mlton.org/pipermail/mlton/2004-July/016029.html">http://www.mlton.org/pipermail/mlton/2004-July/016029.html</ulink>
23897 </simpara>
23898 </listitem>
23899 </itemizedlist>
23900 <simpara><?asciidoc-pagebreak?></simpara>
23901 </section>
23902 </section>
23903 <section id="PrecedenceParse">
23904 <title>PrecedenceParse</title>
23905 <simpara><link linkend="PrecedenceParse">PrecedenceParse</link> is an analysis/rewrite pass for the <link linkend="AST">AST</link>
23906 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="Elaborate">Elaborate</link>.</simpara>
23907 <section id="_description_45">
23908 <title>Description</title>
23909 <simpara>This pass rewrites <link linkend="AST">AST</link> function clauses, expressions, and patterns
23910 to resolve <link linkend="OperatorPrecedence">OperatorPrecedence</link>.</simpara>
23911 </section>
23912 <section id="_implementation_49">
23913 <title>Implementation</title>
23914 <itemizedlist>
23915 <listitem>
23916 <simpara>
23917 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/precedence-parse.sig"><literal>precedence-parse.sig</literal></ulink>
23918 </simpara>
23919 </listitem>
23920 <listitem>
23921 <simpara>
23922 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/precedence-parse.fun"><literal>precedence-parse.fun</literal></ulink>
23923 </simpara>
23924 </listitem>
23925 </itemizedlist>
23926 </section>
23927 <section id="_details_and_notes_48">
23928 <title>Details and Notes</title>
23929 <simpara></simpara>
23930 <simpara><?asciidoc-pagebreak?></simpara>
23931 </section>
23932 </section>
23933 <section id="Printf">
23934 <title>Printf</title>
23935 <simpara>Programmers coming from C or Java often ask if
23936 <link linkend="StandardML">Standard ML</link> has a <literal>printf</literal> function. It does not.
23937 However, it is possible to implement your own version with only a few
23938 lines of code.</simpara>
23939 <simpara>Here is a definition for <literal>printf</literal> and <literal>fprintf</literal>, along with format
23940 specifiers for booleans, integers, and reals.</simpara>
23941 <programlisting language="sml" linenumbering="unnumbered">structure Printf =
23942 struct
23943 fun $ (_, f) = f (fn p =&gt; p ()) ignore
23944 fun fprintf out f = f (out, id)
23945 val printf = fn z =&gt; fprintf TextIO.stdOut z
23946 fun one ((out, f), make) g =
23947 g (out, fn r =&gt;
23948 f (fn p =&gt;
23949 make (fn s =&gt;
23950 r (fn () =&gt; (p (); TextIO.output (out, s))))))
23951 fun ` x s = one (x, fn f =&gt; f s)
23952 fun spec to x = one (x, fn f =&gt; f o to)
23953 val B = fn z =&gt; spec Bool.toString z
23954 val I = fn z =&gt; spec Int.toString z
23955 val R = fn z =&gt; spec Real.toString z
23956 end</programlisting>
23957 <simpara>Here&#8217;s an example use.</simpara>
23958 <programlisting language="sml" linenumbering="unnumbered">val () = printf `"Int="I`" Bool="B`" Real="R`"\n" $ 1 false 2.0</programlisting>
23959 <simpara>This prints the following.</simpara>
23960 <screen>Int=1 Bool=false Real=2.0</screen>
23961 <simpara>In general, a use of <literal>printf</literal> looks like</simpara>
23962 <screen>printf &lt;spec1&gt; ... &lt;specn&gt; $ &lt;arg1&gt; ... &lt;argm&gt;</screen>
23963 <simpara>where each <literal>&lt;speci&gt;</literal> is either a specifier like <literal>B</literal>, <literal>I</literal>, or <literal>R</literal>, or
23964 is an inline string, like <literal>&grave;"foo"</literal>. A backtick (<literal>&grave;</literal>)
23965 must precede each inline string. Each <literal>&lt;argi&gt;</literal> must be of the
23966 appropriate type for the corresponding specifier.</simpara>
23967 <simpara>SML <literal>printf</literal> is more powerful than its C counterpart in a number of
23968 ways. In particular, the function produced by <literal>printf</literal> is a perfectly
23969 ordinary SML function, and can be passed around, used multiple times,
23970 etc. For example:</simpara>
23971 <programlisting language="sml" linenumbering="unnumbered">val f: int -&gt; bool -&gt; unit = printf `"Int="I`" Bool="B`"\n" $
23972 val () = f 1 true
23973 val () = f 2 false</programlisting>
23974 <simpara>The definition of <literal>printf</literal> is even careful to not print anything until
23975 it is fully applied. So, examples like the following will work as
23976 expected.</simpara>
23977 <screen>val f: int -&gt; bool -&gt; unit = printf `"Int="I`" Bool="B`"\n" $ 13
23978 val () = f true
23979 val () = f false</screen>
23980 <simpara>It is also easy to define new format specifiers. For example, suppose
23981 we wanted format specifiers for characters and strings.</simpara>
23982 <screen>val C = fn z =&gt; spec Char.toString z
23983 val S = fn z =&gt; spec (fn s =&gt; s) z</screen>
23984 <simpara>One can define format specifiers for more complex types, e.g. pairs of
23985 integers.</simpara>
23986 <screen>val I2 =
23987 fn z =&gt;
23988 spec (fn (i, j) =&gt;
23989 concat ["(", Int.toString i, ", ", Int.toString j, ")"])
23990 z</screen>
23991 <simpara>Here&#8217;s an example use.</simpara>
23992 <screen>val () = printf `"Test "I2`" a string "S`"\n" $ (1, 2) "hello"</screen>
23993 <section id="_printf_via_link_linkend_fold_fold_link">
23994 <title>Printf via <link linkend="Fold">Fold</link></title>
23995 <simpara><literal>printf</literal> is best viewed as a special case of variable-argument
23996 <link linkend="Fold">Fold</link> that inductively builds a function as it processes its
23997 arguments. Here is the definition of a <literal>Printf</literal> structure in terms of
23998 fold. The structure is equivalent to the above one, except that it
23999 uses the standard <literal>$</literal> instead of a specialized one.</simpara>
24000 <programlisting language="sml" linenumbering="unnumbered">structure Printf =
24001 struct
24002 fun fprintf out =
24003 Fold.fold ((out, id), fn (_, f) =&gt; f (fn p =&gt; p ()) ignore)
24004
24005 val printf = fn z =&gt; fprintf TextIO.stdOut z
24006
24007 fun one ((out, f), make) =
24008 (out, fn r =&gt;
24009 f (fn p =&gt;
24010 make (fn s =&gt;
24011 r (fn () =&gt; (p (); TextIO.output (out, s))))))
24012
24013 val ` =
24014 fn z =&gt; Fold.step1 (fn (s, x) =&gt; one (x, fn f =&gt; f s)) z
24015
24016 fun spec to = Fold.step0 (fn x =&gt; one (x, fn f =&gt; f o to))
24017
24018 val B = fn z =&gt; spec Bool.toString z
24019 val I = fn z =&gt; spec Int.toString z
24020 val R = fn z =&gt; spec Real.toString z
24021 end</programlisting>
24022 <simpara>Viewing <literal>printf</literal> as a fold opens up a number of possibilities. For
24023 example, one can name parts of format strings using the fold idiom for
24024 naming sequences of steps.</simpara>
24025 <screen>val IB = fn u =&gt; Fold.fold u `"Int="I`" Bool="B
24026 val () = printf IB`" "IB`"\n" $ 1 true 3 false</screen>
24027 <simpara>One can even parametrize over partial format strings.</simpara>
24028 <screen>fun XB X = fn u =&gt; Fold.fold u `"X="X`" Bool="B
24029 val () = printf (XB I)`" "(XB R)`"\n" $ 1 true 2.0 false</screen>
24030 </section>
24031 <section id="_also_see_26">
24032 <title>Also see</title>
24033 <itemizedlist>
24034 <listitem>
24035 <simpara>
24036 <link linkend="PrintfGentle">PrintfGentle</link>
24037 </simpara>
24038 </listitem>
24039 <listitem>
24040 <simpara>
24041 <link linkend="References_Danvy98">Functional Unparsing</link>
24042 </simpara>
24043 </listitem>
24044 </itemizedlist>
24045 <simpara><?asciidoc-pagebreak?></simpara>
24046 </section>
24047 </section>
24048 <section id="PrintfGentle">
24049 <title>PrintfGentle</title>
24050 <simpara>This page provides a gentle introduction and derivation of <link linkend="Printf">Printf</link>,
24051 with sections and arrangement more suitable to a talk.</simpara>
24052 <section id="_introduction">
24053 <title>Introduction</title>
24054 <simpara>SML does not have <literal>printf</literal>. Could we define it ourselves?</simpara>
24055 <programlisting language="sml" linenumbering="unnumbered">val () = printf ("here's an int %d and a real %f.\n", 13, 17.0)
24056 val () = printf ("here's three values (%d, %f, %f).\n", 13, 17.0, 19.0)</programlisting>
24057 <simpara>What could the type of <literal>printf</literal> be?</simpara>
24058 <simpara>This obviously can&#8217;t work, because SML functions take a fixed number
24059 of arguments. Actually they take one argument, but if that&#8217;s a tuple,
24060 it can only have a fixed number of components.</simpara>
24061 </section>
24062 <section id="_from_tupling_to_currying">
24063 <title>From tupling to currying</title>
24064 <simpara>What about currying to get around the typing problem?</simpara>
24065 <programlisting language="sml" linenumbering="unnumbered">val () = printf "here's an int %d and a real %f.\n" 13 17.0
24066 val () = printf "here's three values (%d, %f, %f).\n" 13 17.0 19.0</programlisting>
24067 <simpara>That fails for a similar reason. We need two types for <literal>printf</literal>.</simpara>
24068 <screen>val printf: string -&gt; int -&gt; real -&gt; unit
24069 val printf: string -&gt; int -&gt; real -&gt; real -&gt; unit</screen>
24070 <simpara>This can&#8217;t work, because <literal>printf</literal> can only have one type. SML doesn&#8217;t
24071 support programmer-defined overloading.</simpara>
24072 </section>
24073 <section id="_overloading_and_dependent_types">
24074 <title>Overloading and dependent types</title>
24075 <simpara>Even without worrying about number of arguments, there is another
24076 problem. The type of <literal>printf</literal> depends on the format string.</simpara>
24077 <programlisting language="sml" linenumbering="unnumbered">val () = printf "here's an int %d and a real %f.\n" 13 17.0
24078 val () = printf "here's a real %f and an int %d.\n" 17.0 13</programlisting>
24079 <simpara>Now we need</simpara>
24080 <screen>val printf: string -&gt; int -&gt; real -&gt; unit
24081 val printf: string -&gt; real -&gt; int -&gt; unit</screen>
24082 <simpara>Again, this can&#8217;t possibly working because SML doesn&#8217;t have
24083 overloading, and types can&#8217;t depend on values.</simpara>
24084 </section>
24085 <section id="_idea_express_type_information_in_the_format_string">
24086 <title>Idea: express type information in the format string</title>
24087 <simpara>If we express type information in the format string, then different
24088 uses of <literal>printf</literal> can have different types.</simpara>
24089 <programlisting language="sml" linenumbering="unnumbered">type 'a t (* the type of format strings *)
24090 val printf: 'a t -&gt; 'a
24091 infix D F
24092 val fs1: (int -&gt; real -&gt; unit) t = "here's an int "D" and a real "F".\n"
24093 val fs2: (int -&gt; real -&gt; real -&gt; unit) t =
24094 "here's three values ("D", "F", "F").\n"
24095 val () = printf fs1 13 17.0
24096 val () = printf fs2 13 17.0 19.0</programlisting>
24097 <simpara>Now, our two calls to <literal>printf</literal> type check, because the format
24098 string specializes <literal>printf</literal> to the appropriate type.</simpara>
24099 </section>
24100 <section id="_the_types_of_format_characters">
24101 <title>The types of format characters</title>
24102 <simpara>What should the type of format characters <literal>D</literal> and <literal>F</literal> be? Each format
24103 character requires an additional argument of the appropriate type to
24104 be supplied to <literal>printf</literal>.</simpara>
24105 <simpara>Idea: guess the final type that will be needed for <literal>printf</literal> the format
24106 string and verify it with each format character.</simpara>
24107 <programlisting language="sml" linenumbering="unnumbered">type ('a, 'b) t (* 'a = rest of type to verify, 'b = final type *)
24108 val ` : string -&gt; ('a, 'a) t (* guess the type, which must be verified *)
24109 val D: (int -&gt; 'a, 'b) t * string -&gt; ('a, 'b) t (* consume an int *)
24110 val F: (real -&gt; 'a, 'b) t * string -&gt; ('a, 'b) t (* consume a real *)
24111 val printf: (unit, 'a) t -&gt; 'a</programlisting>
24112 <simpara>Don&#8217;t worry. In the end, type inference will guess and verify for us.</simpara>
24113 </section>
24114 <section id="_understanding_guess_and_verify">
24115 <title>Understanding guess and verify</title>
24116 <simpara>Now, let&#8217;s build up a format string and a specialized <literal>printf</literal>.</simpara>
24117 <programlisting language="sml" linenumbering="unnumbered">infix D F
24118 val f0 = `"here's an int "
24119 val f1 = f0 D " and a real "
24120 val f2 = f1 F ".\n"
24121 val p = printf f2</programlisting>
24122 <simpara>These definitions yield the following types.</simpara>
24123 <programlisting language="sml" linenumbering="unnumbered">val f0: (int -&gt; real -&gt; unit, int -&gt; real -&gt; unit) t
24124 val f1: (real -&gt; unit, int -&gt; real -&gt; unit) t
24125 val f2: (unit, int -&gt; real -&gt; unit) t
24126 val p: int -&gt; real -&gt; unit</programlisting>
24127 <simpara>So, <literal>p</literal> is a specialized <literal>printf</literal> function. We could use it as
24128 follows</simpara>
24129 <programlisting language="sml" linenumbering="unnumbered">val () = p 13 17.0
24130 val () = p 14 19.0</programlisting>
24131 </section>
24132 <section id="_type_checking_this_using_a_functor">
24133 <title>Type checking this using a functor</title>
24134 <programlisting language="sml" linenumbering="unnumbered">signature PRINTF =
24135 sig
24136 type ('a, 'b) t
24137 val ` : string -&gt; ('a, 'a) t
24138 val D: (int -&gt; 'a, 'b) t * string -&gt; ('a, 'b) t
24139 val F: (real -&gt; 'a, 'b) t * string -&gt; ('a, 'b) t
24140 val printf: (unit, 'a) t -&gt; 'a
24141 end
24142
24143 functor Test (P: PRINTF) =
24144 struct
24145 open P
24146 infix D F
24147
24148 val () = printf (`"here's an int "D" and a real "F".\n") 13 17.0
24149 val () = printf (`"here's three values ("D", "F ", "F").\n") 13 17.0 19.0
24150 end</programlisting>
24151 </section>
24152 <section id="_implementing_literal_printf_literal">
24153 <title>Implementing <literal>Printf</literal></title>
24154 <simpara>Think of a format character as a formatter transformer. It takes the
24155 formatter for the part of the format string before it and transforms
24156 it into a new formatter that first does the left hand bit, then does
24157 its bit, then continues on with the rest of the format string.</simpara>
24158 <programlisting language="sml" linenumbering="unnumbered">structure Printf: PRINTF =
24159 struct
24160 datatype ('a, 'b) t = T of (unit -&gt; 'a) -&gt; 'b
24161
24162 fun printf (T f) = f (fn () =&gt; ())
24163
24164 fun ` s = T (fn a =&gt; (print s; a ()))
24165
24166 fun D (T f, s) =
24167 T (fn g =&gt; f (fn () =&gt; fn i =&gt;
24168 (print (Int.toString i); print s; g ())))
24169
24170 fun F (T f, s) =
24171 T (fn g =&gt; f (fn () =&gt; fn i =&gt;
24172 (print (Real.toString i); print s; g ())))
24173 end</programlisting>
24174 </section>
24175 <section id="_testing_printf">
24176 <title>Testing printf</title>
24177 <programlisting language="sml" linenumbering="unnumbered">structure Z = Test (Printf)</programlisting>
24178 </section>
24179 <section id="_user_definable_formats">
24180 <title>User-definable formats</title>
24181 <simpara>The definition of the format characters is pretty much the same.
24182 Within the <literal>Printf</literal> structure we can define a format character
24183 generator.</simpara>
24184 <programlisting language="sml" linenumbering="unnumbered">val newFormat: ('a -&gt; string) -&gt; ('a -&gt; 'b, 'c) t * string -&gt; ('b, 'c) t =
24185 fn toString =&gt; fn (T f, s) =&gt;
24186 T (fn th =&gt; f (fn () =&gt; fn a =&gt; (print (toString a); print s ; th ())))
24187 val D = fn z =&gt; newFormat Int.toString z
24188 val F = fn z =&gt; newFormat Real.toString z</programlisting>
24189 </section>
24190 <section id="_a_core_literal_printf_literal">
24191 <title>A core <literal>Printf</literal></title>
24192 <simpara>We can now have a very small <literal>PRINTF</literal> signature, and define all
24193 the format strings externally to the core module.</simpara>
24194 <programlisting language="sml" linenumbering="unnumbered">signature PRINTF =
24195 sig
24196 type ('a, 'b) t
24197 val ` : string -&gt; ('a, 'a) t
24198 val newFormat: ('a -&gt; string) -&gt; ('a -&gt; 'b, 'c) t * string -&gt; ('b, 'c) t
24199 val printf: (unit, 'a) t -&gt; 'a
24200 end
24201
24202 structure Printf: PRINTF =
24203 struct
24204 datatype ('a, 'b) t = T of (unit -&gt; 'a) -&gt; 'b
24205
24206 fun printf (T f) = f (fn () =&gt; ())
24207
24208 fun ` s = T (fn a =&gt; (print s; a ()))
24209
24210 fun newFormat toString (T f, s) =
24211 T (fn th =&gt;
24212 f (fn () =&gt; fn a =&gt;
24213 (print (toString a)
24214 ; print s
24215 ; th ())))
24216 end</programlisting>
24217 </section>
24218 <section id="_extending_to_fprintf">
24219 <title>Extending to fprintf</title>
24220 <simpara>One can implement fprintf by threading the outstream through all the
24221 transformers.</simpara>
24222 <programlisting language="sml" linenumbering="unnumbered">signature PRINTF =
24223 sig
24224 type ('a, 'b) t
24225 val ` : string -&gt; ('a, 'a) t
24226 val fprintf: (unit, 'a) t * TextIO.outstream -&gt; 'a
24227 val newFormat: ('a -&gt; string) -&gt; ('a -&gt; 'b, 'c) t * string -&gt; ('b, 'c) t
24228 val printf: (unit, 'a) t -&gt; 'a
24229 end
24230
24231 structure Printf: PRINTF =
24232 struct
24233 type out = TextIO.outstream
24234 val output = TextIO.output
24235
24236 datatype ('a, 'b) t = T of (out -&gt; 'a) -&gt; out -&gt; 'b
24237
24238 fun fprintf (T f, out) = f (fn _ =&gt; ()) out
24239
24240 fun printf t = fprintf (t, TextIO.stdOut)
24241
24242 fun ` s = T (fn a =&gt; fn out =&gt; (output (out, s); a out))
24243
24244 fun newFormat toString (T f, s) =
24245 T (fn g =&gt;
24246 f (fn out =&gt; fn a =&gt;
24247 (output (out, toString a)
24248 ; output (out, s)
24249 ; g out)))
24250 end</programlisting>
24251 </section>
24252 <section id="_notes_3">
24253 <title>Notes</title>
24254 <itemizedlist>
24255 <listitem>
24256 <simpara>
24257 Lesson: instead of using dependent types for a function, express the
24258 the dependency in the type of the argument.
24259 </simpara>
24260 </listitem>
24261 <listitem>
24262 <simpara>
24263 If <literal>printf</literal> is partially applied, it will do the printing then and
24264 there. Perhaps this could be fixed with some kind of terminator.
24265 </simpara>
24266 <simpara>A syntactic or argument terminator is not necessary. A formatter can
24267 either be eager (as above) or lazy (as below). A lazy formatter
24268 accumulates enough state to print the entire string. The simplest
24269 lazy formatter concatenates the strings as they become available:</simpara>
24270 <programlisting language="sml" linenumbering="unnumbered">structure PrintfLazyConcat: PRINTF =
24271 struct
24272 datatype ('a, 'b) t = T of (string -&gt; 'a) -&gt; string -&gt; 'b
24273
24274 fun printf (T f) = f print ""
24275
24276 fun ` s = T (fn th =&gt; fn s' =&gt; th (s' ^ s))
24277
24278 fun newFormat toString (T f, s) =
24279 T (fn th =&gt;
24280 f (fn s' =&gt; fn a =&gt;
24281 th (s' ^ toString a ^ s)))
24282 end</programlisting>
24283 <simpara>It is somewhat more efficient to accumulate the strings as a list:</simpara>
24284 <programlisting language="sml" linenumbering="unnumbered">structure PrintfLazyList: PRINTF =
24285 struct
24286 datatype ('a, 'b) t = T of (string list -&gt; 'a) -&gt; string list -&gt; 'b
24287
24288 fun printf (T f) = f (List.app print o List.rev) []
24289
24290 fun ` s = T (fn th =&gt; fn ss =&gt; th (s::ss))
24291
24292 fun newFormat toString (T f, s) =
24293 T (fn th =&gt;
24294 f (fn ss =&gt; fn a =&gt;
24295 th (s::toString a::ss)))
24296 end</programlisting>
24297 </listitem>
24298 </itemizedlist>
24299 </section>
24300 <section id="_also_see_27">
24301 <title>Also see</title>
24302 <itemizedlist>
24303 <listitem>
24304 <simpara>
24305 <link linkend="Printf">Printf</link>
24306 </simpara>
24307 </listitem>
24308 <listitem>
24309 <simpara>
24310 <link linkend="References_Danvy98">Functional Unparsing</link>
24311 </simpara>
24312 </listitem>
24313 </itemizedlist>
24314 <simpara><?asciidoc-pagebreak?></simpara>
24315 </section>
24316 </section>
24317 <section id="ProductType">
24318 <title>ProductType</title>
24319 <simpara><link linkend="StandardML">Standard ML</link> has special syntax for products (tuples). A
24320 product type is written as</simpara>
24321 <programlisting language="sml" linenumbering="unnumbered">t1 * t2 * ... * tN</programlisting>
24322 <simpara>and a product pattern is written as</simpara>
24323 <programlisting language="sml" linenumbering="unnumbered">(p1, p2, ..., pN)</programlisting>
24324 <simpara>In most situations the syntax is quite convenient. However, there are
24325 situations where the syntax is cumbersome. There are also situations
24326 in which it is useful to construct and destruct n-ary products
24327 inductively, especially when using <link linkend="Fold">Fold</link>.</simpara>
24328 <simpara>In such situations, it is useful to have a binary product datatype
24329 with an infix constructor defined as follows.</simpara>
24330 <programlisting language="sml" linenumbering="unnumbered">datatype ('a, 'b) product = &amp; of 'a * 'b
24331 infix &amp;</programlisting>
24332 <simpara>With these definitions, one can write an n-ary product as a nested
24333 binary product quite conveniently.</simpara>
24334 <programlisting language="sml" linenumbering="unnumbered">x1 &amp; x2 &amp; ... &amp; xn</programlisting>
24335 <simpara>Because of left associativity, this is the same as</simpara>
24336 <programlisting language="sml" linenumbering="unnumbered">(((x1 &amp; x2) &amp; ...) &amp; xn)</programlisting>
24337 <simpara>Because <literal>&amp;</literal> is a constructor, the syntax can also be used for
24338 patterns.</simpara>
24339 <simpara>The symbol <literal>&amp;</literal> is inspired by the Curry-Howard isomorphism: the proof
24340 of a conjunction <literal>(A &amp; B)</literal> is a pair of proofs <literal>(a, b)</literal>.</simpara>
24341 <section id="_example_parser_combinators">
24342 <title>Example: parser combinators</title>
24343 <simpara>A typical parser combinator library provides a combinator that has a
24344 type of the form.</simpara>
24345 <programlisting language="sml" linenumbering="unnumbered">'a parser * 'b parser -&gt; ('a * 'b) parser</programlisting>
24346 <simpara>and produces a parser for the concatenation of two parsers. When more
24347 than two parsers are concatenated, the result of the resulting parser
24348 is a nested structure of pairs</simpara>
24349 <programlisting language="sml" linenumbering="unnumbered">(...((p1, p2), p3)..., pN)</programlisting>
24350 <simpara>which is somewhat cumbersome.</simpara>
24351 <simpara>By using a product type, the type of the concatenation combinator then
24352 becomes</simpara>
24353 <programlisting language="sml" linenumbering="unnumbered">'a parser * 'b parser -&gt; ('a, 'b) product parser</programlisting>
24354 <simpara>While this doesn&#8217;t stop the nesting, it makes the pattern significantly
24355 easier to write. Instead of</simpara>
24356 <programlisting language="sml" linenumbering="unnumbered">(...((p1, p2), p3)..., pN)</programlisting>
24357 <simpara>the pattern is written as</simpara>
24358 <programlisting language="sml" linenumbering="unnumbered">p1 &amp; p2 &amp; p3 &amp; ... &amp; pN</programlisting>
24359 <simpara>which is considerably more concise.</simpara>
24360 </section>
24361 <section id="_also_see_28">
24362 <title>Also see</title>
24363 <itemizedlist>
24364 <listitem>
24365 <simpara>
24366 <link linkend="VariableArityPolymorphism">VariableArityPolymorphism</link>
24367 </simpara>
24368 </listitem>
24369 <listitem>
24370 <simpara>
24371 <link linkend="Utilities">Utilities</link>
24372 </simpara>
24373 </listitem>
24374 </itemizedlist>
24375 <simpara><?asciidoc-pagebreak?></simpara>
24376 </section>
24377 </section>
24378 <section id="Profiling">
24379 <title>Profiling</title>
24380 <simpara>With MLton and <literal>mlprof</literal>, you can profile your program to find out
24381 bytes allocated, execution counts, or time spent in each function. To
24382 profile you program, compile with <literal>-profile <emphasis>kind</emphasis></literal>, where <emphasis>kind</emphasis>
24383 is one of <literal>alloc</literal>, <literal>count</literal>, or <literal>time</literal>. Then, run the executable,
24384 which will write an <literal>mlmon.out</literal> file when it finishes. You can then
24385 run <literal>mlprof</literal> on the executable and the <literal>mlmon.out</literal> file to see the
24386 performance data.</simpara>
24387 <simpara>Here are the three kinds of profiling that MLton supports.</simpara>
24388 <itemizedlist>
24389 <listitem>
24390 <simpara>
24391 <link linkend="ProfilingAllocation">ProfilingAllocation</link>
24392 </simpara>
24393 </listitem>
24394 <listitem>
24395 <simpara>
24396 <link linkend="ProfilingCounts">ProfilingCounts</link>
24397 </simpara>
24398 </listitem>
24399 <listitem>
24400 <simpara>
24401 <link linkend="ProfilingTime">ProfilingTime</link>
24402 </simpara>
24403 </listitem>
24404 </itemizedlist>
24405 <section id="_next_steps_6">
24406 <title>Next steps</title>
24407 <itemizedlist>
24408 <listitem>
24409 <simpara>
24410 <link linkend="CallGraph">CallGraph</link>s to visualize profiling data.
24411 </simpara>
24412 </listitem>
24413 <listitem>
24414 <simpara>
24415 <link linkend="HowProfilingWorks">HowProfilingWorks</link>
24416 </simpara>
24417 </listitem>
24418 <listitem>
24419 <simpara>
24420 <link linkend="MLmon">MLmon</link>
24421 </simpara>
24422 </listitem>
24423 <listitem>
24424 <simpara>
24425 <link linkend="MLtonProfile">MLtonProfile</link> to selectively profile parts of your program.
24426 </simpara>
24427 </listitem>
24428 <listitem>
24429 <simpara>
24430 <link linkend="ProfilingTheStack">ProfilingTheStack</link>
24431 </simpara>
24432 </listitem>
24433 <listitem>
24434 <simpara>
24435 <link linkend="ShowProf">ShowProf</link>
24436 </simpara>
24437 </listitem>
24438 </itemizedlist>
24439 <simpara><?asciidoc-pagebreak?></simpara>
24440 </section>
24441 </section>
24442 <section id="ProfilingAllocation">
24443 <title>ProfilingAllocation</title>
24444 <simpara>With MLton and <literal>mlprof</literal>, you can <link linkend="Profiling">profile</link> your program to
24445 find out how many bytes each function allocates. To do so, compile
24446 your program with <literal>-profile alloc</literal>. For example, suppose that
24447 <literal>list-rev.sml</literal> is the following.</simpara>
24448 <programlisting language="sml" linenumbering="unnumbered">fun append (l1, l2) =
24449 case l1 of
24450 [] =&gt; l2
24451 | x :: l1 =&gt; x :: append (l1, l2)
24452
24453 fun rev l =
24454 case l of
24455 [] =&gt; []
24456 | x :: l =&gt; append (rev l, [x])
24457
24458 val l = List.tabulate (1000, fn i =&gt; i)
24459 val _ = 1 + hd (rev l)</programlisting>
24460 <simpara>Compile and run <literal>list-rev</literal> as follows.</simpara>
24461 <screen>% mlton -profile alloc list-rev.sml
24462 % ./list-rev
24463 % mlprof -show-line true list-rev mlmon.out
24464 6,030,136 bytes allocated (108,336 bytes by GC)
24465 function cur
24466 ----------------------- -----
24467 append list-rev.sml: 1 97.6%
24468 &lt;gc&gt; 1.8%
24469 &lt;main&gt; 0.4%
24470 rev list-rev.sml: 6 0.2%</screen>
24471 <simpara>The data shows that most of the allocation is done by the <literal>append</literal>
24472 function defined on line 1 of <literal>list-rev.sml</literal>. The table also shows
24473 how special functions like <literal>gc</literal> and <literal>main</literal> are handled: they are
24474 printed with surrounding brackets. C functions are displayed
24475 similarly. In this example, the allocation done by the garbage
24476 collector is due to stack growth, which is usually the case.</simpara>
24477 <simpara>The run-time performance impact of allocation profiling is noticeable,
24478 because it inserts additional C calls for object allocation.</simpara>
24479 <simpara>Compile with <literal>-profile alloc -profile-branch true</literal> to find out how
24480 much allocation is done in each branch of a function; see
24481 <link linkend="ProfilingCounts">ProfilingCounts</link> for more details on <literal>-profile-branch</literal>.</simpara>
24482 <simpara><?asciidoc-pagebreak?></simpara>
24483 </section>
24484 <section id="ProfilingCounts">
24485 <title>ProfilingCounts</title>
24486 <simpara>With MLton and <literal>mlprof</literal>, you can <link linkend="Profiling">profile</link> your program to
24487 find out how many times each function is called and how many times
24488 each branch is taken. To do so, compile your program with
24489 <literal>-profile count -profile-branch true</literal>. For example, suppose that
24490 <literal>tak.sml</literal> contains the following.</simpara>
24491 <programlisting language="sml" linenumbering="unnumbered">structure Tak =
24492 struct
24493 fun tak1 (x, y, z) =
24494 let
24495 fun tak2 (x, y, z) =
24496 if y &gt;= x
24497 then z
24498 else
24499 tak1 (tak2 (x - 1, y, z),
24500 tak2 (y - 1, z, x),
24501 tak2 (z - 1, x, y))
24502 in
24503 if y &gt;= x
24504 then z
24505 else
24506 tak1 (tak2 (x - 1, y, z),
24507 tak2 (y - 1, z, x),
24508 tak2 (z - 1, x, y))
24509 end
24510 end
24511
24512 val rec f =
24513 fn 0 =&gt; ()
24514 | ~1 =&gt; print "this branch is not taken\n"
24515 | n =&gt; (Tak.tak1 (18, 12, 6) ; f (n-1))
24516
24517 val _ = f 5000
24518
24519 fun uncalled () = ()</programlisting>
24520 <simpara>Compile with count profiling and run the program.</simpara>
24521 <screen>% mlton -profile count -profile-branch true tak.sml
24522 % ./tak</screen>
24523 <simpara>Display the profiling data, along with raw counts and file positions.</simpara>
24524 <screen>% mlprof -raw true -show-line true tak mlmon.out
24525 623,610,002 ticks
24526 function cur raw
24527 --------------------------------- ----- -------------
24528 Tak.tak1.tak2 tak.sml: 5 38.2% (238,530,000)
24529 Tak.tak1.tak2.&lt;true&gt; tak.sml: 7 27.5% (171,510,000)
24530 Tak.tak1 tak.sml: 3 10.7% (67,025,000)
24531 Tak.tak1.&lt;true&gt; tak.sml: 14 10.7% (67,025,000)
24532 Tak.tak1.tak2.&lt;false&gt; tak.sml: 9 10.7% (67,020,000)
24533 Tak.tak1.&lt;false&gt; tak.sml: 16 2.0% (12,490,000)
24534 f tak.sml: 23 0.0% (5,001)
24535 f.&lt;branch&gt; tak.sml: 25 0.0% (5,000)
24536 f.&lt;branch&gt; tak.sml: 23 0.0% (1)
24537 uncalled tak.sml: 29 0.0% (0)
24538 f.&lt;branch&gt; tak.sml: 24 0.0% (0)</screen>
24539 <simpara>Branches are displayed with lexical nesting followed by <literal>&lt;branch&gt;</literal>
24540 where the function name would normally be, or <literal>&lt;true&gt;</literal> or <literal>&lt;false&gt;</literal>
24541 for if-expressions. It is best to run <literal>mlprof</literal> with <literal>-show-line true</literal>
24542 to help identify the branch.</simpara>
24543 <simpara>One use of <literal>-profile count</literal> is as a code-coverage tool, to help find
24544 code in your program that hasn&#8217;t been tested. For this reason,
24545 <literal>mlprof</literal> displays functions and branches even if they have a count of
24546 zero. As the above output shows, the branch on line 24 was never
24547 taken and the function defined on line 29 was never called. To see
24548 zero counts, it is best to run <literal>mlprof</literal> with <literal>-raw true</literal>, since some
24549 code (e.g. the branch on line 23 above) will show up with <literal>0.0%</literal> but
24550 may still have been executed and hence have a nonzero raw count.</simpara>
24551 <simpara><?asciidoc-pagebreak?></simpara>
24552 </section>
24553 <section id="ProfilingTheStack">
24554 <title>ProfilingTheStack</title>
24555 <simpara>For all forms of <link linkend="Profiling">Profiling</link>, you can gather counts for all
24556 functions on the stack, not just the currently executing function. To
24557 do so, compile your program with <literal>-profile-stack true</literal>. For example,
24558 suppose that <literal>list-rev.sml</literal> contains the following.</simpara>
24559 <programlisting language="sml" linenumbering="unnumbered">fun append (l1, l2) =
24560 case l1 of
24561 [] =&gt; l2
24562 | x :: l1 =&gt; x :: append (l1, l2)
24563
24564 fun rev l =
24565 case l of
24566 [] =&gt; []
24567 | x :: l =&gt; append (rev l, [x])
24568
24569 val l = List.tabulate (1000, fn i =&gt; i)
24570 val _ = 1 + hd (rev l)</programlisting>
24571 <simpara>Compile with stack profiling and then run the program.</simpara>
24572 <screen>% mlton -profile alloc -profile-stack true list-rev.sml
24573 % ./list-rev</screen>
24574 <simpara>Display the profiling data.</simpara>
24575 <screen>% mlprof -show-line true list-rev mlmon.out
24576 6,030,136 bytes allocated (108,336 bytes by GC)
24577 function cur stack GC
24578 ----------------------- ----- ----- ----
24579 append list-rev.sml: 1 97.6% 97.6% 1.4%
24580 &lt;gc&gt; 1.8% 0.0% 1.8%
24581 &lt;main&gt; 0.4% 98.2% 1.8%
24582 rev list-rev.sml: 6 0.2% 97.6% 1.8%</screen>
24583 <simpara>In the above table, we see that <literal>rev</literal>, defined on line 6 of
24584 <literal>list-rev.sml</literal>, is only responsible for 0.2% of the allocation, but is
24585 on the stack while 97.6% of the allocation is done by the user program
24586 and while 1.8% of the allocation is done by the garbage collector.</simpara>
24587 <simpara>The run-time performance impact of <literal>-profile-stack true</literal> can be
24588 noticeable since there is some extra bookkeeping at every nontail call
24589 and return.</simpara>
24590 <simpara><?asciidoc-pagebreak?></simpara>
24591 </section>
24592 <section id="ProfilingTime">
24593 <title>ProfilingTime</title>
24594 <simpara>With MLton and <literal>mlprof</literal>, you can <link linkend="Profiling">profile</link> your program to
24595 find out how much time is spent in each function over an entire run of
24596 the program. To do so, compile your program with <literal>-profile time</literal>.
24597 For example, suppose that <literal>tak.sml</literal> contains the following.</simpara>
24598 <programlisting language="sml" linenumbering="unnumbered">structure Tak =
24599 struct
24600 fun tak1 (x, y, z) =
24601 let
24602 fun tak2 (x, y, z) =
24603 if y &gt;= x
24604 then z
24605 else
24606 tak1 (tak2 (x - 1, y, z),
24607 tak2 (y - 1, z, x),
24608 tak2 (z - 1, x, y))
24609 in
24610 if y &gt;= x
24611 then z
24612 else
24613 tak1 (tak2 (x - 1, y, z),
24614 tak2 (y - 1, z, x),
24615 tak2 (z - 1, x, y))
24616 end
24617 end
24618
24619 val rec f =
24620 fn 0 =&gt; ()
24621 | ~1 =&gt; print "this branch is not taken\n"
24622 | n =&gt; (Tak.tak1 (18, 12, 6) ; f (n-1))
24623
24624 val _ = f 5000
24625
24626 fun uncalled () = ()</programlisting>
24627 <simpara>Compile with time profiling and run the program.</simpara>
24628 <screen>% mlton -profile time tak.sml
24629 % ./tak</screen>
24630 <simpara>Display the profiling data.</simpara>
24631 <screen>% mlprof tak mlmon.out
24632 6.00 seconds of CPU time (0.00 seconds GC)
24633 function cur
24634 ------------- -----
24635 Tak.tak1.tak2 75.8%
24636 Tak.tak1 24.2%</screen>
24637 <simpara>This example shows how <literal>mlprof</literal> indicates lexical nesting: as a
24638 sequence of period-separated names indicating the structures and
24639 functions in which a function definition is nested. The profiling
24640 data shows that roughly three-quarters of the time is spent in the
24641 <literal>Tak.tak1.tak2</literal> function, while the rest is spent in <literal>Tak.tak1</literal>.</simpara>
24642 <simpara>Display raw counts in addition to percentages with <literal>-raw true</literal>.</simpara>
24643 <screen>% mlprof -raw true tak mlmon.out
24644 6.00 seconds of CPU time (0.00 seconds GC)
24645 function cur raw
24646 ------------- ----- -------
24647 Tak.tak1.tak2 75.8% (4.55s)
24648 Tak.tak1 24.2% (1.45s)</screen>
24649 <simpara>Display the file name and line number for each function in addition to
24650 its name with <literal>-show-line true</literal>.</simpara>
24651 <screen>% mlprof -show-line true tak mlmon.out
24652 6.00 seconds of CPU time (0.00 seconds GC)
24653 function cur
24654 ------------------------- -----
24655 Tak.tak1.tak2 tak.sml: 5 75.8%
24656 Tak.tak1 tak.sml: 3 24.2%</screen>
24657 <simpara>Time profiling is designed to have a very small performance impact.
24658 However, in some cases there will be a run-time performance cost,
24659 which may perturb the results. There is more likely to be an impact
24660 with <literal>-codegen c</literal> than <literal>-codegen native</literal>.</simpara>
24661 <simpara>You can also compile with <literal>-profile time -profile-branch true</literal> to find
24662 out how much time is spent in each branch of a function; see
24663 <link linkend="ProfilingCounts">ProfilingCounts</link> for more details on <literal>-profile-branch</literal>.</simpara>
24664 <section id="_caveats_3">
24665 <title>Caveats</title>
24666 <simpara>With <literal>-profile time</literal>, use of the following in your program will cause
24667 a run-time error, since they would interfere with the profiler signal
24668 handler.</simpara>
24669 <itemizedlist>
24670 <listitem>
24671 <simpara>
24672 <literal>MLton.Itimer.set (MLton.Itimer.Prof, ...)</literal>
24673 </simpara>
24674 </listitem>
24675 <listitem>
24676 <simpara>
24677 <literal>MLton.Signal.setHandler (MLton.Signal.prof, ...)</literal>
24678 </simpara>
24679 </listitem>
24680 </itemizedlist>
24681 <simpara>Also, because of the random sampling used to implement <literal>-profile
24682 time</literal>, it is best to have a long running program (at least tens of
24683 seconds) in order to get reasonable time</simpara>
24684 <simpara><?asciidoc-pagebreak?></simpara>
24685 </section>
24686 </section>
24687 <section id="Projects">
24688 <title>Projects</title>
24689 <simpara>We have lots of ideas for projects to improve MLton, many of which we
24690 do not have time to implement, or at least haven&#8217;t started on yet.
24691 Here is a list of some of those improvements, ranging from the easy (1
24692 week) to the difficult (several months). If you have any interest in
24693 working on one of these, or some other improvement to MLton not listed
24694 here, please send mail to
24695 <ulink url="mailto:MLton-devel@mlton.org"><literal>MLton-devel@mlton.org</literal></ulink>.</simpara>
24696 <itemizedlist>
24697 <listitem>
24698 <simpara>
24699 Port to new platform: Windows (native, not Cygwin or MinGW), &#8230;
24700 </simpara>
24701 </listitem>
24702 <listitem>
24703 <simpara>
24704 Source-level debugger
24705 </simpara>
24706 </listitem>
24707 <listitem>
24708 <simpara>
24709 Heap profiler
24710 </simpara>
24711 </listitem>
24712 <listitem>
24713 <simpara>
24714 Interfaces to libraries: OpenGL, Gtk+, D-BUS, &#8230;
24715 </simpara>
24716 </listitem>
24717 <listitem>
24718 <simpara>
24719 More libraries written in SML (see <ulink url="https://github.com/MLton/mltonlib"><literal>mltonlib</literal></ulink>)
24720 </simpara>
24721 </listitem>
24722 <listitem>
24723 <simpara>
24724 Additional constant types: <literal>structure Real80: REAL</literal>, &#8230;
24725 </simpara>
24726 </listitem>
24727 <listitem>
24728 <simpara>
24729 An IDE (possibly integrated with <link linkend="Eclipse">Eclipse</link>)
24730 </simpara>
24731 </listitem>
24732 <listitem>
24733 <simpara>
24734 Port MLRISC and use for code generation
24735 </simpara>
24736 </listitem>
24737 <listitem>
24738 <simpara>
24739 Optimizations
24740 </simpara>
24741 <itemizedlist>
24742 <listitem>
24743 <simpara>
24744 Improved closure representation
24745 </simpara>
24746 <simpara>Right now, MLton&#8217;s closure conversion algorithm uses a simple flat closure to represent each function.</simpara>
24747 <itemizedlist>
24748 <listitem>
24749 <simpara>
24750 <ulink url="http://www.mlton.org/pipermail/mlton/2003-October/024570.html">http://www.mlton.org/pipermail/mlton/2003-October/024570.html</ulink>
24751 </simpara>
24752 </listitem>
24753 <listitem>
24754 <simpara>
24755 <ulink url="http://www.mlton.org/pipermail/mlton-user/2007-July/001150.html">http://www.mlton.org/pipermail/mlton-user/2007-July/001150.html</ulink>
24756 </simpara>
24757 </listitem>
24758 <listitem>
24759 <simpara>
24760 <link linkend="References_ShaoAppel94">ShaoAppel94</link>
24761 </simpara>
24762 </listitem>
24763 </itemizedlist>
24764 </listitem>
24765 <listitem>
24766 <simpara>
24767 Elimination of array bounds checks in loops
24768 </simpara>
24769 </listitem>
24770 <listitem>
24771 <simpara>
24772 Elimination of overflow checks on array index computations
24773 </simpara>
24774 </listitem>
24775 <listitem>
24776 <simpara>
24777 Common-subexpression elimination of repeated array subscripts
24778 </simpara>
24779 </listitem>
24780 <listitem>
24781 <simpara>
24782 Loop-invariant code motion, especially for tuple selects
24783 </simpara>
24784 </listitem>
24785 <listitem>
24786 <simpara>
24787 Partial redundancy elimination
24788 </simpara>
24789 <itemizedlist>
24790 <listitem>
24791 <simpara>
24792 <ulink url="http://www.mlton.org/pipermail/mlton/2006-April/028598.html">http://www.mlton.org/pipermail/mlton/2006-April/028598.html</ulink>
24793 </simpara>
24794 </listitem>
24795 </itemizedlist>
24796 </listitem>
24797 <listitem>
24798 <simpara>
24799 Loop unrolling, especially for small loops
24800 </simpara>
24801 </listitem>
24802 <listitem>
24803 <simpara>
24804 Auto-vectorization, for MMX/SSE/3DNow!/AltiVec (see the <ulink url="http://gcc.gnu.org/projects/tree-ssa/vectorization.html">work done on GCC</ulink>)
24805 </simpara>
24806 </listitem>
24807 <listitem>
24808 <simpara>
24809 Optimize <literal>MLton_eq</literal>: pointer equality is necessarily false when one of the arguments is freshly allocated in the block
24810 </simpara>
24811 </listitem>
24812 </itemizedlist>
24813 </listitem>
24814 <listitem>
24815 <simpara>
24816 Analyses
24817 </simpara>
24818 <itemizedlist>
24819 <listitem>
24820 <simpara>
24821 Uncaught exception analysis
24822 </simpara>
24823 </listitem>
24824 </itemizedlist>
24825 </listitem>
24826 </itemizedlist>
24827 <simpara><?asciidoc-pagebreak?></simpara>
24828 </section>
24829 <section id="Pronounce">
24830 <title>Pronounce</title>
24831 <simpara>Here is <ulink url="guide/Pronounce.attachments/pronounce-mlton.mp3">how "MLton" sounds</ulink>.</simpara>
24832 <simpara>"MLton" is pronounced in two syllables, with stress on the first
24833 syllable. The first syllable sounds like the word <emphasis>mill</emphasis> (as in
24834 "steel mill"), the second like the word <emphasis>tin</emphasis> (as in "cookie tin").</simpara>
24835 <simpara><?asciidoc-pagebreak?></simpara>
24836 </section>
24837 <section id="PropertyList">
24838 <title>PropertyList</title>
24839 <simpara>A property list is a dictionary-like data structure into which
24840 properties (name-value pairs) can be inserted and from which
24841 properties can be looked up by name. The term comes from the Lisp
24842 language, where every symbol has a property list for storing
24843 information, and where the names are typically symbols and keys can be
24844 any type of value.</simpara>
24845 <simpara>Here is an SML signature for property lists such that for any type of
24846 value a new property can be dynamically created to manipulate that
24847 type of value in a property list.</simpara>
24848 <programlisting language="sml" linenumbering="unnumbered">signature PROPERTY_LIST =
24849 sig
24850 type t
24851
24852 val new: unit -&gt; t
24853 val newProperty: unit -&gt; {add: t * 'a -&gt; unit,
24854 peek: t -&gt; 'a option}
24855 end</programlisting>
24856 <simpara>Here is a functor demonstrating the use of property lists. It first
24857 creates a property list, then two new properties (of different types),
24858 and adds a value to the list for each property.</simpara>
24859 <programlisting language="sml" linenumbering="unnumbered">functor Test (P: PROPERTY_LIST) =
24860 struct
24861 val pl = P.new ()
24862
24863 val {add = addInt: P.t * int -&gt; unit, peek = peekInt} = P.newProperty ()
24864 val {add = addReal: P.t * real -&gt; unit, peek = peekReal} = P.newProperty ()
24865
24866 val () = addInt (pl, 13)
24867 val () = addReal (pl, 17.0)
24868 val s1 = Int.toString (valOf (peekInt pl))
24869 val s2 = Real.toString (valOf (peekReal pl))
24870 val () = print (concat [s1, " ", s2, "\n"])
24871 end</programlisting>
24872 <simpara>Applied to an appropriate implementation <literal>PROPERTY_LIST</literal>, the <literal>Test</literal>
24873 functor will produce the following output.</simpara>
24874 <screen>13 17.0</screen>
24875 <section id="_implementation_50">
24876 <title>Implementation</title>
24877 <simpara>Because property lists can hold values of any type, their
24878 implementation requires a <link linkend="UniversalType">UniversalType</link>. Given that, a property
24879 list is simply a list of elements of the universal type. Adding a
24880 property adds to the front of the list, and looking up a property
24881 scans the list.</simpara>
24882 <programlisting language="sml" linenumbering="unnumbered">functor PropertyList (U: UNIVERSAL_TYPE): PROPERTY_LIST =
24883 struct
24884 datatype t = T of U.t list ref
24885
24886 fun new () = T (ref [])
24887
24888 fun 'a newProperty () =
24889 let
24890 val (inject, out) = U.embed ()
24891 fun add (T r, a: 'a): unit = r := inject a :: (!r)
24892 fun peek (T r) =
24893 Option.map (valOf o out) (List.find (isSome o out) (!r))
24894 in
24895 {add = add, peek = peek}
24896 end
24897 end</programlisting>
24898 <simpara>If <literal>U: UNIVERSAL_TYPE</literal>, then we can test our code as follows.</simpara>
24899 <programlisting language="sml" linenumbering="unnumbered">structure Z = Test (PropertyList (U))</programlisting>
24900 <simpara>Of course, a serious implementation of property lists would have to
24901 handle duplicate insertions of the same property, as well as the
24902 removal of elements in order to avoid space leaks.</simpara>
24903 </section>
24904 <section id="_also_see_29">
24905 <title>Also see</title>
24906 <itemizedlist>
24907 <listitem>
24908 <simpara>
24909 MLton relies heavily on property lists for attaching information to
24910 syntax tree nodes in its intermediate languages. See
24911 <ulink url="https://github.com/MLton/mlton/blob/master/lib/mlton/basic/property-list.sig"><literal>property-list.sig</literal></ulink> and
24912 <ulink url="https://github.com/MLton/mlton/blob/master/lib/mlton/basic/property-list.fun"><literal>property-list.fun</literal></ulink>.
24913 </simpara>
24914 </listitem>
24915 <listitem>
24916 <simpara>
24917 The <link linkend="MLRISCLibrary">MLRISCLibrary</link> <link linkend="References_LeungGeorge99">uses property lists extensively</link>.
24918 </simpara>
24919 </listitem>
24920 </itemizedlist>
24921 <simpara><?asciidoc-pagebreak?></simpara>
24922 </section>
24923 </section>
24924 <section id="Pygments">
24925 <title>Pygments</title>
24926 <simpara><ulink url="http://pygments.org/">Pygments</ulink> is a generic syntax highlighter. Here is a <emphasis>lexer</emphasis> for highlighting
24927 <link linkend="StandardML">Standard ML</link>.</simpara>
24928 <itemizedlist>
24929 <listitem>
24930 <simpara>
24931 <ulink url="https://github.com/MLton/mlton/tree/master/ide/pygments/sml_lexer"><literal>sml_lexer</literal></ulink>&#8201;&#8212;&#8201;Provides highlighting of keywords, special constants, and (nested) comments.
24932 </simpara>
24933 </listitem>
24934 </itemizedlist>
24935 <section id="_install_and_use_2">
24936 <title>Install and use</title>
24937 <itemizedlist>
24938 <listitem>
24939 <simpara>
24940 Checkout all files and install as a <ulink url="http://pygments.org/">Pygments</ulink> plugin.
24941 </simpara>
24942 <screen>$ git clone https://github.com/MLton/mlton.git mlton
24943 $ cd mlton/ide/pygments
24944 $ python setup.py install</screen>
24945 </listitem>
24946 <listitem>
24947 <simpara>
24948 Invoke <literal>pygmentize</literal> with <literal>-l sml</literal>.
24949 </simpara>
24950 </listitem>
24951 </itemizedlist>
24952 </section>
24953 <section id="_feedback_2">
24954 <title>Feedback</title>
24955 <simpara>Comments and suggestions should be directed to <link linkend="MatthewFluet">MatthewFluet</link>.</simpara>
24956 <simpara><?asciidoc-pagebreak?></simpara>
24957 </section>
24958 </section>
24959 <section id="RayRacine">
24960 <title>RayRacine</title>
24961 <simpara>Using SML in some <emphasis>Semantic Web</emphasis> stuff. Anyone interested in
24962 similar, please contact me. GreyLensman on #sml on IRC or rracine at
24963 this domain adelphia with a dot here net.</simpara>
24964 <simpara>Current areas of coding.</simpara>
24965 <orderedlist numeration="arabic">
24966 <listitem>
24967 <simpara>
24968 Pretty solid, high performance Rete implementation - base functionality is complete.
24969 </simpara>
24970 </listitem>
24971 <listitem>
24972 <simpara>
24973 N3 parser - mostly complete
24974 </simpara>
24975 </listitem>
24976 <listitem>
24977 <simpara>
24978 RDF parser based on fxg - not started.
24979 </simpara>
24980 </listitem>
24981 <listitem>
24982 <simpara>
24983 Swerve HTTP server - 1/2 done.
24984 </simpara>
24985 </listitem>
24986 <listitem>
24987 <simpara>
24988 SPARQL implementation - not started.
24989 </simpara>
24990 </listitem>
24991 <listitem>
24992 <simpara>
24993 Persistent engine based on BerkelyDB - not started.
24994 </simpara>
24995 </listitem>
24996 <listitem>
24997 <simpara>
24998 Native implementation of Postgresql protocol - underway, ways to go.
24999 </simpara>
25000 </listitem>
25001 <listitem>
25002 <simpara>
25003 I also have a small change to the MLton compiler to add <literal>PackWord<emphasis>&lt;N&gt;</emphasis></literal> - changes compile but needs some more work, clean-up and unit tests.
25004 </simpara>
25005 </listitem>
25006 </orderedlist>
25007 <simpara><?asciidoc-pagebreak?></simpara>
25008 </section>
25009 <section id="Reachability">
25010 <title>Reachability</title>
25011 <simpara>Reachability is a notion dealing with the graph of heap objects
25012 maintained at runtime. Nodes in the graph are heap objects and edges
25013 correspond to the pointers between heap objects. As the program runs,
25014 it allocates new objects (adds nodes to the graph), and those new
25015 objects can contain pointers to other objects (new edges in the
25016 graph). If the program uses mutable objects (refs or arrays), it can
25017 also change edges in the graph.</simpara>
25018 <simpara>At any time, the program has access to some finite set of <emphasis>root</emphasis>
25019 nodes, and can only ever access nodes that are reachable by following
25020 edges from these root nodes. Nodes that are <emphasis>unreachable</emphasis> can be
25021 garbage collected.</simpara>
25022 <section id="_also_see_30">
25023 <title>Also see</title>
25024 <itemizedlist>
25025 <listitem>
25026 <simpara>
25027 <link linkend="MLtonFinalizable">MLtonFinalizable</link>
25028 </simpara>
25029 </listitem>
25030 <listitem>
25031 <simpara>
25032 <link linkend="MLtonWeak">MLtonWeak</link>
25033 </simpara>
25034 </listitem>
25035 </itemizedlist>
25036 <simpara><?asciidoc-pagebreak?></simpara>
25037 </section>
25038 </section>
25039 <section id="Redundant">
25040 <title>Redundant</title>
25041 <simpara><link linkend="Redundant">Redundant</link> is an optimization pass for the <link linkend="SSA">SSA</link>
25042 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
25043 <section id="_description_46">
25044 <title>Description</title>
25045 <simpara>The redundant SSA optimization eliminates redundant function and label
25046 arguments; an argument of a function or label is redundant if it is
25047 always the same as another argument of the same function or label.
25048 The analysis finds an equivalence relation on the arguments of a
25049 function or label, such that all arguments in an equivalence class are
25050 redundant with respect to the other arguments in the equivalence
25051 class; the transformation selects one representative of each
25052 equivalence class and drops the binding occurrence of
25053 non-representative variables and renames use occurrences of the
25054 non-representative variables to the representative variable. The
25055 analysis finds the equivalence classes via a fixed-point analysis.
25056 Each vector of arguments to a function or label is initialized to
25057 equivalence classes that equate all arguments of the same type; one
25058 could start with an equivalence class that equates all arguments, but
25059 arguments of different type cannot be redundant. Variables bound in
25060 statements are initialized to singleton equivalence classes. The
25061 fixed-point analysis repeatedly refines these equivalence classes on
25062 the formals by the equivalence classes of the actuals.</simpara>
25063 </section>
25064 <section id="_implementation_51">
25065 <title>Implementation</title>
25066 <itemizedlist>
25067 <listitem>
25068 <simpara>
25069 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/redundant.fun"><literal>redundant.fun</literal></ulink>
25070 </simpara>
25071 </listitem>
25072 </itemizedlist>
25073 </section>
25074 <section id="_details_and_notes_49">
25075 <title>Details and Notes</title>
25076 <simpara>The reason <link linkend="Redundant">Redundant</link> got put in was due to some output of the
25077 <link linkend="ClosureConvert">ClosureConvert</link> pass converter where the environment record, or
25078 components of it, were passed around in several places. That may have
25079 been more relevant with polyvariant analyses (which are long gone).
25080 But it still seems possibly relevant, especially with more aggressive
25081 flattening, which should reveal some fields in nested closure records
25082 that are redundant.</simpara>
25083 <simpara><?asciidoc-pagebreak?></simpara>
25084 </section>
25085 </section>
25086 <section id="RedundantTests">
25087 <title>RedundantTests</title>
25088 <simpara><link linkend="RedundantTests">RedundantTests</link> is an optimization pass for the <link linkend="SSA">SSA</link>
25089 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
25090 <section id="_description_47">
25091 <title>Description</title>
25092 <simpara>This pass simplifies conditionals whose results are implied by a
25093 previous conditional test.</simpara>
25094 </section>
25095 <section id="_implementation_52">
25096 <title>Implementation</title>
25097 <itemizedlist>
25098 <listitem>
25099 <simpara>
25100 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/redundant-tests.fun"><literal>redundant-tests.fun</literal></ulink>
25101 </simpara>
25102 </listitem>
25103 </itemizedlist>
25104 </section>
25105 <section id="_details_and_notes_50">
25106 <title>Details and Notes</title>
25107 <simpara>An additional test will sometimes eliminate the overflow test when
25108 adding or subtracting 1. In particular, it will eliminate it in the
25109 following cases:</simpara>
25110 <programlisting language="sml" linenumbering="unnumbered">if x &lt; y
25111 then ... x + 1 ...
25112 else ... y - 1 ...</programlisting>
25113 <simpara><?asciidoc-pagebreak?></simpara>
25114 </section>
25115 </section>
25116 <section id="References">
25117 <title>References</title>
25118 <simpara><link linkend="References_AAA">A</link>
25119 <link linkend="References_BBB">B</link>
25120 <link linkend="References_CCC">C</link>
25121 <link linkend="References_DDD">D</link>
25122 <link linkend="References_EEE">E</link>
25123 <link linkend="References_FFF">F</link>
25124 <link linkend="References_GGG">G</link>
25125 <link linkend="References_HHH">H</link>
25126 <link linkend="References_III">I</link>
25127 <link linkend="References_JJJ">J</link>
25128 <link linkend="References_KKK">K</link>
25129 <link linkend="References_LLL">L</link>
25130 <link linkend="References_MMM">M</link>
25131 <link linkend="References_NNN">N</link>
25132 <link linkend="References_OOO">O</link>
25133 <link linkend="References_PPP">P</link>
25134 <link linkend="References_QQQ">Q</link>
25135 <link linkend="References_RRR">R</link>
25136 <link linkend="References_SSS">S</link>
25137 <link linkend="References_TTT">T</link>
25138 <link linkend="References_UUU">U</link>
25139 <link linkend="References_VVV">V</link>
25140 <link linkend="References_WWW">W</link>
25141 <link linkend="References_XXX">X</link>
25142 <link linkend="References_YYY">Y</link>
25143 <link linkend="References_ZZZ">Z</link></simpara>
25144 <section id="_anchor_id_references_aaa_xreflabel_references_aaa_a">
25145 <title><anchor id="References_AAA" xreflabel="[References_AAA]"/>A</title>
25146 <itemizedlist>
25147 <listitem>
25148 <simpara>
25149 <anchor id="References_AcarEtAl06" xreflabel="[References_AcarEtAl06]"/>
25150 <ulink url="http://www.umut-acar.org/publications/pldi2006.pdf">An Experimental Analysis of Self-Adjusting Computation</ulink>
25151 Umut Acar, Guy Blelloch, Matthias Blume, and Kanat Tangwongsan.
25152 <link linkend="References_PLDI">PLDI</link> 2006.
25153 </simpara>
25154 </listitem>
25155 <listitem>
25156 <simpara>
25157 <anchor id="References_Appel92" xreflabel="[References_Appel92]"/>
25158 <ulink url="http://us.cambridge.org/titles/catalogue.asp?isbn=0521416957">Compiling with Continuations</ulink>
25159 (<ulink url="http://www.addall.com/New/submitNew.cgi?query=0-521-41695-7&amp;type=ISBN&amp;location=10000&amp;state=&amp;dispCurr=USD">addall</ulink>).
25160 ISBN 0521416957.
25161 Andrew W. Appel.
25162 Cambridge University Press, 1992.
25163 </simpara>
25164 </listitem>
25165 <listitem>
25166 <simpara>
25167 <anchor id="References_Appel93" xreflabel="[References_Appel93]"/>
25168 <ulink url="http://www.cs.princeton.edu/research/techreps/TR-364-92">A Critique of Standard ML</ulink>.
25169 Andrew W. Appel.
25170 <link linkend="References_JFP">JFP</link> 1993.
25171 </simpara>
25172 </listitem>
25173 <listitem>
25174 <simpara>
25175 <anchor id="References_Appel98" xreflabel="[References_Appel98]"/>
25176 <ulink url="http://us.cambridge.org/titles/catalogue.asp?isbn=0521582741">Modern Compiler Implementation in ML</ulink>
25177 (<ulink url="http://www.addall.com/New/submitNew.cgi?query=0-521-58274-1&amp;type=ISBN&amp;location=10000&amp;state=&amp;dispCurr=USD">addall</ulink>).
25178 ISBN 0521582741
25179 Andrew W. Appel.
25180 Cambridge University Press, 1998.
25181 </simpara>
25182 </listitem>
25183 <listitem>
25184 <simpara>
25185 <anchor id="References_AppelJim97" xreflabel="[References_AppelJim97]"/>
25186 <ulink url="http://ncstrl.cs.princeton.edu/expand.php?id=TR-556-97">Shrinking Lambda Expressions in Linear Time</ulink>
25187 Andrew Appel and Trevor Jim.
25188 <link linkend="References_JFP">JFP</link> 1997.
25189 </simpara>
25190 </listitem>
25191 <listitem>
25192 <simpara>
25193 <anchor id="References_AppelEtAl94" xreflabel="[References_AppelEtAl94]"/>
25194 <ulink url="http://www.smlnj.org/doc/ML-Lex/manual.html">A lexical analyzer generator for Standard ML. Version 1.6.0</ulink>
25195 Andrew W. Appel, James S. Mattson, and David R. Tarditi. 1994
25196 </simpara>
25197 </listitem>
25198 </itemizedlist>
25199 </section>
25200 <section id="_anchor_id_references_bbb_xreflabel_references_bbb_b">
25201 <title><anchor id="References_BBB" xreflabel="[References_BBB]"/>B</title>
25202 <itemizedlist>
25203 <listitem>
25204 <simpara>
25205 <anchor id="References_BaudinetMacQueen85" xreflabel="[References_BaudinetMacQueen85]"/>
25206 <ulink url="http://www.classes.cs.uchicago.edu/archive/2011/spring/22620-1/papers/macqueen-baudinet85.pdf">Tree Pattern Matching for ML</ulink>.
25207 Marianne Baudinet, David MacQueen. 1985.
25208 </simpara>
25209 <blockquote>
25210 <simpara>Describes the match compiler used in an early version of
25211 <link linkend="SMLNJ">SML/NJ</link>.</simpara>
25212 </blockquote>
25213 </listitem>
25214 <listitem>
25215 <simpara>
25216 <anchor id="References_BentonEtAl98" xreflabel="[References_BentonEtAl98]"/>
25217 <ulink url="http://research.microsoft.com/en-us/um/people/nick/icfp98.pdf">Compiling Standard ML to Java Bytecodes</ulink>.
25218 Nick Benton, Andrew Kennedy, and George Russell.
25219 <link linkend="References_ICFP">ICFP</link> 1998.
25220 </simpara>
25221 </listitem>
25222 <listitem>
25223 <simpara>
25224 <anchor id="References_BentonKennedy99" xreflabel="[References_BentonKennedy99]"/>
25225 <ulink url="http://research.microsoft.com/en-us/um/people/nick/SMLJavaInterop.pdf">Interlanguage Working Without Tears: Blending SML with Java</ulink>.
25226 Nick Benton and Andrew Kennedy.
25227 <link linkend="References_ICFP">ICFP</link> 1999.
25228 </simpara>
25229 </listitem>
25230 <listitem>
25231 <simpara>
25232 <anchor id="References_BentonKennedy01" xreflabel="[References_BentonKennedy01]"/>
25233 <ulink url="http://research.microsoft.com/en-us/um/people/akenn/sml/ExceptionalSyntax.pdf">Exceptional Syntax</ulink>.
25234 Nick Benton and Andrew Kennedy.
25235 <link linkend="References_JFP">JFP</link> 2001.
25236 </simpara>
25237 </listitem>
25238 <listitem>
25239 <simpara>
25240 <anchor id="References_BentonEtAl04" xreflabel="[References_BentonEtAl04]"/>
25241 <ulink url="http://research.microsoft.com/en-us/um/people/nick/p53-Benton.pdf">Adventures in Interoperability: The SML.NET Experience</ulink>.
25242 Nick Benton, Andrew Kennedy, and Claudio Russo.
25243 <link linkend="References_PPDP">PPDP</link> 2004.
25244 </simpara>
25245 </listitem>
25246 <listitem>
25247 <simpara>
25248 <anchor id="References_BentonEtAl04_2" xreflabel="[References_BentonEtAl04_2]"/>
25249 <ulink url="http://research.microsoft.com/en-us/um/people/nick/shrinking.pdf">Shrinking Reductions in SML.NET</ulink>.
25250 Nick Benton, Andrew Kennedy, Sam Lindley and Claudio Russo.
25251 <link linkend="References_IFL">IFL</link> 2004.
25252 </simpara>
25253 <blockquote>
25254 <simpara>Describes a linear-time implementation of an
25255 <link linkend="References_AppelJim97">Appel-Jim shrinker</link>, using a mutable IL, and shows
25256 that it yields nice speedups in SML.NET&#8217;s compile times. There are
25257 also benchmarks showing that SML.NET when compiled by MLton runs
25258 roughly five times faster than when compiled by SML/NJ.</simpara>
25259 </blockquote>
25260 </listitem>
25261 <listitem>
25262 <simpara>
25263 <anchor id="References_Benton05" xreflabel="[References_Benton05]"/>
25264 <ulink url="http://research.microsoft.com/en-us/um/people/nick/benton03.pdf">Embedded Interpreters</ulink>.
25265 Nick Benton.
25266 <link linkend="References_JFP">JFP</link> 2005.
25267 </simpara>
25268 </listitem>
25269 <listitem>
25270 <simpara>
25271 <anchor id="References_Berry91" xreflabel="[References_Berry91]"/>
25272 <ulink url="http://www.lfcs.inf.ed.ac.uk/reports/91/ECS-LFCS-91-148/ECS-LFCS-91-148.pdf">The Edinburgh SML Library</ulink>.
25273 Dave Berry.
25274 University of Edinburgh Technical Report ECS-LFCS-91-148, 1991.
25275 </simpara>
25276 </listitem>
25277 <listitem>
25278 <simpara>
25279 <anchor id="References_BerryEtAl93" xreflabel="[References_BerryEtAl93]"/>
25280 <ulink url="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.36.7958&amp;rep=rep1&amp;type=ps">A semantics for ML concurrency primitives</ulink>.
25281 Dave Berry, Robin Milner, and David N. Turner.
25282 <link linkend="References_POPL">POPL</link> 1992.
25283 </simpara>
25284 </listitem>
25285 <listitem>
25286 <simpara>
25287 <anchor id="References_Berry93" xreflabel="[References_Berry93]"/>
25288 <ulink url="http://journals.cambridge.org/abstract_S0956796800000873">Lessons From the Design of a Standard ML Library</ulink>.
25289 Dave Berry.
25290 <link linkend="References_JFP">JFP</link> 1993.
25291 </simpara>
25292 </listitem>
25293 <listitem>
25294 <simpara>
25295 <anchor id="References_Bertelsen98" xreflabel="[References_Bertelsen98]"/>
25296 <ulink url="http://www.petermb.dk/sml2jvm.ps.gz">Compiling SML to Java Bytecode</ulink>.
25297 Peter Bertelsen.
25298 Master&#8217;s Thesis, 1998.
25299 </simpara>
25300 </listitem>
25301 <listitem>
25302 <simpara>
25303 <anchor id="References_Berthomieu00" xreflabel="[References_Berthomieu00]"/>
25304 <ulink url="http://homepages.laas.fr/bernard/oo/ooml.html">OO Programming styles in ML</ulink>.
25305 Bernard Berthomieu.
25306 LAAS Report #2000111, 2000.
25307 </simpara>
25308 </listitem>
25309 <listitem>
25310 <simpara>
25311 <anchor id="References_Blume01" xreflabel="[References_Blume01]"/>
25312 <ulink url="http://people.cs.uchicago.edu/~blume/papers/nlffi-entcs.pdf">No-Longer-Foreign: Teaching an ML compiler to speak C "natively"</ulink>.
25313 Matthias Blume.
25314 <link linkend="References_BABEL">BABEL</link> 2001.
25315 </simpara>
25316 </listitem>
25317 <listitem>
25318 <simpara>
25319 <anchor id="References_Blume01_02" xreflabel="[References_Blume01_02]"/>
25320 <ulink url="http://people.cs.uchicago.edu/~blume/pgraph/proposal.pdf">Portable library descriptions for Standard ML</ulink>.
25321 Matthias Blume. 2001.
25322 </simpara>
25323 </listitem>
25324 <listitem>
25325 <simpara>
25326 <anchor id="References_Boehm03" xreflabel="[References_Boehm03]"/>
25327 <ulink url="http://www.hpl.hp.com/techreports/2002/HPL-2002-335.html">Destructors, Finalizers, and Synchronization</ulink>.
25328 Hans Boehm.
25329 <link linkend="References_POPL">POPL</link> 2003.
25330 </simpara>
25331 <blockquote>
25332 <simpara>Discusses a number of issues in the design of finalizers. Many of the
25333 design choices are consistent with <link linkend="MLtonFinalizable">MLtonFinalizable</link>.</simpara>
25334 </blockquote>
25335 </listitem>
25336 </itemizedlist>
25337 </section>
25338 <section id="_anchor_id_references_ccc_xreflabel_references_ccc_c">
25339 <title><anchor id="References_CCC" xreflabel="[References_CCC]"/>C</title>
25340 <itemizedlist>
25341 <listitem>
25342 <simpara>
25343 <anchor id="References_CejtinEtAl00" xreflabel="[References_CejtinEtAl00]"/>
25344 <ulink url="http://www.cs.purdue.edu/homes/suresh/papers/icfp99.ps.gz">Flow-directed Closure Conversion for Typed Languages</ulink>.
25345 Henry Cejtin, Suresh Jagannathan, and Stephen Weeks.
25346 <link linkend="References_ESOP">ESOP</link> 2000.
25347 </simpara>
25348 <blockquote>
25349 <simpara>Describes MLton&#8217;s closure-conversion algorithm, which translates from
25350 its simply-typed higher-order intermediate language to its
25351 simply-typed first-order intermediate language.</simpara>
25352 </blockquote>
25353 </listitem>
25354 <listitem>
25355 <simpara>
25356 <anchor id="References_ChengBlelloch01" xreflabel="[References_ChengBlelloch01]"/>
25357 <ulink url="http://www.cs.cmu.edu/afs/cs/project/pscico/pscico/papers/gc01/pldi-final.pdf">A Parallel, Real-Time Garbage Collector</ulink>.
25358 Perry Cheng and Guy E. Blelloch.
25359 <link linkend="References_PLDI">PLDI</link> 2001.
25360 </simpara>
25361 </listitem>
25362 <listitem>
25363 <simpara>
25364 <anchor id="References_Claessen00" xreflabel="[References_Claessen00]"/>
25365 <ulink url="http://users.eecs.northwestern.edu/~robby/courses/395-495-2009-fall/quick.pdf">QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs</ulink>.
25366 Koen Claessen and John Hughes.
25367 <link linkend="References_ICFP">ICFP</link> 2000.
25368 </simpara>
25369 </listitem>
25370 <listitem>
25371 <simpara>
25372 <anchor id="References_Clinger98" xreflabel="[References_Clinger98]"/>
25373 <ulink url="http://www.cesura17.net/~will/Professional/Research/Papers/tail.pdf">Proper Tail Recursion and Space Efficiency</ulink>.
25374 William D. Clinger.
25375 <link linkend="References_PLDI">PLDI</link> 1998.
25376 </simpara>
25377 </listitem>
25378 <listitem>
25379 <simpara>
25380 <anchor id="References_CooperMorrisett90" xreflabel="[References_CooperMorrisett90]"/>
25381 <ulink url="http://www.eecs.harvard.edu/~greg/papers/jgmorris-mlthreads.ps">Adding Threads to Standard ML</ulink>.
25382 Eric C. Cooper and J. Gregory Morrisett.
25383 CMU Technical Report CMU-CS-90-186, 1990.
25384 </simpara>
25385 </listitem>
25386 <listitem>
25387 <simpara>
25388 <anchor id="References_CouttsEtAl07" xreflabel="[References_CouttsEtAl07]"/>
25389 <ulink url="http://metagraph.org/papers/stream_fusion.pdf">Stream Fusion: From Lists to Streams to Nothing at All</ulink>.
25390 Duncan Coutts, Roman Leshchinskiy, and Don Stewart.
25391 Submitted for publication. April 2007.
25392 </simpara>
25393 </listitem>
25394 </itemizedlist>
25395 </section>
25396 <section id="_anchor_id_references_ddd_xreflabel_references_ddd_d">
25397 <title><anchor id="References_DDD" xreflabel="[References_DDD]"/>D</title>
25398 <itemizedlist>
25399 <listitem>
25400 <simpara>
25401 <anchor id="References_DamasMilner82" xreflabel="[References_DamasMilner82]"/>
25402 <ulink url="http://groups.csail.mit.edu/pag/6.883/readings/p207-damas.pdf">Principal Type-Schemes for Functional Programs</ulink>.
25403 Luis Damas and Robin Milner.
25404 <link linkend="References_POPL">POPL</link> 1982.
25405 </simpara>
25406 </listitem>
25407 <listitem>
25408 <simpara>
25409 <anchor id="References_Danvy98" xreflabel="[References_Danvy98]"/>
25410 <ulink url="http://www.brics.dk/RS/98/12">Functional Unparsing</ulink>.
25411 Olivier Danvy.
25412 BRICS Technical Report RS 98-12, 1998.
25413 </simpara>
25414 </listitem>
25415 <listitem>
25416 <simpara>
25417 <anchor id="References_Deboer05" xreflabel="[References_Deboer05]"/>
25418 <ulink url="http://alleystoughton.us/eXene/dusty-thesis.pdf">Exhancements to eXene</ulink>.
25419 Dustin B. deBoer.
25420 Master of Science Thesis, 2005.
25421 </simpara>
25422 <blockquote>
25423 <simpara>Describes ways to improve widget concurrency, handling of input focus,
25424 X resources and selections.</simpara>
25425 </blockquote>
25426 </listitem>
25427 <listitem>
25428 <simpara>
25429 <anchor id="References_DoligezLeroy93" xreflabel="[References_DoligezLeroy93]"/>
25430 <ulink url="http://cristal.inria.fr/~doligez/publications/doligez-leroy-popl-1993.pdf">A Concurrent, Generational Garbage Collector for a Multithreaded Implementation of ML</ulink>.
25431 Damien Doligez and Xavier Leroy.
25432 <link linkend="References_POPL">POPL</link> 1993.
25433 </simpara>
25434 </listitem>
25435 <listitem>
25436 <simpara>
25437 <anchor id="References_Dreyer07" xreflabel="[References_Dreyer07]"/>
25438 <ulink url="http://www.mpi-sws.org/~dreyer/papers/mtc/main-long.pdf">Modular Type Classes</ulink>.
25439 Derek Dreyer, Robert Harper, Manuel M.T. Chakravarty, Gabriele Keller.
25440 University of Chicago Technical Report TR-2007-02, 2006.
25441 </simpara>
25442 </listitem>
25443 <listitem>
25444 <simpara>
25445 <anchor id="References_DreyerBlume07" xreflabel="[References_DreyerBlume07]"/>
25446 <ulink url="http://www.mpi-sws.org/~dreyer/papers/infmod/main-long.pdf">Principal Type Schemes for Modular Programs</ulink>.
25447 Derek Dreyer and Matthias Blume.
25448 <link linkend="References_ESOP">ESOP</link> 2007.
25449 </simpara>
25450 </listitem>
25451 <listitem>
25452 <simpara>
25453 <anchor id="References_Dubois95" xreflabel="[References_Dubois95]"/>
25454 <ulink url="ftp://ftp.inria.fr/INRIA/Projects/cristal/Francois.Rouaix/generics.dvi.Z">Extensional Polymorphism</ulink>.
25455 Catherin Dubois, Francois Rouaix, and Pierre Weis.
25456 <link linkend="References_POPL">POPL</link> 1995.
25457 </simpara>
25458 <blockquote>
25459 <simpara>An extension of ML that allows the definition of ad-hoc polymorphic
25460 functions by inspecting the type of their argument.</simpara>
25461 </blockquote>
25462 </listitem>
25463 </itemizedlist>
25464 </section>
25465 <section id="_anchor_id_references_eee_xreflabel_references_eee_e">
25466 <title><anchor id="References_EEE" xreflabel="[References_EEE]"/>E</title>
25467 <itemizedlist>
25468 <listitem>
25469 <simpara>
25470 <anchor id="References_Elsman03" xreflabel="[References_Elsman03]"/>
25471 <ulink url="http://www.elsman.com/tldi03.pdf">Garbage Collection Safety for Region-based Memory Management</ulink>.
25472 Martin Elsman.
25473 <link linkend="References_TLDI">TLDI</link> 2003.
25474 </simpara>
25475 </listitem>
25476 <listitem>
25477 <simpara>
25478 <anchor id="References_Elsman04" xreflabel="[References_Elsman04]"/>
25479 <ulink url="http://www.elsman.com/ITU-TR-2004-43.pdf">Type-Specialized Serialization with Sharing</ulink>.
25480 Martin Elsman. University of Copenhagen. IT University Technical
25481 Report TR-2004-43, 2004.
25482 </simpara>
25483 </listitem>
25484 </itemizedlist>
25485 </section>
25486 <section id="_anchor_id_references_fff_xreflabel_references_fff_f">
25487 <title><anchor id="References_FFF" xreflabel="[References_FFF]"/>F</title>
25488 <itemizedlist>
25489 <listitem>
25490 <simpara>
25491 <anchor id="References_FelleisenFreidman98" xreflabel="[References_FelleisenFreidman98]"/>
25492 <ulink url="http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&amp;tid=4787">The Little MLer</ulink>
25493 (<ulink url="http://www3.addall.com/New/submitNew.cgi?query=026256114X&amp;type=ISBN">addall</ulink>).
25494 ISBN 026256114X.
25495 Matthias Felleisen and Dan Freidman.
25496 The MIT Press, 1998.
25497 </simpara>
25498 </listitem>
25499 <listitem>
25500 <simpara>
25501 <anchor id="References_FlattFindler04" xreflabel="[References_FlattFindler04]"/>
25502 <ulink url="http://www.cs.utah.edu/plt/kill-safe/">Kill-Safe Synchronization Abstractions</ulink>.
25503 Matthew Flatt and Robert Bruce Findler.
25504 <link linkend="References_PLDI">PLDI</link> 2004.
25505 </simpara>
25506 </listitem>
25507 <listitem>
25508 <simpara>
25509 <anchor id="References_FluetWeeks01" xreflabel="[References_FluetWeeks01]"/>
25510 <ulink url="http://www.cs.rit.edu/~mtf/research/contification">Contification Using Dominators</ulink>.
25511 Matthew Fluet and Stephen Weeks.
25512 <link linkend="References_ICFP">ICFP</link> 2001.
25513 </simpara>
25514 <blockquote>
25515 <simpara>Describes contification, a generalization of tail-recursion
25516 elimination that is an optimization operating on MLton&#8217;s static single
25517 assignment (SSA) intermediate language.</simpara>
25518 </blockquote>
25519 </listitem>
25520 <listitem>
25521 <simpara>
25522 <anchor id="References_FluetPucella06" xreflabel="[References_FluetPucella06]"/>
25523 <ulink url="http://www.cs.rit.edu/~mtf/research/phantom-subtyping/jfp06/jfp06.pdf">Phantom Types and Subtyping</ulink>.
25524 Matthew Fluet and Riccardo Pucella.
25525 <link linkend="References_JFP">JFP</link> 2006.
25526 </simpara>
25527 </listitem>
25528 <listitem>
25529 <simpara>
25530 <anchor id="References_Furuse01" xreflabel="[References_Furuse01]"/>
25531 <ulink url="http://jfla.inria.fr/2001/actes/07-furuse.ps">Generic Polymorphism in ML</ulink>.
25532 J. Furuse.
25533 <link linkend="References_JFLA">JFLA</link> 2001.
25534 </simpara>
25535 <blockquote>
25536 <simpara>The formalism behind G&#8217;CAML, which has an approach to ad-hoc
25537 polymorphism based on <link linkend="References_Dubois95">Dubois95</link>, the differences being in how
25538 type checking works an an improved compilation approach for typecase
25539 that does the matching at compile time, not run time.</simpara>
25540 </blockquote>
25541 </listitem>
25542 </itemizedlist>
25543 </section>
25544 <section id="_anchor_id_references_ggg_xreflabel_references_ggg_g">
25545 <title><anchor id="References_GGG" xreflabel="[References_GGG]"/>G</title>
25546 <itemizedlist>
25547 <listitem>
25548 <simpara>
25549 <anchor id="References_GansnerReppy93" xreflabel="[References_GansnerReppy93]"/>
25550 <ulink url="http://alleystoughton.us/eXene/1993-trends.pdf">A Multi-Threaded Higher-order User Interface Toolkit</ulink>.
25551 Emden R. Gansner and John H. Reppy.
25552 User Interface Software, 1993.
25553 </simpara>
25554 </listitem>
25555 <listitem>
25556 <simpara>
25557 <anchor id="References_GansnerReppy04" xreflabel="[References_GansnerReppy04]"/>
25558 <ulink url="http://www.cambridge.org/gb/academic/subjects/computer-science/programming-languages-and-applied-logic/standard-ml-basis-library">The Standard ML Basis Library</ulink>.
25559 (<ulink url="http://www3.addall.com/New/submitNew.cgi?query=9780521794787&amp;type=ISBN">addall</ulink>)
25560 ISBN 9780521794787.
25561 Emden R. Gansner and John H. Reppy.
25562 Cambridge University Press, 2004.
25563 </simpara>
25564 <blockquote>
25565 <simpara>An introduction and overview of the <link linkend="BasisLibrary">Basis Library</link>,
25566 followed by a detailed description of each module. The module
25567 descriptions are also available
25568 <ulink url="http://www.standardml.org/Basis">online</ulink>.</simpara>
25569 </blockquote>
25570 </listitem>
25571 <listitem>
25572 <simpara>
25573 <anchor id="References_GrossmanEtAl02" xreflabel="[References_GrossmanEtAl02]"/>
25574 <ulink url="http://www.cs.umd.edu/projects/cyclone/papers/cyclone-regions.pdf">Region-based Memory Management in Cyclone</ulink>.
25575 Dan Grossman, Greg Morrisett, Trevor Jim, Michael Hicks, Yanling
25576 Wang, and James Cheney.
25577 <link linkend="References_PLDI">PLDI</link> 2002.
25578 </simpara>
25579 </listitem>
25580 </itemizedlist>
25581 </section>
25582 <section id="_anchor_id_references_hhh_xreflabel_references_hhh_h">
25583 <title><anchor id="References_HHH" xreflabel="[References_HHH]"/>H</title>
25584 <itemizedlist>
25585 <listitem>
25586 <simpara>
25587 <anchor id="References_HallenbergEtAl02" xreflabel="[References_HallenbergEtAl02]"/>
25588 <ulink url="http://www.itu.dk/people/tofte/publ/pldi2002.pdf">Combining Region Inference and Garbage Collection</ulink>.
25589 Niels Hallenberg, Martin Elsman, and Mads Tofte.
25590 <link linkend="References_PLDI">PLDI</link> 2002.
25591 </simpara>
25592 </listitem>
25593 <listitem>
25594 <simpara>
25595 <anchor id="References_HansenRichel99" xreflabel="[References_HansenRichel99]"/>
25596 <ulink url="http://www.it.dtu.dk/introSML">Introduction to Programming Using SML</ulink>
25597 (<ulink url="http://www3.addall.com/New/submitNew.cgi?query=0201398206&amp;type=ISBN">addall</ulink>).
25598 ISBN 0201398206.
25599 Michael R. Hansen, Hans Rischel.
25600 Addison-Wesley, 1999.
25601 </simpara>
25602 </listitem>
25603 <listitem>
25604 <simpara>
25605 <anchor id="References_Harper11" xreflabel="[References_Harper11]"/>
25606 <ulink url="http://www.cs.cmu.edu/~rwh/smlbook/book.pdf">Programming in Standard ML</ulink>.
25607 Robert Harper.
25608 </simpara>
25609 </listitem>
25610 <listitem>
25611 <simpara>
25612 <anchor id="References_HarperEtAl93" xreflabel="[References_HarperEtAl93]"/>
25613 <ulink url="http://www.cs.cmu.edu/~rwh/papers/callcc/jfp.pdf">Typing First-Class Continuations in ML</ulink>.
25614 Robert Harper, Bruce F. Duba, and David MacQueen.
25615 <link linkend="References_JFP">JFP</link> 1993.
25616 </simpara>
25617 </listitem>
25618 <listitem>
25619 <simpara>
25620 <anchor id="References_HarperMitchell92" xreflabel="[References_HarperMitchell92]"/>
25621 <ulink url="http://www.cs.cmu.edu/~rwh/papers/xml/toplas93.pdf">On the Type Structure of Standard ML</ulink>.
25622 Robert Harper and John C. Mitchell.
25623 <link linkend="References_TOPLAS">TOPLAS</link> 1992.
25624 </simpara>
25625 </listitem>
25626 <listitem>
25627 <simpara>
25628 <anchor id="References_HauserBenson04" xreflabel="[References_HauserBenson04]"/>
25629 <ulink url="http://doi.ieeecomputersociety.org/10.1109/CSD.2004.1309122">On the Practicality and Desirability of Highly-concurrent, Mostly-functional Programming</ulink>.
25630 Carl H. Hauser and David B. Benson.
25631 <link linkend="References_ACSD">ACSD</link> 2004.
25632 </simpara>
25633 <blockquote>
25634 <simpara>Describes the use of <link linkend="ConcurrentML">Concurrent ML</link> in implementing
25635 the Ped text editor. Argues that using large numbers of threads and
25636 message passing style is a practical and effective way of
25637 modularizing a program.</simpara>
25638 </blockquote>
25639 </listitem>
25640 <listitem>
25641 <simpara>
25642 <anchor id="References_HeckmanWilhelm97" xreflabel="[References_HeckmanWilhelm97]"/>
25643 <ulink url="http://rw4.cs.uni-sb.de/~heckmann/abstracts/neuform.html">A Functional Description of TeX&#8217;s Formula Layout</ulink>.
25644 Reinhold Heckmann and Reinhard Wilhelm.
25645 <link linkend="References_JFP">JFP</link> 1997.
25646 </simpara>
25647 </listitem>
25648 <listitem>
25649 <simpara>
25650 <anchor id="References_HicksEtAl03" xreflabel="[References_HicksEtAl03]"/>
25651 <ulink url="http://wwwold.cs.umd.edu/Library/TRs/CS-TR-4514/CS-TR-4514.pdf">Safe and Flexible Memory Management in Cyclone</ulink>.
25652 Mike Hicks, Greg Morrisett, Dan Grossman, and Trevor Jim.
25653 University of Maryland Technical Report CS-TR-4514, 2003.
25654 </simpara>
25655 </listitem>
25656 <listitem>
25657 <simpara>
25658 <anchor id="References_Hurd04" xreflabel="[References_Hurd04]"/>
25659 <ulink url="http://www.gilith.com/research/talks/tphols2004.pdf">Compiling HOL4 to Native Code</ulink>.
25660 Joe Hurd.
25661 <link linkend="References_TPHOLs">TPHOLs</link> 2004.
25662 </simpara>
25663 <blockquote>
25664 <simpara>Describes a port of HOL from Moscow ML to MLton, the difficulties
25665 encountered in compiling large programs, and the speedups achieved
25666 (roughly 10x).</simpara>
25667 </blockquote>
25668 </listitem>
25669 </itemizedlist>
25670 </section>
25671 <section id="_anchor_id_references_iii_xreflabel_references_iii_i">
25672 <title><anchor id="References_III" xreflabel="[References_III]"/>I</title>
25673 <simpara></simpara>
25674 </section>
25675 <section id="_anchor_id_references_jjj_xreflabel_references_jjj_j">
25676 <title><anchor id="References_JJJ" xreflabel="[References_JJJ]"/>J</title>
25677 <itemizedlist>
25678 <listitem>
25679 <simpara>
25680 <anchor id="References_Jones99" xreflabel="[References_Jones99]"/>
25681 <ulink url="http://www.cs.kent.ac.uk/people/staff/rej/gcbook">Garbage Collection: Algorithms for Automatic Memory Management</ulink>
25682 (<ulink url="http://www3.addall.com/New/submitNew.cgi?query=0471941484&amp;type=ISBN">addall</ulink>).
25683 ISBN 0471941484.
25684 Richard Jones.
25685 John Wiley &amp; Sons, 1999.
25686 </simpara>
25687 </listitem>
25688 </itemizedlist>
25689 </section>
25690 <section id="_anchor_id_references_kkk_xreflabel_references_kkk_k">
25691 <title><anchor id="References_KKK" xreflabel="[References_KKK]"/>K</title>
25692 <itemizedlist>
25693 <listitem>
25694 <simpara>
25695 <anchor id="References_Kahrs93" xreflabel="[References_Kahrs93]"/>
25696 <ulink url="http://kar.kent.ac.uk/21122/">Mistakes and Ambiguities in the Definition of Standard ML</ulink>.
25697 Stefan Kahrs.
25698 University of Edinburgh Technical Report ECS-LFCS-93-257, 1993.
25699 </simpara>
25700 <blockquote>
25701 <simpara>Describes a number of problems with the
25702 <link linkend="References_MilnerEtAl90">1990 Definition</link>, many of which were fixed in the
25703 <link linkend="References_MilnerEtAl97">1997 Definition</link>.</simpara>
25704 <simpara>Also see the <ulink url="http://www.cs.kent.ac.uk/~smk/errors-new.ps.Z">addenda</ulink>
25705 published in 1996.</simpara>
25706 </blockquote>
25707 </listitem>
25708 <listitem>
25709 <simpara>
25710 <anchor id="References_Karvonen07" xreflabel="[References_Karvonen07]"/>
25711 <ulink url="http://dl.acm.org/citation.cfm?doid=1292535.1292547">Generics for the Working ML&#8217;er</ulink>.
25712 Vesa Karvonen.
25713 <link linkend="References_ML">ML</link> 2007. <ulink url="http://research.microsoft.com/~crusso/ml2007/slides/ml08rp-karvonen-slides.pdf">Slides</ulink> from the presentation are also available.
25714 </simpara>
25715 </listitem>
25716 <listitem>
25717 <simpara>
25718 <anchor id="References_Kennedy04" xreflabel="[References_Kennedy04]"/>
25719 <ulink url="http://research.microsoft.com/~akenn/fun/picklercombinators.pdf">Pickler Combinators</ulink>.
25720 Andrew Kennedy.
25721 <link linkend="References_JFP">JFP</link> 2004.
25722 </simpara>
25723 </listitem>
25724 <listitem>
25725 <simpara>
25726 <anchor id="References_KoserEtAl03" xreflabel="[References_KoserEtAl03]"/>
25727 <ulink url="http://www.litech.org/~vaughan/pdf/dpcool2003.pdf">sml2java: A Source To Source Translator</ulink>.
25728 Justin Koser, Haakon Larsen, Jeffrey A. Vaughan.
25729 <link linkend="References_DPCOOL">DPCOOL</link> 2003.
25730 </simpara>
25731 </listitem>
25732 </itemizedlist>
25733 </section>
25734 <section id="_anchor_id_references_lll_xreflabel_references_lll_l">
25735 <title><anchor id="References_LLL" xreflabel="[References_LLL]"/>L</title>
25736 <itemizedlist>
25737 <listitem>
25738 <simpara>
25739 <anchor id="References_Lang99" xreflabel="[References_Lang99]"/>
25740 <ulink url="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.29.7130&amp;rep=rep1&amp;type=ps">Faster Algorithms for Finding Minimal Consistent DFAs</ulink>.
25741 Kevin Lang. 1999.
25742 </simpara>
25743 </listitem>
25744 <listitem>
25745 <simpara>
25746 <anchor id="References_LarsenNiss04" xreflabel="[References_LarsenNiss04]"/>
25747 <ulink url="http://usenix.org/publications/library/proceedings/usenix04/tech/freenix/full_papers/larsen/larsen.pdf">mGTK: An SML binding of Gtk+</ulink>.
25748 Ken Larsen and Henning Niss.
25749 USENIX Annual Technical Conference, 2004.
25750 </simpara>
25751 </listitem>
25752 <listitem>
25753 <simpara>
25754 <anchor id="References_Leibig13" xreflabel="[References_Leibig13]"/>
25755 <ulink url="http://www.cs.rit.edu/~bal6053/msproject/">An LLVM Back-end for MLton</ulink>.
25756 Brian Leibig.
25757 MS Project Report, 2013.
25758 </simpara>
25759 <blockquote>
25760 <simpara>Describes MLton&#8217;s <link linkend="LLVMCodegen">LLVMCodegen</link>.</simpara>
25761 </blockquote>
25762 </listitem>
25763 <listitem>
25764 <simpara>
25765 <anchor id="References_Leroy90" xreflabel="[References_Leroy90]"/>
25766 <ulink url="http://pauillac.inria.fr/~xleroy/bibrefs/Leroy-ZINC.html">The ZINC Experiment: an Economical Implementation of the ML Language</ulink>.
25767 Xavier Leroy.
25768 Technical report 117, INRIA, 1990.
25769 </simpara>
25770 <blockquote>
25771 <simpara>A detailed explanation of the design and implementation of a bytecode
25772 compiler and interpreter for ML with a machine model aimed at
25773 efficient implementation.</simpara>
25774 </blockquote>
25775 </listitem>
25776 <listitem>
25777 <simpara>
25778 <anchor id="References_Leroy93" xreflabel="[References_Leroy93]"/>
25779 <ulink url="http://pauillac.inria.fr/~xleroy/bibrefs/Leroy-poly-par-nom.html">Polymorphism by Name for References and Continuations</ulink>.
25780 Xavier Leroy.
25781 <link linkend="References_POPL">POPL</link> 1993.
25782 </simpara>
25783 </listitem>
25784 <listitem>
25785 <simpara>
25786 <anchor id="References_LeungGeorge99" xreflabel="[References_LeungGeorge99]"/>
25787 <ulink url="http://www.cs.nyu.edu/leunga/my-papers/annotations.ps">MLRISC Annotations</ulink>.
25788 Allen Leung and Lal George. 1999.
25789 </simpara>
25790 </listitem>
25791 </itemizedlist>
25792 </section>
25793 <section id="_anchor_id_references_mmm_xreflabel_references_mmm_m">
25794 <title><anchor id="References_MMM" xreflabel="[References_MMM]"/>M</title>
25795 <itemizedlist>
25796 <listitem>
25797 <simpara>
25798 <anchor id="References_MarlowEtAl01" xreflabel="[References_MarlowEtAl01]"/>
25799 <ulink url="http://community.haskell.org/~simonmar/papers/async.pdf">Asynchronous Exceptions in Haskell</ulink>.
25800 Simon Marlow, Simon Peyton Jones, Andy Moran and John Reppy.
25801 <link linkend="References_PLDI">PLDI</link> 2001.
25802 </simpara>
25803 <blockquote>
25804 <simpara>An asynchronous exception is a signal that one thread can send to
25805 another, and is useful for the receiving thread to treat as an
25806 exception so that it can clean up locks or other state relevant to its
25807 current context.</simpara>
25808 </blockquote>
25809 </listitem>
25810 <listitem>
25811 <simpara>
25812 <anchor id="References_MacQueenEtAl84" xreflabel="[References_MacQueenEtAl84]"/>
25813 <ulink url="http://homepages.inf.ed.ac.uk/gdp/publications/Ideal_model.pdf">An Ideal Model for Recursive Polymorphic Types</ulink>.
25814 David MacQueen, Gordon Plotkin, Ravi Sethi.
25815 <link linkend="References_POPL">POPL</link> 1984.
25816 </simpara>
25817 </listitem>
25818 <listitem>
25819 <simpara>
25820 <anchor id="References_Matthews91" xreflabel="[References_Matthews91]"/>
25821 <ulink url="http://www.lfcs.inf.ed.ac.uk/reports/91/ECS-LFCS-91-174">A Distributed Concurrent Implementation of Standard ML</ulink>.
25822 David Matthews.
25823 University of Edinburgh Technical Report ECS-LFCS-91-174, 1991.
25824 </simpara>
25825 </listitem>
25826 <listitem>
25827 <simpara>
25828 <anchor id="References_Matthews95" xreflabel="[References_Matthews95]"/>
25829 <ulink url="http://www.lfcs.inf.ed.ac.uk/reports/95/ECS-LFCS-95-335">Papers on Poly/ML</ulink>.
25830 David C. J. Matthews.
25831 University of Edinburgh Technical Report ECS-LFCS-95-335, 1995.
25832 </simpara>
25833 </listitem>
25834 <listitem>
25835 <simpara>
25836 <ulink url="http://www.lfcs.inf.ed.ac.uk/reports/97/ECS-LFCS-97-375">That About Wraps it Up: Using FIX to Handle Errors Without Exceptions, and Other Programming Tricks</ulink>.
25837 Bruce J. McAdam.
25838 University of Edinburgh Technical Report ECS-LFCS-97-375, 1997.
25839 </simpara>
25840 </listitem>
25841 <listitem>
25842 <simpara>
25843 <anchor id="References_MeierNorgaard93" xreflabel="[References_MeierNorgaard93]"/>
25844 A Just-In-Time Backend for Moscow ML 2.00 in SML.
25845 Bjarke Meier, Kristian Nørgaard.
25846 Masters Thesis, 2003.
25847 </simpara>
25848 <blockquote>
25849 <simpara>A just-in-time compiler using GNU Lightning, showing a speedup of up
25850 to four times over Moscow ML&#8217;s usual bytecode interpreter.</simpara>
25851 <simpara>The full report is only available in
25852 <ulink url="http://www.itu.dk/stud/speciale/bmkn/fundanemt/download/report">Danish</ulink>.</simpara>
25853 </blockquote>
25854 </listitem>
25855 <listitem>
25856 <simpara>
25857 <anchor id="References_Milner78" xreflabel="[References_Milner78]"/>
25858 <ulink url="http://courses.engr.illinois.edu/cs421/sp2013/project/milner-polymorphism.pdf">A Theory of Type Polymorphism in Programming</ulink>.
25859 Robin Milner.
25860 Journal of Computer and System Sciences, 1978.
25861 </simpara>
25862 </listitem>
25863 <listitem>
25864 <simpara>
25865 <anchor id="References_Milner82" xreflabel="[References_Milner82]"/>
25866 <ulink url="http://homepages.inf.ed.ac.uk/dts/fps/papers/evolved.dvi.gz">How ML Evolved</ulink>.
25867 Robin Milner.
25868 Polymorphism&#8212;The ML/LCF/Hope Newsletter, 1983.
25869 </simpara>
25870 </listitem>
25871 <listitem>
25872 <simpara>
25873 <anchor id="References_MilnerTofte91" xreflabel="[References_MilnerTofte91]"/>
25874 <ulink url="http://www.itu.dk/people/tofte/publ/1990sml/1990sml.html">Commentary on Standard ML</ulink>
25875 (<ulink url="http://www3.addall.com/New/submitNew.cgi?query=0262631377&amp;type=ISBN">addall</ulink>)
25876 ISBN 0262631377.
25877 Robin Milner and Mads Tofte.
25878 The MIT Press, 1991.
25879 </simpara>
25880 <blockquote>
25881 <simpara>Introduces and explains the notation and approach used in
25882 <link linkend="References_MilnerEtAl90">The Definition of Standard ML</link>.</simpara>
25883 </blockquote>
25884 </listitem>
25885 <listitem>
25886 <simpara>
25887 <anchor id="References_MilnerEtAl90" xreflabel="[References_MilnerEtAl90]"/>
25888 <ulink url="http://www.itu.dk/people/tofte/publ/1990sml/1990sml.html">The Definition of Standard ML</ulink>.
25889 (<ulink url="http://www3.addall.com/New/submitNew.cgi?query=0262631326&amp;type=ISBN">addall</ulink>)
25890 ISBN 0262631326.
25891 Robin Milner, Mads Tofte, and Robert Harper.
25892 The MIT Press, 1990.
25893 </simpara>
25894 <blockquote>
25895 <simpara>Superseded by <link linkend="References_MilnerEtAl97">The Definition of Standard ML (Revised)</link>.
25896 Accompanied by the <link linkend="References_MilnerTofte91">Commentary on Standard ML</link>.</simpara>
25897 </blockquote>
25898 </listitem>
25899 <listitem>
25900 <simpara>
25901 <anchor id="References_MilnerEtAl97" xreflabel="[References_MilnerEtAl97]"/>
25902 <ulink url="http://mitpress.mit.edu/books/definition-standard-ml">The Definition of Standard ML (Revised)</ulink>.
25903 (<ulink url="http://www3.addall.com/New/submitNew.cgi?query=0262631814&amp;type=ISBN">addall</ulink>)
25904 ISBN 0262631814.
25905 Robin Milner, Mads Tofte, Robert Harper, and David MacQueen.
25906 The MIT Press, 1997.
25907 </simpara>
25908 <blockquote>
25909 <simpara>A terse and formal specification of Standard ML&#8217;s syntax and
25910 semantics. Supersedes <link linkend="References_MilnerEtAl90">The Definition of Standard ML</link>.</simpara>
25911 </blockquote>
25912 </listitem>
25913 <listitem>
25914 <simpara>
25915 <anchor id="References_ML2000" xreflabel="[References_ML2000]"/>
25916 <ulink url="http://flint.cs.yale.edu/flint/publications/ml2000.html">Principles and a Preliminary Design for ML2000</ulink>.
25917 The ML2000 working group, 1999.
25918 </simpara>
25919 </listitem>
25920 <listitem>
25921 <simpara>
25922 <anchor id="References_Morentsen99" xreflabel="[References_Morentsen99]"/>
25923 <ulink url="http://daimi.au.dk/CPnets/workshop99/papers/Mortensen.pdf">Automatic Code Generation from Coloured Petri Nets for an Access Control System</ulink>.
25924 Kjeld H. Mortensen.
25925 Workshop on Practical Use of Coloured Petri Nets and Design/CPN, 1999.
25926 </simpara>
25927 </listitem>
25928 <listitem>
25929 <simpara>
25930 <anchor id="References_MorrisettTolmach93" xreflabel="[References_MorrisettTolmach93]"/>
25931 <ulink url="http://web.cecs.pdx.edu/~apt/ppopp93.ps">Procs and Locks: a Portable Multiprocessing Platform for Standard ML of New Jersey</ulink>.
25932 J. Gregory Morrisett and Andrew Tolmach.
25933 <link linkend="References_PPoPP">PPoPP</link> 1993.
25934 </simpara>
25935 </listitem>
25936 <listitem>
25937 <simpara>
25938 <anchor id="References_Murphy06" xreflabel="[References_Murphy06]"/>
25939 <ulink url="http://www.cs.cmu.edu/~tom7/papers/grid-ml06.pdf">ML Grid Programming with ConCert</ulink>.
25940 Tom Murphy VII.
25941 <link linkend="References_ML">ML</link> 2006.
25942 </simpara>
25943 </listitem>
25944 </itemizedlist>
25945 </section>
25946 <section id="_anchor_id_references_nnn_xreflabel_references_nnn_n">
25947 <title><anchor id="References_NNN" xreflabel="[References_NNN]"/>N</title>
25948 <itemizedlist>
25949 <listitem>
25950 <simpara>
25951 <anchor id="References_Neumann99" xreflabel="[References_Neumann99]"/>
25952 <ulink url="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.25.9485&amp;rep=rep1&amp;type=ps">fxp - Processing Structured Documents in SML</ulink>.
25953 Andreas Neumann.
25954 Scottish Functional Programming Workshop, 1999.
25955 </simpara>
25956 <blockquote>
25957 <simpara>Describes <ulink url="http://atseidl2.informatik.tu-muenchen.de/~berlea/Fxp">fxp</ulink>,
25958 an XML parser implemented in Standard ML.</simpara>
25959 </blockquote>
25960 </listitem>
25961 <listitem>
25962 <simpara>
25963 <anchor id="References_Neumann99Thesis" xreflabel="[References_Neumann99Thesis]"/>
25964 <ulink url="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.25.8108&amp;rep=rep1&amp;type=ps">Parsing and Querying XML Documents in SML</ulink>.
25965 Andreas Neumann.
25966 Doctoral Thesis, 1999.
25967 </simpara>
25968 </listitem>
25969 <listitem>
25970 <simpara>
25971 <anchor id="References_NguyenOhori06" xreflabel="[References_NguyenOhori06]"/>
25972 <ulink url="http://www.pllab.riec.tohoku.ac.jp/~ohori/research/NguyenOhoriPPDP06.pdf">Compiling ML Polymorphism with Explicit Layout Bitmap</ulink>.
25973 Huu-Duc Nguyen and Atsushi Ohori.
25974 <link linkend="References_PPDP">PPDP</link> 2006.
25975 </simpara>
25976 </listitem>
25977 </itemizedlist>
25978 </section>
25979 <section id="_anchor_id_references_ooo_xreflabel_references_ooo_o">
25980 <title><anchor id="References_OOO" xreflabel="[References_OOO]"/>O</title>
25981 <itemizedlist>
25982 <listitem>
25983 <simpara>
25984 <anchor id="References_Okasaki99" xreflabel="[References_Okasaki99]"/>
25985 <ulink url="http://www.cambridge.org/gb/academic/subjects/computer-science/programming-languages-and-applied-logic/purely-functional-data-structures">Purely Functional Data Structures</ulink>.
25986 ISBN 9780521663502.
25987 Chris Okasaki.
25988 Cambridge University Press, 1999.
25989 </simpara>
25990 </listitem>
25991 <listitem>
25992 <simpara>
25993 <anchor id="References_Ohori89" xreflabel="[References_Ohori89]"/>
25994 <ulink url="http://www.pllab.riec.tohoku.ac.jp/~ohori/research/fpca89.pdf">A Simple Semantics for ML Polymorphism</ulink>.
25995 Atsushi Ohori.
25996 <link linkend="References_FPCA">FPCA</link> 1989.
25997 </simpara>
25998 </listitem>
25999 <listitem>
26000 <simpara>
26001 <anchor id="References_Ohori95" xreflabel="[References_Ohori95]"/>
26002 <ulink url="http://www.pllab.riec.tohoku.ac.jp/~ohori/research/toplas95.pdf">A Polymorphic Record Calculus and Its Compilation</ulink>.
26003 Atsushi Ohori.
26004 <link linkend="References_TOPLAS">TOPLAS</link> 1995.
26005 </simpara>
26006 </listitem>
26007 <listitem>
26008 <simpara>
26009 <anchor id="References_OhoriTakamizawa97" xreflabel="[References_OhoriTakamizawa97]"/>
26010 <ulink url="http://www.pllab.riec.tohoku.ac.jp/~ohori/research/jlsc97.pdf">An Unboxed Operational Semantics for ML Polymorphism</ulink>.
26011 Atsushi Ohori and Tomonobu Takamizawa.
26012 <link linkend="References_LASC">LASC</link> 1997.
26013 </simpara>
26014 </listitem>
26015 <listitem>
26016 <simpara>
26017 <anchor id="References_Ohori99" xreflabel="[References_Ohori99]"/>
26018 <ulink url="http://www.pllab.riec.tohoku.ac.jp/~ohori/research/ic98.pdf">Type-Directed Specialization of Polymorphism</ulink>.
26019 Atsushi Ohori.
26020 <link linkend="References_IC">IC</link> 1999.
26021 </simpara>
26022 </listitem>
26023 <listitem>
26024 <simpara>
26025 <anchor id="References_OwensEtAl09" xreflabel="[References_OwensEtAl09]"/>
26026 <ulink url="http://www.mpi-sws.org/~turon/re-deriv.pdf">Regular-expression derivatives reexamined</ulink>.
26027 Scott Owens, John Reppy, and Aaron Turon.
26028 <link linkend="References_JFP">JFP</link> 2009.
26029 </simpara>
26030 </listitem>
26031 </itemizedlist>
26032 </section>
26033 <section id="_anchor_id_references_ppp_xreflabel_references_ppp_p">
26034 <title><anchor id="References_PPP" xreflabel="[References_PPP]"/>P</title>
26035 <itemizedlist>
26036 <listitem>
26037 <simpara>
26038 <anchor id="References_Paulson96" xreflabel="[References_Paulson96]"/>
26039 <ulink url="http://www.cambridge.org/co/academic/subjects/computer-science/programming-languages-and-applied-logic/ml-working-programmer-2nd-edition">ML For the Working Programmer</ulink>
26040 (<ulink url="http://www3.addall.com/New/submitNew.cgi?query=052156543X&amp;type=ISBN">addall</ulink>)
26041 ISBN 052156543X.
26042 Larry C. Paulson.
26043 Cambridge University Press, 1996.
26044 </simpara>
26045 </listitem>
26046 <listitem>
26047 <simpara>
26048 <anchor id="References_PetterssonEtAl02" xreflabel="[References_PetterssonEtAl02]"/>
26049 <ulink url="http://user.it.uu.se/~kostis/Papers/flops02_22.ps.gz">The HiPE/x86 Erlang Compiler: System Description and Performance Evaluation</ulink>.
26050 Mikael Pettersson, Konstantinos Sagonas, and Erik Johansson.
26051 <link linkend="References_FLOPS">FLOPS</link> 2002.
26052 </simpara>
26053 <blockquote>
26054 <simpara>Describes a native x86 Erlang compiler and a comparison of many
26055 different native x86 compilers (including MLton) and their register
26056 usage and call stack implementations.</simpara>
26057 </blockquote>
26058 </listitem>
26059 <listitem>
26060 <simpara>
26061 <anchor id="References_Price09" xreflabel="[References_Price09]"/>
26062 <ulink url="http://rogerprice.org/#UG">User&#8217;s Guide to ML-Lex and ML-Yacc</ulink>
26063 Roger Price. 2009.
26064 </simpara>
26065 </listitem>
26066 <listitem>
26067 <simpara>
26068 <anchor id="References_Pucella98" xreflabel="[References_Pucella98]"/>
26069 <ulink url="http://arxiv.org/abs/cs.PL/0405080">Reactive Programming in Standard ML</ulink>.
26070 Riccardo R. Puccella. 1998.
26071 <link linkend="References_ICCL">ICCL</link> 1998.
26072 </simpara>
26073 </listitem>
26074 </itemizedlist>
26075 </section>
26076 <section id="_anchor_id_references_qqq_xreflabel_references_qqq_q">
26077 <title><anchor id="References_QQQ" xreflabel="[References_QQQ]"/>Q</title>
26078 <simpara></simpara>
26079 </section>
26080 <section id="_anchor_id_references_rrr_xreflabel_references_rrr_r">
26081 <title><anchor id="References_RRR" xreflabel="[References_RRR]"/>R</title>
26082 <itemizedlist>
26083 <listitem>
26084 <simpara>
26085 <anchor id="References_Ramsey90" xreflabel="[References_Ramsey90]"/>
26086 <ulink url="https://www.cs.princeton.edu/research/techreps/TR-262-90">Concurrent Programming in ML</ulink>.
26087 Norman Ramsey.
26088 Princeton University Technical Report CS-TR-262-90, 1990.
26089 </simpara>
26090 </listitem>
26091 <listitem>
26092 <simpara>
26093 <anchor id="References_Ramsey11" xreflabel="[References_Ramsey11]"/>
26094 <ulink url="http://www.cs.tufts.edu/~nr/pubs/embedj-abstract.html">Embedding an Interpreted Language Using Higher-Order Functions and Types</ulink>.
26095 Norman Ramsey.
26096 <link linkend="References_JFP">JFP</link> 2011.
26097 </simpara>
26098 </listitem>
26099 <listitem>
26100 <simpara>
26101 <anchor id="References_RamseyFisherGovereau05" xreflabel="[References_RamseyFisherGovereau05]"/>
26102 <ulink url="http://www.cs.tufts.edu/~nr/pubs/els-abstract.html">An Expressive Language of Signatures</ulink>.
26103 Norman Ramsey, Kathleen Fisher, and Paul Govereau.
26104 <link linkend="References_ICFP">ICFP</link> 2005.
26105 </simpara>
26106 </listitem>
26107 <listitem>
26108 <simpara>
26109 <anchor id="References_RedwineRamsey04" xreflabel="[References_RedwineRamsey04]"/>
26110 <ulink url="http://www.cs.tufts.edu/~nr/pubs/widen-abstract.html">Widening Integer Arithmetic</ulink>.
26111 Kevin Redwine and Norman Ramsey.
26112 <link linkend="References_CC">CC</link> 2004.
26113 </simpara>
26114 <blockquote>
26115 <simpara>Describes a method to implement numeric types and operations (like
26116 <literal>Int31</literal> or <literal>Word17</literal>) for sizes smaller than that provided by the
26117 processor.</simpara>
26118 </blockquote>
26119 </listitem>
26120 <listitem>
26121 <simpara>
26122 <anchor id="References_Reppy88" xreflabel="[References_Reppy88]"/>
26123 Synchronous Operations as First-Class Values.
26124 John Reppy.
26125 <link linkend="References_PLDI">PLDI</link> 1988.
26126 </simpara>
26127 </listitem>
26128 <listitem>
26129 <simpara>
26130 <anchor id="References_Reppy07" xreflabel="[References_Reppy07]"/>
26131 <ulink url="http://www.cambridge.org/co/academic/subjects/computer-science/distributed-networked-and-mobile-computing/concurrent-programming-ml">Concurrent Programming in ML</ulink>
26132 (<ulink url="http://www3.addall.com/New/submitNew.cgi?query=9780521714723&amp;type=ISBN">addall</ulink>).
26133 ISBN 9780521714723.
26134 John Reppy.
26135 Cambridge University Press, 2007.
26136 </simpara>
26137 <blockquote>
26138 <simpara>Describes <link linkend="ConcurrentML">ConcurrentML</link>.</simpara>
26139 </blockquote>
26140 </listitem>
26141 <listitem>
26142 <simpara>
26143 <anchor id="References_Reynolds98" xreflabel="[References_Reynolds98]"/>
26144 <ulink url="https://users-cs.au.dk/hosc/local/HOSC-11-4-pp355-361.pdf">Definitional Interpreters Revisited</ulink>.
26145 John C. Reynolds.
26146 <link linkend="References_HOSC">HOSC</link> 1998.
26147 </simpara>
26148 </listitem>
26149 <listitem>
26150 <simpara>
26151 <anchor id="References_Reynolds98_2" xreflabel="[References_Reynolds98_2]"/>
26152 <ulink url="https://users-cs.au.dk/hosc/local/HOSC-11-4-pp363-397.pdf">Definitional Interpreters for Higher-Order Programming Languages</ulink>
26153 John C. Reynolds.
26154 <link linkend="References_HOSC">HOSC</link> 1998.
26155 </simpara>
26156 </listitem>
26157 <listitem>
26158 <simpara>
26159 <anchor id="References_Rossberg01" xreflabel="[References_Rossberg01]"/>
26160 <ulink url="http://www.mpi-sws.org/~rossberg/papers/Rossberg%20-%20Defects%20in%20the%20Revised%20Definition%20of%20Standard%20ML%20%5B2007-01-22%20Update%5D.pdf">Defects in the Revised Definition of Standard ML</ulink>.
26161 Andreas Rossberg. 2001.
26162 </simpara>
26163 </listitem>
26164 </itemizedlist>
26165 </section>
26166 <section id="_anchor_id_references_sss_xreflabel_references_sss_s">
26167 <title><anchor id="References_SSS" xreflabel="[References_SSS]"/>S</title>
26168 <itemizedlist>
26169 <listitem>
26170 <simpara>
26171 <anchor id="References_Sansom91" xreflabel="[References_Sansom91]"/>
26172 <ulink url="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.24.1020&amp;rep=rep1&amp;type=ps">Dual-Mode Garbage Collection</ulink>.
26173 Patrick M. Sansom.
26174 Workshop on the Parallel Implementation of Functional Languages, 1991.
26175 </simpara>
26176 </listitem>
26177 <listitem>
26178 <simpara>
26179 <anchor id="References_ScottRamsey00" xreflabel="[References_ScottRamsey00]"/>
26180 <ulink url="http://www.cs.tufts.edu/~nr/pubs/match-abstract.html">When Do Match-Compilation Heuristics Matter</ulink>.
26181 Kevin Scott and Norman Ramsey.
26182 University of Virginia Technical Report CS-2000-13, 2000.
26183 </simpara>
26184 <blockquote>
26185 <simpara>Modified SML/NJ to experimentally compare a number of
26186 match-compilation heuristics and showed that choice of heuristic
26187 usually does not significantly affect code size or run time.</simpara>
26188 </blockquote>
26189 </listitem>
26190 <listitem>
26191 <simpara>
26192 <anchor id="References_Sestoft96" xreflabel="[References_Sestoft96]"/>
26193 <ulink url="http://www.itu.dk/~sestoft/papers/match.ps.gz">ML Pattern Match Compilation and Partial Evaluation</ulink>.
26194 Peter Sestoft.
26195 Partial Evaluation, 1996.
26196 </simpara>
26197 <blockquote>
26198 <simpara>Describes the derivation of the match compiler used in
26199 <link linkend="MoscowML">Moscow ML</link>.</simpara>
26200 </blockquote>
26201 </listitem>
26202 <listitem>
26203 <simpara>
26204 <anchor id="References_ShaoAppel94" xreflabel="[References_ShaoAppel94]"/>
26205 <ulink url="http://flint.cs.yale.edu/flint/publications/closure.html">Space-Efficient Closure Representations</ulink>.
26206 Zhong Shao and Andrew W. Appel.
26207 <link linkend="References_LFP">LFP</link> 1994.
26208 </simpara>
26209 </listitem>
26210 <listitem>
26211 <simpara>
26212 <anchor id="References_Shipman02" xreflabel="[References_Shipman02]"/>
26213 <ulink url="guide/References.attachments/Shipman02.pdf">Unix System Programming with Standard ML</ulink>.
26214 Anthony L. Shipman.
26215 2002.
26216 </simpara>
26217 <blockquote>
26218 <simpara>Includes a description of the <link linkend="Swerve">Swerve</link> HTTP server written in SML.</simpara>
26219 </blockquote>
26220 </listitem>
26221 <listitem>
26222 <simpara>
26223 <anchor id="References_Signoles03" xreflabel="[References_Signoles03]"/>
26224 Calcul Statique des Applications de Modules Parametres.
26225 Julien Signoles.
26226 <link linkend="References_JFLA">JFLA</link> 2003.
26227 </simpara>
26228 <blockquote>
26229 <simpara>Describes a <ulink url="http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=382">defunctorizer</ulink>
26230 for OCaml, and compares it to existing defunctorizers, including MLton.</simpara>
26231 </blockquote>
26232 </listitem>
26233 <listitem>
26234 <simpara>
26235 <anchor id="References_SittampalamEtAl04" xreflabel="[References_SittampalamEtAl04]"/>
26236 <ulink url="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.4.1349&amp;rep=rep1&amp;type=ps">Incremental Execution of Transformation Specifications</ulink>.
26237 Ganesh Sittampalam, Oege de Moor, and Ken Friis Larsen.
26238 <link linkend="References_POPL">POPL</link> 2004.
26239 </simpara>
26240 <blockquote>
26241 <simpara>Mentions a port from Moscow ML to MLton of
26242 <ulink url="http://www.itu.dk/research/muddy/">MuDDY</ulink>, an SML wrapper around the
26243 <ulink url="http://sourceforge.net/projects/buddy">BuDDY</ulink> BDD package.</simpara>
26244 </blockquote>
26245 </listitem>
26246 <listitem>
26247 <simpara>
26248 <anchor id="References_SwaseyEtAl06" xreflabel="[References_SwaseyEtAl06]"/>
26249 <ulink url="http://www.cs.cmu.edu/~tom7/papers/smlsc2-ml06.pdf">A Separate Compilation Extension to Standard ML</ulink>.
26250 David Swasey, Tom Murphy VII, Karl Crary and Robert Harper.
26251 <link linkend="References_ML">ML</link> 2006.
26252 </simpara>
26253 </listitem>
26254 </itemizedlist>
26255 </section>
26256 <section id="_anchor_id_references_ttt_xreflabel_references_ttt_t">
26257 <title><anchor id="References_TTT" xreflabel="[References_TTT]"/>T</title>
26258 <itemizedlist>
26259 <listitem>
26260 <simpara>
26261 <anchor id="References_TarditiAppel00" xreflabel="[References_TarditiAppel00]"/>
26262 <ulink url="http://www.smlnj.org/doc/ML-Yacc/index.html">ML-Yacc User&#8217;s Manual. Version 2.4</ulink>
26263 David R. Tarditi and Andrew W. Appel. 2000.
26264 </simpara>
26265 </listitem>
26266 <listitem>
26267 <simpara>
26268 <anchor id="References_TarditiEtAl90" xreflabel="[References_TarditiEtAl90]"/>
26269 <ulink url="http://research.microsoft.com/pubs/68738/loplas-sml2c.ps">No Assembly Required: Compiling Standard ML to C</ulink>.
26270 David Tarditi, Peter Lee, and Anurag Acharya. 1990.
26271 </simpara>
26272 </listitem>
26273 <listitem>
26274 <simpara>
26275 <anchor id="References_ThorupTofte94" xreflabel="[References_ThorupTofte94]"/>
26276 <ulink url="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.53.5372&amp;rep=rep1&amp;type=ps">Object-oriented programming and Standard ML</ulink>.
26277 Lars Thorup and Mads Tofte.
26278 <link linkend="References_ML">ML</link>, 1994.
26279 </simpara>
26280 </listitem>
26281 <listitem>
26282 <simpara>
26283 <anchor id="References_Tofte90" xreflabel="[References_Tofte90]"/>
26284 Type Inference for Polymorphic References.
26285 Mads Tofte.
26286 <link linkend="References_IC">IC</link> 1990.
26287 </simpara>
26288 </listitem>
26289 <listitem>
26290 <simpara>
26291 <anchor id="References_Tofte96" xreflabel="[References_Tofte96]"/>
26292 <ulink url="http://www.itu.dk/courses/FDP/E2004/Tofte-1996-Essentials_of_SML_Modules.pdf">Essentials of Standard ML Modules</ulink>.
26293 Mads Tofte.
26294 </simpara>
26295 </listitem>
26296 <listitem>
26297 <simpara>
26298 <anchor id="References_Tofte09" xreflabel="[References_Tofte09]"/>
26299 <ulink url="http://www.itu.dk/people/tofte/publ/tips.pdf">Tips for Computer Scientists on Standard ML (Revised)</ulink>.
26300 Mads Tofte.
26301 </simpara>
26302 </listitem>
26303 <listitem>
26304 <simpara>
26305 <anchor id="References_TolmachAppel95" xreflabel="[References_TolmachAppel95]"/>
26306 <ulink url="http://web.cecs.pdx.edu/~apt/jfp95.ps">A Debugger for Standard ML</ulink>.
26307 Andrew Tolmach and Andrew W. Appel.
26308 <link linkend="References_JFP">JFP</link> 1995.
26309 </simpara>
26310 </listitem>
26311 <listitem>
26312 <simpara>
26313 <anchor id="References_Tolmach97" xreflabel="[References_Tolmach97]"/>
26314 <ulink url="http://web.cecs.pdx.edu/~apt/tic97.ps">Combining Closure Conversion with Closure Analysis using Algebraic Types</ulink>.
26315 Andrew Tolmach.
26316 <link linkend="References_TIC">TIC</link> 1997.
26317 </simpara>
26318 <blockquote>
26319 <simpara>Describes a closure-conversion algorithm for a monomorphic IL. The
26320 algorithm uses a unification-based flow analysis followed by
26321 defunctionalization and is similar to the approach used in MLton
26322 (<link linkend="References_CejtinEtAl00">CejtinEtAl00</link>).</simpara>
26323 </blockquote>
26324 </listitem>
26325 <listitem>
26326 <simpara>
26327 <anchor id="References_TolmachOliva98" xreflabel="[References_TolmachOliva98]"/>
26328 <ulink url="http://web.cecs.pdx.edu/~apt/jfp98.ps">From ML to Ada: Strongly-typed Language Interoperability via Source Translation</ulink>.
26329 Andrew Tolmach and Dino Oliva.
26330 <link linkend="References_JFP">JFP</link> 1998.
26331 </simpara>
26332 <blockquote>
26333 <simpara>Describes a compiler for RML, a core SML-like language. The compiler
26334 is similar in structure to MLton, using monomorphisation,
26335 defunctionalization, and optimization on a first-order IL.</simpara>
26336 </blockquote>
26337 </listitem>
26338 </itemizedlist>
26339 </section>
26340 <section id="_anchor_id_references_uuu_xreflabel_references_uuu_u">
26341 <title><anchor id="References_UUU" xreflabel="[References_UUU]"/>U</title>
26342 <itemizedlist>
26343 <listitem>
26344 <simpara>
26345 <anchor id="References_Ullman98" xreflabel="[References_Ullman98]"/>
26346 <ulink url="http://www-db.stanford.edu/~ullman/emlp.html">Elements of ML Programming</ulink>
26347 (<ulink url="http://www3.addall.com/New/submitNew.cgi?query=0137903871&amp;type=ISBN">addall</ulink>).
26348 ISBN 0137903871.
26349 Jeffrey D. Ullman.
26350 Prentice-Hall, 1998.
26351 </simpara>
26352 </listitem>
26353 </itemizedlist>
26354 </section>
26355 <section id="_anchor_id_references_vvv_xreflabel_references_vvv_v">
26356 <title><anchor id="References_VVV" xreflabel="[References_VVV]"/>V</title>
26357 <simpara></simpara>
26358 </section>
26359 <section id="_anchor_id_references_www_xreflabel_references_www_w">
26360 <title><anchor id="References_WWW" xreflabel="[References_WWW]"/>W</title>
26361 <itemizedlist>
26362 <listitem>
26363 <simpara>
26364 <anchor id="References_Wand84" xreflabel="[References_Wand84]"/>
26365 <ulink url="http://portal.acm.org/citation.cfm?id=800527">A Types-as-Sets Semantics for Milner-Style Polymorphism</ulink>.
26366 Mitchell Wand.
26367 <link linkend="References_POPL">POPL</link> 1984.
26368 </simpara>
26369 </listitem>
26370 <listitem>
26371 <simpara>
26372 <anchor id="References_Wang01" xreflabel="[References_Wang01]"/>
26373 <ulink url="http://ncstrl.cs.princeton.edu/expand.php?id=TR-640-01">Managing Memory with Types</ulink>.
26374 Daniel C. Wang.
26375 PhD Thesis.
26376 </simpara>
26377 <blockquote>
26378 <simpara>Chapter 6 describes an implementation of a type-preserving garbage
26379 collector for MLton.</simpara>
26380 </blockquote>
26381 </listitem>
26382 <listitem>
26383 <simpara>
26384 <anchor id="References_WangAppel01" xreflabel="[References_WangAppel01]"/>
26385 <ulink url="http://www.cs.princeton.edu/~appel/papers/typegc.pdf">Type-Preserving Garbage Collectors</ulink>.
26386 Daniel C. Wang and Andrew W. Appel.
26387 <link linkend="References_POPL">POPL</link> 2001.
26388 </simpara>
26389 <blockquote>
26390 <simpara>Shows how to modify MLton to generate a strongly-typed garbage
26391 collector as part of a program.</simpara>
26392 </blockquote>
26393 </listitem>
26394 <listitem>
26395 <simpara>
26396 <anchor id="References_WangMurphy02" xreflabel="[References_WangMurphy02]"/>
26397 <ulink url="http://www.cs.cmu.edu/~tom7/papers/wang-murphy-recursion.pdf">Programming With Recursion Schemes</ulink>.
26398 Daniel C. Wang and Tom Murphy VII.
26399 </simpara>
26400 <blockquote>
26401 <simpara>Describes a programming technique for data abstraction, along with
26402 benchmarks of MLton and other SML compilers.</simpara>
26403 </blockquote>
26404 </listitem>
26405 <listitem>
26406 <simpara>
26407 <anchor id="References_Weeks06" xreflabel="[References_Weeks06]"/>
26408 <ulink url="guide/References.attachments/060916-mlton.pdf">Whole-Program Compilation in MLton</ulink>.
26409 Stephen Weeks.
26410 <link linkend="References_ML">ML</link> 2006.
26411 </simpara>
26412 </listitem>
26413 <listitem>
26414 <simpara>
26415 <anchor id="References_Wright95" xreflabel="[References_Wright95]"/>
26416 <ulink url="http://homepages.inf.ed.ac.uk/dts/fps/papers/wright.ps.gz">Simple Imperative Polymorphism</ulink>.
26417 Andrew Wright.
26418 <link linkend="References_LASC">LASC</link>, 8(4):343-355, 1995.
26419 </simpara>
26420 <blockquote>
26421 <simpara>The origin of the <link linkend="ValueRestriction">ValueRestriction</link>.</simpara>
26422 </blockquote>
26423 </listitem>
26424 </itemizedlist>
26425 </section>
26426 <section id="_anchor_id_references_xxx_xreflabel_references_xxx_x">
26427 <title><anchor id="References_XXX" xreflabel="[References_XXX]"/>X</title>
26428 <simpara></simpara>
26429 </section>
26430 <section id="_anchor_id_references_yyy_xreflabel_references_yyy_y">
26431 <title><anchor id="References_YYY" xreflabel="[References_YYY]"/>Y</title>
26432 <itemizedlist>
26433 <listitem>
26434 <simpara>
26435 <anchor id="References_Yang98" xreflabel="[References_Yang98]"/>
26436 <ulink url="http://cs.nyu.edu/zheyang/papers/YangZ--ICFP98.html">Encoding Types in ML-like Languages</ulink>.
26437 Zhe Yang.
26438 <link linkend="References_ICFP">ICFP</link> 1998.
26439 </simpara>
26440 </listitem>
26441 </itemizedlist>
26442 </section>
26443 <section id="_anchor_id_references_zzz_xreflabel_references_zzz_z">
26444 <title><anchor id="References_ZZZ" xreflabel="[References_ZZZ]"/>Z</title>
26445 <itemizedlist>
26446 <listitem>
26447 <simpara>
26448 <anchor id="References_ZiarekEtAl06" xreflabel="[References_ZiarekEtAl06]"/>
26449 <ulink url="http://www.cs.purdue.edu/homes/lziarek/icfp06.pdf">Stabilizers: A Modular Checkpointing Abstraction for Concurrent Functional Programs</ulink>.
26450 Lukasz Ziarek, Philip Schatz, and Suresh Jagannathan.
26451 <link linkend="References_ICFP">ICFP</link> 2006.
26452 </simpara>
26453 </listitem>
26454 <listitem>
26455 <simpara>
26456 <anchor id="References_ZiarekEtAl08" xreflabel="[References_ZiarekEtAl08]"/>
26457 <ulink url="http://www.cse.buffalo.edu/~lziarek/hosc.pdf">Flattening tuples in an SSA intermediate representation</ulink>.
26458 Lukasz Ziarek, Stephen Weeks, and Suresh Jagannathan.
26459 <link linkend="References_HOSC">HOSC</link> 2008.
26460 </simpara>
26461 </listitem>
26462 </itemizedlist>
26463 </section>
26464 <section id="_abbreviations">
26465 <title>Abbreviations</title>
26466 <itemizedlist>
26467 <listitem>
26468 <simpara>
26469 <anchor id="References_ACSD" xreflabel="[References_ACSD]"/> ACSD = International Conference on Application of Concurrency to System Design
26470 </simpara>
26471 </listitem>
26472 <listitem>
26473 <simpara>
26474 <anchor id="References_BABEL" xreflabel="[References_BABEL]"/> BABEL = Workshop on multi-language infrastructure and interoperability
26475 </simpara>
26476 </listitem>
26477 <listitem>
26478 <simpara>
26479 <anchor id="References_CC" xreflabel="[References_CC]"/> CC = International Conference on Compiler Construction
26480 </simpara>
26481 </listitem>
26482 <listitem>
26483 <simpara>
26484 <anchor id="References_DPCOOL" xreflabel="[References_DPCOOL]"/> DPCOOL = Workshop on Declarative Programming in the Context of OO Languages
26485 </simpara>
26486 </listitem>
26487 <listitem>
26488 <simpara>
26489 <anchor id="References_ESOP" xreflabel="[References_ESOP]"/> ESOP = European Symposium on Programming
26490 </simpara>
26491 </listitem>
26492 <listitem>
26493 <simpara>
26494 <anchor id="References_FLOPS" xreflabel="[References_FLOPS]"/> FLOPS = Symposium on Functional and Logic Programming
26495 </simpara>
26496 </listitem>
26497 <listitem>
26498 <simpara>
26499 <anchor id="References_FPCA" xreflabel="[References_FPCA]"/> FPCA = Conference on Functional Programming Languages and Computer Architecture
26500 </simpara>
26501 </listitem>
26502 <listitem>
26503 <simpara>
26504 <anchor id="References_HOSC" xreflabel="[References_HOSC]"/> HOSC = Higher-Order and Symbolic Computation
26505 </simpara>
26506 </listitem>
26507 <listitem>
26508 <simpara>
26509 <anchor id="References_IC" xreflabel="[References_IC]"/> IC = Information and Computation
26510 </simpara>
26511 </listitem>
26512 <listitem>
26513 <simpara>
26514 <anchor id="References_ICCL" xreflabel="[References_ICCL]"/> ICCL = IEEE International Conference on Computer Languages
26515 </simpara>
26516 </listitem>
26517 <listitem>
26518 <simpara>
26519 <anchor id="References_ICFP" xreflabel="[References_ICFP]"/> ICFP = International Conference on Functional Programming
26520 </simpara>
26521 </listitem>
26522 <listitem>
26523 <simpara>
26524 <anchor id="References_IFL" xreflabel="[References_IFL]"/> IFL = International Workshop on Implementation and Application of Functional Languages
26525 </simpara>
26526 </listitem>
26527 <listitem>
26528 <simpara>
26529 <anchor id="References_IVME" xreflabel="[References_IVME]"/> IVME = Workshop on Interpreters, Virtual Machines and Emulators
26530 </simpara>
26531 </listitem>
26532 <listitem>
26533 <simpara>
26534 <anchor id="References_JFLA" xreflabel="[References_JFLA]"/> JFLA = Journees Francophones des Langages Applicatifs
26535 </simpara>
26536 </listitem>
26537 <listitem>
26538 <simpara>
26539 <anchor id="References_JFP" xreflabel="[References_JFP]"/> JFP = Journal of Functional Programming
26540 </simpara>
26541 </listitem>
26542 <listitem>
26543 <simpara>
26544 <anchor id="References_LASC" xreflabel="[References_LASC]"/> LASC = Lisp and Symbolic Computation
26545 </simpara>
26546 </listitem>
26547 <listitem>
26548 <simpara>
26549 <anchor id="References_LFP" xreflabel="[References_LFP]"/> LFP = Lisp and Functional Programming
26550 </simpara>
26551 </listitem>
26552 <listitem>
26553 <simpara>
26554 <anchor id="References_ML" xreflabel="[References_ML]"/> ML = Workshop on ML
26555 </simpara>
26556 </listitem>
26557 <listitem>
26558 <simpara>
26559 <anchor id="References_PLDI" xreflabel="[References_PLDI]"/> PLDI = Conference on Programming Language Design and Implementation
26560 </simpara>
26561 </listitem>
26562 <listitem>
26563 <simpara>
26564 <anchor id="References_POPL" xreflabel="[References_POPL]"/> POPL = Symposium on Principles of Programming Languages
26565 </simpara>
26566 </listitem>
26567 <listitem>
26568 <simpara>
26569 <anchor id="References_PPDP" xreflabel="[References_PPDP]"/> PPDP = International Conference on Principles and Practice of Declarative Programming
26570 </simpara>
26571 </listitem>
26572 <listitem>
26573 <simpara>
26574 <anchor id="References_PPoPP" xreflabel="[References_PPoPP]"/> PPoPP = Principles and Practice of Parallel Programming
26575 </simpara>
26576 </listitem>
26577 <listitem>
26578 <simpara>
26579 <anchor id="References_TCS" xreflabel="[References_TCS]"/> TCS = IFIP International Conference on Theoretical Computer Science
26580 </simpara>
26581 </listitem>
26582 <listitem>
26583 <simpara>
26584 <anchor id="References_TIC" xreflabel="[References_TIC]"/> TIC = Types in Compilation
26585 </simpara>
26586 </listitem>
26587 <listitem>
26588 <simpara>
26589 <anchor id="References_TLDI" xreflabel="[References_TLDI]"/> TLDI = Workshop on Types in Language Design and Implementation
26590 </simpara>
26591 </listitem>
26592 <listitem>
26593 <simpara>
26594 <anchor id="References_TOPLAS" xreflabel="[References_TOPLAS]"/> TOPLAS = Transactions on Programming Languages and Systems
26595 </simpara>
26596 </listitem>
26597 <listitem>
26598 <simpara>
26599 <anchor id="References_TPHOLs" xreflabel="[References_TPHOLs]"/> TPHOLs = International Conference on Theorem Proving in Higher Order Logics
26600 </simpara>
26601 </listitem>
26602 </itemizedlist>
26603 <simpara><?asciidoc-pagebreak?></simpara>
26604 </section>
26605 </section>
26606 <section id="RefFlatten">
26607 <title>RefFlatten</title>
26608 <simpara><link linkend="RefFlatten">RefFlatten</link> is an optimization pass for the <link linkend="SSA2">SSA2</link>
26609 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSA2Simplify">SSA2Simplify</link>.</simpara>
26610 <section id="_description_48">
26611 <title>Description</title>
26612 <simpara>This pass flattens a <literal>ref</literal> cell into its containing object.
26613 The idea is to replace, where possible, a type like</simpara>
26614 <screen>(int ref * real)</screen>
26615 <simpara>with a type like</simpara>
26616 <screen>(int[m] * real)</screen>
26617 <simpara>where the <literal>[m]</literal> indicates a mutable field of a tuple.</simpara>
26618 </section>
26619 <section id="_implementation_53">
26620 <title>Implementation</title>
26621 <itemizedlist>
26622 <listitem>
26623 <simpara>
26624 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ref-flatten.fun"><literal>ref-flatten.fun</literal></ulink>
26625 </simpara>
26626 </listitem>
26627 </itemizedlist>
26628 </section>
26629 <section id="_details_and_notes_51">
26630 <title>Details and Notes</title>
26631 <simpara>The savings is obvious, I hope. We avoid an extra heap-allocated
26632 object for the <literal>ref</literal>, which in the above case saves two words. We
26633 also save the time and code for the extra indirection at each get and
26634 set. There are lots of useful data structures (singly-linked and
26635 doubly-linked lists, union-find, Fibonacci heaps, &#8230;) that I believe
26636 we are paying through the nose right now because of the absence of ref
26637 flattening.</simpara>
26638 <simpara>The idea is to compute for each occurrence of a <literal>ref</literal> type in the
26639 program whether or not that <literal>ref</literal> can be represented as an offset of
26640 some object (constructor or tuple). As before, a unification-based
26641 whole-program with deep abstract values makes sure the analysis is
26642 consistent.</simpara>
26643 <simpara>The only syntactic part of the analysis that remains is the part that
26644 checks that for a variable bound to a value constructed by <literal>Ref_ref</literal>:</simpara>
26645 <itemizedlist>
26646 <listitem>
26647 <simpara>
26648 the object allocation is in the same block. This is pretty
26649 draconian, and it would be nice to generalize it some day to allow
26650 flattening as long as the <literal>ref</literal> allocation and object allocation "line
26651 up one-to-one" in the same loop-free chunk of code.
26652 </simpara>
26653 </listitem>
26654 <listitem>
26655 <simpara>
26656 updates occur in the same block (and hence it is safe-for-space
26657 because the containing object is still alive). It would be nice to
26658 relax this to allow updates as long as it can be provedthat the
26659 container is live.
26660 </simpara>
26661 </listitem>
26662 </itemizedlist>
26663 <simpara>Prevent flattening of <literal>unit ref</literal>-s.</simpara>
26664 <simpara><link linkend="RefFlatten">RefFlatten</link> is safe for space. The idea is to prevent a <literal>ref</literal>
26665 being flattened into an object that has a component of unbounded size
26666 (other than possibly the <literal>ref</literal> itself) unless we can prove that at
26667 each point the <literal>ref</literal> is live, then the containing object is live too.
26668 I used a pretty simple approximation to liveness.</simpara>
26669 <simpara><?asciidoc-pagebreak?></simpara>
26670 </section>
26671 </section>
26672 <section id="Regions">
26673 <title>Regions</title>
26674 <simpara>In region-based memory management, the heap is divided into a
26675 collection of regions into which objects are allocated. At compile
26676 time, either in the source program or through automatic inference,
26677 allocation points are annotated with the region in which the
26678 allocation will occur. Typically, although not always, the regions
26679 are allocated and deallocated according to a stack discipline.</simpara>
26680 <simpara>MLton does not use region-based memory management; it uses traditional
26681 <link linkend="GarbageCollection">GarbageCollection</link>. We have considered integrating regions with
26682 MLton, but in our opinion it is far from clear that regions would
26683 provide MLton with improved performance, while they would certainly
26684 add a lot of complexity to the compiler and complicate reasoning about
26685 and achieving <link linkend="SpaceSafety">SpaceSafety</link>. Region-based memory management and
26686 garbage collection have different strengths and weaknesses; it&#8217;s
26687 pretty easy to come up with programs that do significantly better
26688 under regions than under GC, and vice versa. We believe that it is
26689 the case that common SML idioms tend to work better under GC than
26690 under regions.</simpara>
26691 <simpara>One common argument for regions is that the region operations can all
26692 be done in (approximately) constant time; therefore, you eliminate GC
26693 pause times, leading to a real-time GC. However, because of space
26694 safety concerns (see below), we believe that region-based memory
26695 management for SML must also include a traditional garbage collector.
26696 Hence, to achieve real-time memory management for MLton/SML, we
26697 believe that it would be both easier and more efficient to implement a
26698 traditional real-time garbage collector than it would be to implement
26699 a region system.</simpara>
26700 <section id="_regions_the_ml_kit_and_space_safety">
26701 <title>Regions, the ML Kit, and space safety</title>
26702 <simpara>The <link linkend="MLKit">ML Kit</link> pioneered the use of regions for compiling
26703 Standard ML. The ML Kit maintains a stack of regions at run time. At
26704 compile time, it uses region inference to decide when data can be
26705 allocated in a stack-like manner, assigning it to an appropriate
26706 region. The ML Kit has put a lot of effort into improving the
26707 supporting analyses and representations of regions, which are all
26708 necessary to improve the performance.</simpara>
26709 <simpara>Unfortunately, under a pure stack-based region system, space leaks are
26710 inevitable in theory, and costly in practice. Data for which region
26711 inference can not determine the lifetime is moved into the "global
26712 region" whose lifetime is the entire program. There are two ways in
26713 which region inference will place an object to the global region.</simpara>
26714 <itemizedlist>
26715 <listitem>
26716 <simpara>
26717 When the inference is too conservative, that is, when the data is
26718 used in a stack-like manner but the region inference can&#8217;t figure it
26719 out.
26720 </simpara>
26721 </listitem>
26722 <listitem>
26723 <simpara>
26724 When data is not used in a stack-like manner. In this case,
26725 correctness requires region inference to place the object
26726 </simpara>
26727 </listitem>
26728 </itemizedlist>
26729 <simpara>This global region is a source of space leaks. No matter what region
26730 system you use, there are some programs such that the global region
26731 must exist, and its size will grow to an unbounded multiple of the
26732 live data size. For these programs one must have a GC to achieve
26733 space safety.</simpara>
26734 <simpara>To solve this problem, the ML Kit has undergone work to combine
26735 garbage collection with region-based memory management.
26736 <link linkend="References_HallenbergEtAl02">HallenbergEtAl02</link> and <link linkend="References_Elsman03">Elsman03</link> describe the addition
26737 of a garbage collector to the ML Kit&#8217;s region-based system. These
26738 papers provide convincing evidence for space leaks in the global
26739 region. They show a number of benchmarks where the memory usage of
26740 the program running with just regions is a large multiple (2, 10, 50,
26741 even 150) of the program running with regions plus GC.</simpara>
26742 <simpara>These papers also give some numbers to show the ML Kit with just
26743 regions does better than either a system with just GC or a combined
26744 system. Unfortunately, a pure region system isn&#8217;t practical because
26745 of the lack of space safety. And the other performance numbers are
26746 not so convincing, because they compare to an old version of SML/NJ
26747 and not at all with MLton. It would be interesting to see a
26748 comparison with a more serious collector.</simpara>
26749 </section>
26750 <section id="_regions_garbage_collection_and_cyclone">
26751 <title>Regions, Garbage Collection, and Cyclone</title>
26752 <simpara>One possibility is to take Cyclone&#8217;s approach, and provide both
26753 region-based memory management and garbage collection, but at the
26754 programmer&#8217;s option (<link linkend="References_GrossmanEtAl02">GrossmanEtAl02</link>, <link linkend="References_HicksEtAl03">HicksEtAl03</link>).</simpara>
26755 <simpara>One might ask whether we might do the same thing&#8201;&#8212;&#8201;i.e., provide a
26756 <literal>MLton.Regions</literal> structure with explicit region based memory
26757 management operations, so that the programmer could use them when
26758 appropriate. <link linkend="MatthewFluet">MatthewFluet</link> has thought about this question</simpara>
26759 <itemizedlist>
26760 <listitem>
26761 <simpara>
26762 <ulink url="http://www.cs.cornell.edu/People/fluet/rgn-monad/index.html">http://www.cs.cornell.edu/People/fluet/rgn-monad/index.html</ulink>
26763 </simpara>
26764 </listitem>
26765 </itemizedlist>
26766 <simpara>Unfortunately, his conclusion is that the SML type system is too weak
26767 to support this option, although there might be a "poor-man&#8217;s" version
26768 with dynamic checks.</simpara>
26769 <simpara><?asciidoc-pagebreak?></simpara>
26770 </section>
26771 </section>
26772 <section id="Release20041109">
26773 <title>Release20041109</title>
26774 <simpara>This is an archived public release of MLton, version 20041109.</simpara>
26775 <section id="_changes_since_the_last_public_release">
26776 <title>Changes since the last public release</title>
26777 <itemizedlist>
26778 <listitem>
26779 <simpara>
26780 New platforms:
26781 </simpara>
26782 <itemizedlist>
26783 <listitem>
26784 <simpara>
26785 x86: FreeBSD 5.x, OpenBSD
26786 </simpara>
26787 </listitem>
26788 <listitem>
26789 <simpara>
26790 PowerPC: Darwin (MacOSX)
26791 </simpara>
26792 </listitem>
26793 </itemizedlist>
26794 </listitem>
26795 <listitem>
26796 <simpara>
26797 Support for the <link linkend="MLBasis">ML Basis system</link>, a new mechanism supporting programming in the very large, separate delivery of library sources, and more.
26798 </simpara>
26799 </listitem>
26800 <listitem>
26801 <simpara>
26802 Support for dynamic libraries.
26803 </simpara>
26804 </listitem>
26805 <listitem>
26806 <simpara>
26807 Support for <link linkend="ConcurrentML">ConcurrentML</link> (CML).
26808 </simpara>
26809 </listitem>
26810 <listitem>
26811 <simpara>
26812 New structures: <literal>Int2</literal>, <literal>Int3</literal>, &#8230;, <literal>Int31</literal> and <literal>Word2</literal>, <literal>Word3</literal>, &#8230;, <literal>Word31</literal>.
26813 </simpara>
26814 </listitem>
26815 <listitem>
26816 <simpara>
26817 Front-end bug fixes and improvements.
26818 </simpara>
26819 </listitem>
26820 <listitem>
26821 <simpara>
26822 A new form of profiling with <literal>-profile count</literal>, which can be used to test code coverage.
26823 </simpara>
26824 </listitem>
26825 <listitem>
26826 <simpara>
26827 A bytecode generator, available via <literal>-codegen bytecode</literal>.
26828 </simpara>
26829 </listitem>
26830 <listitem>
26831 <simpara>
26832 Representation improvements:
26833 </simpara>
26834 <itemizedlist>
26835 <listitem>
26836 <simpara>
26837 Tuples and datatypes are packed to decrease space usage.
26838 </simpara>
26839 </listitem>
26840 <listitem>
26841 <simpara>
26842 Ref cells may be unboxed into their containing object.
26843 </simpara>
26844 </listitem>
26845 <listitem>
26846 <simpara>
26847 Arrays of tuples may represent the tuples unboxed.
26848 </simpara>
26849 </listitem>
26850 </itemizedlist>
26851 </listitem>
26852 </itemizedlist>
26853 <simpara>For a complete list of changes and bug fixes since 20040227, see the
26854 <ulink url="https://raw.github.com/MLton/mlton/on-20041109-release/doc/changelog"><literal>changelog</literal></ulink>.</simpara>
26855 </section>
26856 <section id="_also_see_31">
26857 <title>Also see</title>
26858 <itemizedlist>
26859 <listitem>
26860 <simpara>
26861 <link linkend="Bugs20041109">Bugs20041109</link>
26862 </simpara>
26863 </listitem>
26864 </itemizedlist>
26865 <simpara><?asciidoc-pagebreak?></simpara>
26866 </section>
26867 </section>
26868 <section id="Release20051202">
26869 <title>Release20051202</title>
26870 <simpara>This is an archived public release of MLton, version 20051202.</simpara>
26871 <section id="_changes_since_the_last_public_release_2">
26872 <title>Changes since the last public release</title>
26873 <itemizedlist>
26874 <listitem>
26875 <simpara>
26876 The <link linkend="License">MLton license</link> is now BSD-style instead of the GPL.
26877 </simpara>
26878 </listitem>
26879 <listitem>
26880 <simpara>
26881 New platforms: <link linkend="RunningOnMinGW">X86/MinGW</link> and HPPA/Linux.
26882 </simpara>
26883 </listitem>
26884 <listitem>
26885 <simpara>
26886 Improved and expanded documentation, based on the MLton wiki.
26887 </simpara>
26888 </listitem>
26889 <listitem>
26890 <simpara>
26891 Compiler.
26892 </simpara>
26893 <itemizedlist>
26894 <listitem>
26895 <simpara>
26896 improved exception history.
26897 </simpara>
26898 </listitem>
26899 <listitem>
26900 <simpara>
26901 <link linkend="CompileTimeOptions">Command-line switches</link>.
26902 </simpara>
26903 <itemizedlist>
26904 <listitem>
26905 <simpara>
26906 Added: <literal>-as-opt</literal>, <literal>-mlb-path-map</literal>, <literal>-target-as-opt</literal>, <literal>-target-cc-opt</literal>.
26907 </simpara>
26908 </listitem>
26909 <listitem>
26910 <simpara>
26911 Removed: <literal>-native</literal>, <literal>-sequence-unit</literal>, <literal>-warn-match</literal>, <literal>-warn-unused</literal>.
26912 </simpara>
26913 </listitem>
26914 </itemizedlist>
26915 </listitem>
26916 </itemizedlist>
26917 </listitem>
26918 <listitem>
26919 <simpara>
26920 Language.
26921 </simpara>
26922 <itemizedlist>
26923 <listitem>
26924 <simpara>
26925 <link linkend="ForeignFunctionInterface">FFI</link> syntax changes and extensions.
26926 </simpara>
26927 <itemizedlist>
26928 <listitem>
26929 <simpara>
26930 Added: <literal>_symbol</literal>.
26931 </simpara>
26932 </listitem>
26933 <listitem>
26934 <simpara>
26935 Changed: <literal>_export</literal>, <literal>_import</literal>.
26936 </simpara>
26937 </listitem>
26938 <listitem>
26939 <simpara>
26940 Removed: <literal>_ffi</literal>.
26941 </simpara>
26942 </listitem>
26943 </itemizedlist>
26944 </listitem>
26945 <listitem>
26946 <simpara>
26947 <link linkend="MLBasisAnnotations">ML Basis annotations</link>.
26948 </simpara>
26949 <itemizedlist>
26950 <listitem>
26951 <simpara>
26952 Added: <literal>allowFFI</literal>, <literal>nonexhaustiveExnMatch</literal>, <literal>nonexhaustiveMatch</literal>, <literal>redundantMatch</literal>, <literal>sequenceNonUnit</literal>.
26953 </simpara>
26954 </listitem>
26955 <listitem>
26956 <simpara>
26957 Deprecated: <literal>allowExport</literal>, <literal>allowImport</literal>, <literal>sequenceUnit</literal>, <literal>warnMatch</literal>.
26958 </simpara>
26959 </listitem>
26960 </itemizedlist>
26961 </listitem>
26962 </itemizedlist>
26963 </listitem>
26964 <listitem>
26965 <simpara>
26966 Libraries.
26967 </simpara>
26968 <itemizedlist>
26969 <listitem>
26970 <simpara>
26971 Basis Library.
26972 </simpara>
26973 <itemizedlist>
26974 <listitem>
26975 <simpara>
26976 Added: <literal>Int1</literal>, <literal>Word1</literal>.
26977 </simpara>
26978 </listitem>
26979 </itemizedlist>
26980 </listitem>
26981 <listitem>
26982 <simpara>
26983 <link linkend="MLtonStructure">MLton structure</link>.
26984 </simpara>
26985 <itemizedlist>
26986 <listitem>
26987 <simpara>
26988 Added: <literal>Process.create</literal>, <literal>ProcEnv.setgroups</literal>, <literal>Rusage.measureGC</literal>, <literal>Socket.fdToSock</literal>, <literal>Socket.Ctl.getError</literal>.
26989 </simpara>
26990 </listitem>
26991 <listitem>
26992 <simpara>
26993 Changed: <literal>MLton.Platform.Arch</literal>.
26994 </simpara>
26995 </listitem>
26996 </itemizedlist>
26997 </listitem>
26998 <listitem>
26999 <simpara>
27000 Other libraries.
27001 </simpara>
27002 <itemizedlist>
27003 <listitem>
27004 <simpara>
27005 Added: <link linkend="CKitLibrary">ckit</link>, <link linkend="MLNLFFI">ML-NLFFI library</link>, <link linkend="SMLNJLibrary">SML/NJ library</link>.
27006 </simpara>
27007 </listitem>
27008 </itemizedlist>
27009 </listitem>
27010 </itemizedlist>
27011 </listitem>
27012 <listitem>
27013 <simpara>
27014 Tools.
27015 </simpara>
27016 <itemizedlist>
27017 <listitem>
27018 <simpara>
27019 Updates of <literal>mllex</literal> and <literal>mlyacc</literal> from SML/NJ.
27020 </simpara>
27021 </listitem>
27022 <listitem>
27023 <simpara>
27024 Added <link linkend="MLNLFFI">mlnlffigen</link>.
27025 </simpara>
27026 </listitem>
27027 <listitem>
27028 <simpara>
27029 <link linkend="Profiling">Profiling</link> supports better inclusion/exclusion of code.
27030 </simpara>
27031 </listitem>
27032 </itemizedlist>
27033 </listitem>
27034 </itemizedlist>
27035 <simpara>For a complete list of changes and bug fixes since
27036 <link linkend="Release20041109">Release20041109</link>, see the
27037 <ulink url="https://raw.github.com/MLton/mlton/on-20051202-release/doc/changelog"><literal>changelog</literal></ulink> and
27038 <link linkend="Bugs20041109">Bugs20041109</link>.</simpara>
27039 </section>
27040 <section id="_20051202_binary_packages">
27041 <title>20051202 binary packages</title>
27042 <itemizedlist>
27043 <listitem>
27044 <simpara>
27045 x86
27046 </simpara>
27047 <itemizedlist>
27048 <listitem>
27049 <simpara>
27050 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.i386-cygwin.tgz">Cygwin</ulink> 1.5.18-1
27051 </simpara>
27052 </listitem>
27053 <listitem>
27054 <simpara>
27055 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.i386-freebsd.tbz">FreeBSD</ulink> 5.4
27056 </simpara>
27057 </listitem>
27058 <listitem>
27059 <simpara>
27060 Linux
27061 </simpara>
27062 <itemizedlist>
27063 <listitem>
27064 <simpara>
27065 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton_20051202-1_i386.deb">Debian</ulink> sid
27066 </simpara>
27067 </listitem>
27068 <listitem>
27069 <simpara>
27070 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton_20051202-1_i386.stable.deb">Debian</ulink> stable (Sarge)
27071 </simpara>
27072 </listitem>
27073 <listitem>
27074 <simpara>
27075 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.i386.rpm">RedHat</ulink> 7.1-9.3 FC1-FC4
27076 </simpara>
27077 </listitem>
27078 <listitem>
27079 <simpara>
27080 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.i386-linux.tgz">tgz</ulink> for other distributions (glibc 2.3)
27081 </simpara>
27082 </listitem>
27083 </itemizedlist>
27084 </listitem>
27085 <listitem>
27086 <simpara>
27087 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.i386-mingw.tgz">MinGW</ulink>
27088 </simpara>
27089 </listitem>
27090 <listitem>
27091 <simpara>
27092 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.i386-netbsd.tgz">NetBSD</ulink> 2.0.2
27093 </simpara>
27094 </listitem>
27095 <listitem>
27096 <simpara>
27097 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.i386-openbsd.tgz">OpenBSD</ulink> 3.7
27098 </simpara>
27099 </listitem>
27100 </itemizedlist>
27101 </listitem>
27102 <listitem>
27103 <simpara>
27104 PowerPC
27105 </simpara>
27106 <itemizedlist>
27107 <listitem>
27108 <simpara>
27109 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.powerpc-darwin.tgz">Darwin</ulink> 7.9.0 (Mac OS X)
27110 </simpara>
27111 </listitem>
27112 </itemizedlist>
27113 </listitem>
27114 <listitem>
27115 <simpara>
27116 Sparc
27117 </simpara>
27118 <itemizedlist>
27119 <listitem>
27120 <simpara>
27121 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.sparc-solaris.tgz">Solaris</ulink> 8
27122 </simpara>
27123 </listitem>
27124 </itemizedlist>
27125 </listitem>
27126 </itemizedlist>
27127 </section>
27128 <section id="_20051202_source_packages">
27129 <title>20051202 source packages</title>
27130 <itemizedlist>
27131 <listitem>
27132 <simpara>
27133 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.src.tgz">source tgz</ulink>
27134 </simpara>
27135 </listitem>
27136 <listitem>
27137 <simpara>
27138 Debian <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton_20051202-1.dsc">dsc</ulink>, <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton_20051202-1.diff.gz">diff.gz</ulink>, <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton_20051202.orig.tar.gz">orig.tar.gz</ulink>
27139 </simpara>
27140 </listitem>
27141 <listitem>
27142 <simpara>
27143 RedHat <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20051202/mlton-20051202-1.src.rpm">source rpm</ulink>
27144 </simpara>
27145 </listitem>
27146 </itemizedlist>
27147 </section>
27148 <section id="_packages_available_at_other_sites">
27149 <title>Packages available at other sites</title>
27150 <itemizedlist>
27151 <listitem>
27152 <simpara>
27153 <ulink url="http://packages.debian.org/cgi-bin/search_packages.pl?searchon=names&amp;version=all&amp;exact=1&amp;keywords=mlton">Debian</ulink>
27154 </simpara>
27155 </listitem>
27156 <listitem>
27157 <simpara>
27158 <ulink url="http://www.freebsd.org/cgi/ports.cgi?query=mlton&amp;stype=all">FreeBSD</ulink>
27159 </simpara>
27160 </listitem>
27161 <listitem>
27162 <simpara>
27163 Fedora Core <ulink url="http://fedoraproject.org/extras/4/i386/repodata/repoview/mlton-0-20051202-8.fc4.html">4</ulink> <ulink url="http://fedoraproject.org/extras/5/i386/repodata/repoview/mlton-0-20051202-8.fc5.html">5</ulink>
27164 </simpara>
27165 </listitem>
27166 <listitem>
27167 <simpara>
27168 <ulink url="http://packages.ubuntu.com/dapper/devel/mlton">Ubuntu</ulink>
27169 </simpara>
27170 </listitem>
27171 </itemizedlist>
27172 </section>
27173 <section id="_also_see_32">
27174 <title>Also see</title>
27175 <itemizedlist>
27176 <listitem>
27177 <simpara>
27178 <link linkend="Bugs20051202">Bugs20051202</link>
27179 </simpara>
27180 </listitem>
27181 <listitem>
27182 <simpara>
27183 <ulink url="http://www.mlton.org/guide/20051202/">MLton Guide (20051202)</ulink>.
27184 </simpara>
27185 <simpara>A snapshot of the MLton wiki at the time of release.</simpara>
27186 </listitem>
27187 </itemizedlist>
27188 <simpara><?asciidoc-pagebreak?></simpara>
27189 </section>
27190 </section>
27191 <section id="Release20070826">
27192 <title>Release20070826</title>
27193 <simpara>This is an archived public release of MLton, version 20070826.</simpara>
27194 <section id="_changes_since_the_last_public_release_3">
27195 <title>Changes since the last public release</title>
27196 <itemizedlist>
27197 <listitem>
27198 <simpara>
27199 New platforms:
27200 </simpara>
27201 <itemizedlist>
27202 <listitem>
27203 <simpara>
27204 <link linkend="RunningOnAMD64">AMD64</link>/<link linkend="RunningOnLinux">Linux</link>, <link linkend="RunningOnAMD64">AMD64</link>/<link linkend="RunningOnFreeBSD">FreeBSD</link>
27205 </simpara>
27206 </listitem>
27207 <listitem>
27208 <simpara>
27209 <link linkend="RunningOnHPPA">HPPA</link>/<link linkend="RunningOnHPUX">HPUX</link>
27210 </simpara>
27211 </listitem>
27212 <listitem>
27213 <simpara>
27214 <link linkend="RunningOnPowerPC">PowerPC</link>/<link linkend="RunningOnAIX">AIX</link>
27215 </simpara>
27216 </listitem>
27217 <listitem>
27218 <simpara>
27219 <link linkend="RunningOnX86">X86</link>/<link linkend="RunningOnDarwin">Darwin (Mac OS X)</link>
27220 </simpara>
27221 </listitem>
27222 </itemizedlist>
27223 </listitem>
27224 <listitem>
27225 <simpara>
27226 Compiler.
27227 </simpara>
27228 <itemizedlist>
27229 <listitem>
27230 <simpara>
27231 Support for 64-bit platforms.
27232 </simpara>
27233 <itemizedlist>
27234 <listitem>
27235 <simpara>
27236 Native amd64 codegen.
27237 </simpara>
27238 </listitem>
27239 </itemizedlist>
27240 </listitem>
27241 <listitem>
27242 <simpara>
27243 <link linkend="CompileTimeOptions">Compile-time options</link>.
27244 </simpara>
27245 <itemizedlist>
27246 <listitem>
27247 <simpara>
27248 Added: <literal>-codegen amd64</literal>, <literal>-codegen x86</literal>, <literal>-default-type <emphasis>type</emphasis></literal>, <literal>-profile-val {false|true}</literal>.
27249 </simpara>
27250 </listitem>
27251 <listitem>
27252 <simpara>
27253 Changed: <literal>-stop f</literal> (file listing now includes <literal>.mlb</literal> files).
27254 </simpara>
27255 </listitem>
27256 </itemizedlist>
27257 </listitem>
27258 <listitem>
27259 <simpara>
27260 Bytecode codegen.
27261 </simpara>
27262 <itemizedlist>
27263 <listitem>
27264 <simpara>
27265 Support for exception history.
27266 </simpara>
27267 </listitem>
27268 <listitem>
27269 <simpara>
27270 Support for profiling.
27271 </simpara>
27272 </listitem>
27273 </itemizedlist>
27274 </listitem>
27275 </itemizedlist>
27276 </listitem>
27277 <listitem>
27278 <simpara>
27279 Language.
27280 </simpara>
27281 <itemizedlist>
27282 <listitem>
27283 <simpara>
27284 <link linkend="MLBasisAnnotations">ML Basis annotations</link>.
27285 </simpara>
27286 <itemizedlist>
27287 <listitem>
27288 <simpara>
27289 Removed: <literal>allowExport</literal>, <literal>allowImport</literal>, <literal>sequenceUnit</literal>, <literal>warnMatch</literal>.
27290 </simpara>
27291 </listitem>
27292 </itemizedlist>
27293 </listitem>
27294 </itemizedlist>
27295 </listitem>
27296 <listitem>
27297 <simpara>
27298 Libraries.
27299 </simpara>
27300 <itemizedlist>
27301 <listitem>
27302 <simpara>
27303 <link linkend="BasisLibrary">Basis Library</link>.
27304 </simpara>
27305 <itemizedlist>
27306 <listitem>
27307 <simpara>
27308 Added: <literal>PackWord16Big</literal>, <literal>PackWord16Little</literal>, <literal>PackWord64Big</literal>, <literal>PackWord64Little</literal>.
27309 </simpara>
27310 </listitem>
27311 <listitem>
27312 <simpara>
27313 Bug fixes: see <ulink url="https://raw.github.com/MLton/mlton/on-20070826-release/doc/changelog"><literal>changelog</literal></ulink>.
27314 </simpara>
27315 </listitem>
27316 </itemizedlist>
27317 </listitem>
27318 <listitem>
27319 <simpara>
27320 <link linkend="MLtonStructure">MLton structure</link>.
27321 </simpara>
27322 <itemizedlist>
27323 <listitem>
27324 <simpara>
27325 Added: <literal>MLTON_MONO_ARRAY</literal>, <literal>MLTON_MONO_VECTOR</literal>, <literal>MLTON_REAL</literal>, <literal>MLton.BinIO.tempPrefix</literal>, <literal>MLton.CharArray</literal>, <literal>MLton.CharVector</literal>, <literal>MLton.Exn.defaultTopLevelHandler</literal>, <literal>MLton.Exn.getTopLevelHandler</literal>, <literal>MLton.Exn.setTopLevelHandler</literal>, <literal>MLton.IntInf.BigWord</literal>, <literal>Mlton.IntInf.SmallInt</literal>, <literal>MLton.LargeReal</literal>, <literal>MLton.LargeWord</literal>, <literal>MLton.Real</literal>, <literal>MLton.Real32</literal>, <literal>MLton.Real64</literal>, <literal>MLton.Rlimit.Rlim</literal>, <literal>MLton.TextIO.tempPrefix</literal>, <literal>MLton.Vector.create</literal>, <literal>MLton.Word.bswap</literal>, <literal>MLton.Word8.bswap</literal>, <literal>MLton.Word16</literal>, <literal>MLton.Word32</literal>, <literal>MLton.Word64</literal>, <literal>MLton.Word8Array</literal>, <literal>MLton.Word8Vector</literal>.
27326 </simpara>
27327 </listitem>
27328 <listitem>
27329 <simpara>
27330 Changed: <literal>MLton.Array.unfoldi</literal>, <literal>MLton.IntInf.rep</literal>, <literal>MLton.Rlimit</literal>, <literal>MLton.Vector.unfoldi</literal>.
27331 </simpara>
27332 </listitem>
27333 <listitem>
27334 <simpara>
27335 Deprecated: <literal>MLton.Socket</literal>.
27336 </simpara>
27337 </listitem>
27338 </itemizedlist>
27339 </listitem>
27340 <listitem>
27341 <simpara>
27342 Other libraries.
27343 </simpara>
27344 <itemizedlist>
27345 <listitem>
27346 <simpara>
27347 Added: <link linkend="MLRISCLibrary">MLRISC library</link>.
27348 </simpara>
27349 </listitem>
27350 <listitem>
27351 <simpara>
27352 Updated: <link linkend="CKitLibrary">ckit library</link>, <link linkend="SMLNJLibrary">SML/NJ library</link>.
27353 </simpara>
27354 </listitem>
27355 </itemizedlist>
27356 </listitem>
27357 </itemizedlist>
27358 </listitem>
27359 <listitem>
27360 <simpara>
27361 Tools.
27362 </simpara>
27363 </listitem>
27364 </itemizedlist>
27365 <simpara>For a complete list of changes and bug fixes since
27366 <link linkend="Release20051202">Release20051202</link>, see the
27367 <ulink url="https://raw.github.com/MLton/mlton/on-20070826-release/doc/changelog"><literal>changelog</literal></ulink> and
27368 <link linkend="Bugs20051202">Bugs20051202</link>.</simpara>
27369 </section>
27370 <section id="_20070826_binary_packages">
27371 <title>20070826 binary packages</title>
27372 <itemizedlist>
27373 <listitem>
27374 <simpara>
27375 AMD64
27376 </simpara>
27377 <itemizedlist>
27378 <listitem>
27379 <simpara>
27380 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.amd64-linux.tgz">Linux</ulink>, glibc 2.3
27381 </simpara>
27382 </listitem>
27383 </itemizedlist>
27384 </listitem>
27385 <listitem>
27386 <simpara>
27387 HPPA
27388 </simpara>
27389 <itemizedlist>
27390 <listitem>
27391 <simpara>
27392 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.hppa-hpux1100.tgz">HPUX</ulink> 11.00 and above, statically linked against <link linkend="GnuMP">GnuMP</link>
27393 </simpara>
27394 </listitem>
27395 </itemizedlist>
27396 </listitem>
27397 <listitem>
27398 <simpara>
27399 PowerPC
27400 </simpara>
27401 <itemizedlist>
27402 <listitem>
27403 <simpara>
27404 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.powerpc-aix51.tgz">AIX</ulink> 5.1 and above, statically linked against <link linkend="GnuMP">GnuMP</link>
27405 </simpara>
27406 </listitem>
27407 <listitem>
27408 <simpara>
27409 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.powerpc-darwin.gmp-static.tgz">Darwin</ulink> 8.10 (Mac OS X), statically linked against <link linkend="GnuMP">GnuMP</link>
27410 </simpara>
27411 </listitem>
27412 <listitem>
27413 <simpara>
27414 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.powerpc-darwin.gmp-macports.tgz">Darwin</ulink> 8.10 (Mac OS X), dynamically linked against <link linkend="GnuMP">GnuMP</link> in <literal>/opt/local/lib</literal> (suitable for <ulink url="http://macports.org">MacPorts</ulink> install of <link linkend="GnuMP">GnuMP</link>)
27415 </simpara>
27416 </listitem>
27417 </itemizedlist>
27418 </listitem>
27419 <listitem>
27420 <simpara>
27421 Sparc
27422 </simpara>
27423 <itemizedlist>
27424 <listitem>
27425 <simpara>
27426 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.sparc-solaris8.tgz">Solaris</ulink> 8 and above, statically linked against <link linkend="GnuMP">GnuMP</link>
27427 </simpara>
27428 </listitem>
27429 </itemizedlist>
27430 </listitem>
27431 <listitem>
27432 <simpara>
27433 X86
27434 </simpara>
27435 <itemizedlist>
27436 <listitem>
27437 <simpara>
27438 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.x86-cygwin.tgz">Cygwin</ulink> 1.5.24-2
27439 </simpara>
27440 </listitem>
27441 <listitem>
27442 <simpara>
27443 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.x86-darwin.gmp-macports.tgz">Darwin (.tgz)</ulink> 8.10 (Mac OS X), dynamically linked against <link linkend="GnuMP">GnuMP</link> in <literal>/opt/local/lib</literal> (suitable for <ulink url="http://macports.org">MacPorts</ulink> install of <link linkend="GnuMP">GnuMP</link>)
27444 </simpara>
27445 </listitem>
27446 <listitem>
27447 <simpara>
27448 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.x86-darwin.gmp-macports.dmg">Darwin (.dmg)</ulink> 8.10 (Mac OS X), dynamically linked against <link linkend="GnuMP">GnuMP</link> in <literal>/opt/local/lib</literal> (suitable for <ulink url="http://macports.org">MacPorts</ulink> install of <link linkend="GnuMP">GnuMP</link>)
27449 </simpara>
27450 </listitem>
27451 <listitem>
27452 <simpara>
27453 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.x86-darwin.gmp-static.tgz">Darwin (.tgz)</ulink> 8.10 (Mac OS X), statically linked against <link linkend="GnuMP">GnuMP</link>
27454 </simpara>
27455 </listitem>
27456 <listitem>
27457 <simpara>
27458 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.x86-darwin.gmp-static.dmg">Darwin (.dmg)</ulink> 8.10 (Mac OS X), statically linked against <link linkend="GnuMP">GnuMP</link>
27459 </simpara>
27460 </listitem>
27461 <listitem>
27462 <simpara>
27463 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.x86-freebsd.tgz">FreeBSD</ulink>
27464 </simpara>
27465 </listitem>
27466 <listitem>
27467 <simpara>
27468 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.x86-linux.tgz">Linux</ulink>, glibc 2.3
27469 </simpara>
27470 </listitem>
27471 <listitem>
27472 <simpara>
27473 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.x86-linux.glibc213.gmp-static.tgz">Linux</ulink>, glibc 2.1, statically linked against <link linkend="GnuMP">GnuMP</link>
27474 </simpara>
27475 </listitem>
27476 <listitem>
27477 <simpara>
27478 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.x86-mingw.gmp-dll.tgz">MinGW</ulink>, dynamically linked against <link linkend="GnuMP">GnuMP</link> (requires <literal>libgmp-3.dll</literal>)
27479 </simpara>
27480 </listitem>
27481 <listitem>
27482 <simpara>
27483 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.x86-mingw.gmp-static.tgz">MinGW</ulink>, statically linked against <link linkend="GnuMP">GnuMP</link>
27484 </simpara>
27485 </listitem>
27486 </itemizedlist>
27487 </listitem>
27488 </itemizedlist>
27489 </section>
27490 <section id="_20070826_source_packages">
27491 <title>20070826 source packages</title>
27492 <itemizedlist>
27493 <listitem>
27494 <simpara>
27495 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton-20070826-1.src.tgz">source tgz</ulink>
27496 </simpara>
27497 </listitem>
27498 <listitem>
27499 <simpara>
27500 Debian <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton_20070826-1.dsc">dsc</ulink>,
27501 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton_20070826-1.diff.gz">diff.gz</ulink>,
27502 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20070826/mlton_20070826.orig.tar.gz">orig.tar.gz</ulink>
27503 </simpara>
27504 </listitem>
27505 </itemizedlist>
27506 </section>
27507 <section id="_packages_available_at_other_sites_2">
27508 <title>Packages available at other sites</title>
27509 <itemizedlist>
27510 <listitem>
27511 <simpara>
27512 <ulink url="http://packages.debian.org/search?keywords=mlton&amp;searchon=names&amp;suite=all&amp;section=all">Debian</ulink>
27513 </simpara>
27514 </listitem>
27515 <listitem>
27516 <simpara>
27517 <ulink url="http://www.freebsd.org/cgi/ports.cgi?query=mlton&amp;stype=all">FreeBSD</ulink>
27518 </simpara>
27519 </listitem>
27520 <listitem>
27521 <simpara>
27522 <ulink url="https://admin.fedoraproject.org/pkgdb/packages/name/mlton">Fedora</ulink>
27523 </simpara>
27524 </listitem>
27525 <listitem>
27526 <simpara>
27527 <ulink url="http://packages.ubuntu.com/cgi-bin/search_packages.pl?keywords=mlton&amp;searchon=names&amp;version=all&amp;release=all">Ubuntu</ulink>
27528 </simpara>
27529 </listitem>
27530 </itemizedlist>
27531 </section>
27532 <section id="_also_see_33">
27533 <title>Also see</title>
27534 <itemizedlist>
27535 <listitem>
27536 <simpara>
27537 <link linkend="Bugs20070826">Bugs20070826</link>
27538 </simpara>
27539 </listitem>
27540 <listitem>
27541 <simpara>
27542 <ulink url="http://www.mlton.org/guide/20070826/">MLton Guide (20070826)</ulink>.
27543 </simpara>
27544 <simpara>A snapshot of the MLton wiki at the time of release.</simpara>
27545 </listitem>
27546 </itemizedlist>
27547 <simpara><?asciidoc-pagebreak?></simpara>
27548 </section>
27549 </section>
27550 <section id="Release20100608">
27551 <title>Release20100608</title>
27552 <simpara>This is an archived public release of MLton, version 20100608.</simpara>
27553 <section id="_changes_since_the_last_public_release_4">
27554 <title>Changes since the last public release</title>
27555 <itemizedlist>
27556 <listitem>
27557 <simpara>
27558 New platforms.
27559 </simpara>
27560 <itemizedlist>
27561 <listitem>
27562 <simpara>
27563 <link linkend="RunningOnAMD64">AMD64</link>/<link linkend="RunningOnDarwin">Darwin</link> (Mac OS X Snow Leopard)
27564 </simpara>
27565 </listitem>
27566 <listitem>
27567 <simpara>
27568 <link linkend="RunningOnIA64">IA64</link>/<link linkend="RunningOnHPUX">HPUX</link>
27569 </simpara>
27570 </listitem>
27571 <listitem>
27572 <simpara>
27573 <link linkend="RunningOnPowerPC64">PowerPC64</link>/<link linkend="RunningOnAIX">AIX</link>
27574 </simpara>
27575 </listitem>
27576 </itemizedlist>
27577 </listitem>
27578 <listitem>
27579 <simpara>
27580 Compiler.
27581 </simpara>
27582 <itemizedlist>
27583 <listitem>
27584 <simpara>
27585 <link linkend="CompileTimeOptions">Command-line switches</link>.
27586 </simpara>
27587 <itemizedlist>
27588 <listitem>
27589 <simpara>
27590 Added: <literal>-mlb-path-var <emphasis>&lt;name&gt; &lt;value&gt;</emphasis></literal>
27591 </simpara>
27592 </listitem>
27593 <listitem>
27594 <simpara>
27595 Removed: <literal>-keep sml</literal>, <literal>-stop sml</literal>
27596 </simpara>
27597 </listitem>
27598 </itemizedlist>
27599 </listitem>
27600 <listitem>
27601 <simpara>
27602 Improved constant folding of floating-point operations.
27603 </simpara>
27604 </listitem>
27605 <listitem>
27606 <simpara>
27607 Experimental: Support for compiling to a C library; see <link linkend="LibrarySupport">documentation</link>.
27608 </simpara>
27609 </listitem>
27610 <listitem>
27611 <simpara>
27612 Extended <literal>-show-def-use <emphasis>output</emphasis></literal> to include types of variable definitions.
27613 </simpara>
27614 </listitem>
27615 <listitem>
27616 <simpara>
27617 Deprecated features (to be removed in a future release)
27618 </simpara>
27619 <itemizedlist>
27620 <listitem>
27621 <simpara>
27622 Bytecode codegen: The bytecode codegen has not seen significant use and it is not well understood by any of the active developers.
27623 </simpara>
27624 </listitem>
27625 <listitem>
27626 <simpara>
27627 Support for <literal>.cm</literal> files as input: The ML Basis system provides much better infrastructure for "programming in the very large" than the (very) limited support for CM. The <literal>cm2mlb</literal> tool (available in the source distribution) can be used to convert CM projects to MLB projects, preserving the CM scoping of module identifiers.
27628 </simpara>
27629 </listitem>
27630 </itemizedlist>
27631 </listitem>
27632 <listitem>
27633 <simpara>
27634 Bug fixes: see <ulink url="https://raw.github.com/MLton/mlton/on-20100608-release/doc/changelog"><literal>changelog</literal></ulink>
27635 </simpara>
27636 </listitem>
27637 </itemizedlist>
27638 </listitem>
27639 <listitem>
27640 <simpara>
27641 Runtime.
27642 </simpara>
27643 <itemizedlist>
27644 <listitem>
27645 <simpara>
27646 <link linkend="RunTimeOptions">@MLton switches</link>.
27647 </simpara>
27648 <itemizedlist>
27649 <listitem>
27650 <simpara>
27651 Added: <literal>may-page-heap {false|true}</literal>
27652 </simpara>
27653 </listitem>
27654 </itemizedlist>
27655 </listitem>
27656 <listitem>
27657 <simpara>
27658 <literal>may-page-heap</literal>: By default, MLton will not page the heap to disk when unable to grow the heap to accommodate an allocation. (Previously, this behavior was the default, with no means to disable, with security an least-surprise issues.)
27659 </simpara>
27660 </listitem>
27661 <listitem>
27662 <simpara>
27663 Bug fixes: see <ulink url="https://raw.github.com/MLton/mlton/on-20100608-release/doc/changelog"><literal>changelog</literal></ulink>
27664 </simpara>
27665 </listitem>
27666 </itemizedlist>
27667 </listitem>
27668 <listitem>
27669 <simpara>
27670 Language.
27671 </simpara>
27672 <itemizedlist>
27673 <listitem>
27674 <simpara>
27675 Allow numeric characters in <link linkend="MLBasis">ML Basis</link> path variables.
27676 </simpara>
27677 </listitem>
27678 </itemizedlist>
27679 </listitem>
27680 <listitem>
27681 <simpara>
27682 Libraries.
27683 </simpara>
27684 <itemizedlist>
27685 <listitem>
27686 <simpara>
27687 <link linkend="BasisLibrary">Basis Library</link>.
27688 </simpara>
27689 <itemizedlist>
27690 <listitem>
27691 <simpara>
27692 Bug fixes: see <ulink url="https://raw.github.com/MLton/mlton/on-20100608-release/doc/changelog"><literal>changelog</literal></ulink>
27693 </simpara>
27694 </listitem>
27695 </itemizedlist>
27696 </listitem>
27697 <listitem>
27698 <simpara>
27699 <link linkend="MLtonStructure">MLton structure</link>.
27700 </simpara>
27701 <itemizedlist>
27702 <listitem>
27703 <simpara>
27704 Added: <literal>MLton.equal</literal>, <literal>MLton.hash</literal>, <literal>MLton.Cont.isolate</literal>, <literal>MLton.GC.Statistics</literal>, <literal>MLton.Pointer.sizeofPointer</literal>, <literal>MLton.Socket.Address.toVector</literal>
27705 </simpara>
27706 </listitem>
27707 <listitem>
27708 <simpara>
27709 Changed:
27710 </simpara>
27711 </listitem>
27712 <listitem>
27713 <simpara>
27714 Deprecated: <literal>MLton.Socket</literal>
27715 </simpara>
27716 </listitem>
27717 </itemizedlist>
27718 </listitem>
27719 <listitem>
27720 <simpara>
27721 <link linkend="UnsafeStructure">Unsafe structure</link>.
27722 </simpara>
27723 <itemizedlist>
27724 <listitem>
27725 <simpara>
27726 Added versions of all of the monomorphic array and vector structures.
27727 </simpara>
27728 </listitem>
27729 </itemizedlist>
27730 </listitem>
27731 <listitem>
27732 <simpara>
27733 Other libraries.
27734 </simpara>
27735 <itemizedlist>
27736 <listitem>
27737 <simpara>
27738 Updated: <link linkend="CKitLibrary">ckit library</link>, <link linkend="MLRISCLibrary">MLRISC library</link>, <link linkend="SMLNJLibrary">SML/NJ library</link>.
27739 </simpara>
27740 </listitem>
27741 </itemizedlist>
27742 </listitem>
27743 </itemizedlist>
27744 </listitem>
27745 <listitem>
27746 <simpara>
27747 Tools.
27748 </simpara>
27749 <itemizedlist>
27750 <listitem>
27751 <simpara>
27752 <literal>mllex</literal>
27753 </simpara>
27754 <itemizedlist>
27755 <listitem>
27756 <simpara>
27757 Eliminated top-level <literal>type int = Int.int</literal> in output.
27758 </simpara>
27759 </listitem>
27760 <listitem>
27761 <simpara>
27762 Include <literal>(*#line line:col "file.lex" *)</literal> directives in output.
27763 </simpara>
27764 </listitem>
27765 <listitem>
27766 <simpara>
27767 Added <literal>%posint</literal> command, to set the <literal>yypos</literal> type and allow the lexing of multi-gigabyte files.
27768 </simpara>
27769 </listitem>
27770 </itemizedlist>
27771 </listitem>
27772 <listitem>
27773 <simpara>
27774 <literal>mlnlffigen</literal>
27775 </simpara>
27776 <itemizedlist>
27777 <listitem>
27778 <simpara>
27779 Added command-line switches <literal>-linkage archive</literal> and <literal>-linkage shared</literal>.
27780 </simpara>
27781 </listitem>
27782 <listitem>
27783 <simpara>
27784 Deprecated command-line switch <literal>-linkage static</literal>.
27785 </simpara>
27786 </listitem>
27787 <listitem>
27788 <simpara>
27789 Added support for <link linkend="RunningOnIA64">IA64</link> and <link linkend="RunningOnHPPA">HPPA</link> targets.
27790 </simpara>
27791 </listitem>
27792 </itemizedlist>
27793 </listitem>
27794 <listitem>
27795 <simpara>
27796 <literal>mlyacc</literal>
27797 </simpara>
27798 <itemizedlist>
27799 <listitem>
27800 <simpara>
27801 Eliminated top-level <literal>type int = Int.int</literal> in output.
27802 </simpara>
27803 </listitem>
27804 <listitem>
27805 <simpara>
27806 Include <literal>(*#line line:col "file.grm" *)</literal> directives in output.
27807 </simpara>
27808 </listitem>
27809 </itemizedlist>
27810 </listitem>
27811 </itemizedlist>
27812 </listitem>
27813 </itemizedlist>
27814 <simpara>For a complete list of changes and bug fixes since <link linkend="Release20070826">Release20070826</link>, see the
27815 <ulink url="https://raw.github.com/MLton/mlton/on-20100608-release/doc/changelog"><literal>changelog</literal></ulink>
27816 and <link linkend="Bugs20070826">Bugs20070826</link>.</simpara>
27817 </section>
27818 <section id="_20100608_binary_packages">
27819 <title>20100608 binary packages</title>
27820 <itemizedlist>
27821 <listitem>
27822 <simpara>
27823 AMD64 (aka "x86-64" or "x64")
27824 </simpara>
27825 <itemizedlist>
27826 <listitem>
27827 <simpara>
27828 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/mlton-20100608-1.amd64-darwin.gmp-macports.tgz">Darwin (.tgz)</ulink> 10.3 (Mac OS X Snow Leopard), dynamically linked against <link linkend="GnuMP">GnuMP</link> in <literal>/opt/local/lib</literal> (suitable for <ulink url="http://macports.org">MacPorts</ulink> install of <link linkend="GnuMP">GnuMP</link>)
27829 </simpara>
27830 </listitem>
27831 <listitem>
27832 <simpara>
27833 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/mlton-20100608-1.amd64-darwin.gmp-static.tgz">Darwin (.tgz)</ulink> 10.3 (Mac OS X Snow Leopard), statically linked against <link linkend="GnuMP">GnuMP</link> (but requires <link linkend="GnuMP">GnuMP</link> for generated executables)
27834 </simpara>
27835 </listitem>
27836 <listitem>
27837 <simpara>
27838 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/mlton-20100608-1.amd64-linux.tgz">Linux</ulink>, glibc 2.11
27839 </simpara>
27840 </listitem>
27841 <listitem>
27842 <simpara>
27843 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/mlton-20100608-1.amd64-linux.static.tgz">Linux</ulink>, statically linked
27844 </simpara>
27845 </listitem>
27846 <listitem>
27847 <simpara>
27848 Windows MinGW 32/64 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/MLton-20100608-1.exe">self-extracting</ulink> (28MB) or <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/MLton-20100608-1.msi">MSI</ulink> (61MB) installer
27849 </simpara>
27850 </listitem>
27851 </itemizedlist>
27852 </listitem>
27853 <listitem>
27854 <simpara>
27855 X86
27856 </simpara>
27857 <itemizedlist>
27858 <listitem>
27859 <simpara>
27860 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/mlton-20100608-1.x86-cygwin.tgz">Cygwin</ulink> 1.7.5
27861 </simpara>
27862 </listitem>
27863 <listitem>
27864 <simpara>
27865 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/mlton-20100608-1.x86-darwin.gmp-macports.tgz">Darwin (.tgz)</ulink> 9.8 (Mac OS X Leopard), dynamically linked against <link linkend="GnuMP">GnuMP</link> in <literal>/opt/local/lib</literal> (suitable for <ulink url="http://macports.org">MacPorts</ulink> install of <link linkend="GnuMP">GnuMP</link>)
27866 </simpara>
27867 </listitem>
27868 <listitem>
27869 <simpara>
27870 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/mlton-20100608-1.x86-darwin.gmp-static.tgz">Darwin (.tgz)</ulink> 9.8 (Mac OS X Leopard), statically linked against <link linkend="GnuMP">GnuMP</link> (but requires <link linkend="GnuMP">GnuMP</link> for generated executables)
27871 </simpara>
27872 </listitem>
27873 <listitem>
27874 <simpara>
27875 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/mlton-20100608-1.x86-linux.tgz">Linux</ulink>, glibc 2.11
27876 </simpara>
27877 </listitem>
27878 <listitem>
27879 <simpara>
27880 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/mlton-20100608-1.x86-linux.static.tgz">Linux</ulink>, statically linked
27881 </simpara>
27882 </listitem>
27883 <listitem>
27884 <simpara>
27885 Windows MinGW 32/64 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/MLton-20100608-1.exe">self-extracting</ulink> (28MB) or <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/MLton-20100608-1.msi">MSI</ulink> (61MB) installer
27886 </simpara>
27887 </listitem>
27888 </itemizedlist>
27889 </listitem>
27890 </itemizedlist>
27891 </section>
27892 <section id="_20100608_source_packages">
27893 <title>20100608 source packages</title>
27894 <itemizedlist>
27895 <listitem>
27896 <simpara>
27897 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20100608/mlton-20100608.src.tgz">mlton-20100608.src.tgz</ulink>
27898 </simpara>
27899 </listitem>
27900 </itemizedlist>
27901 </section>
27902 <section id="_packages_available_at_other_sites_3">
27903 <title>Packages available at other sites</title>
27904 <itemizedlist>
27905 <listitem>
27906 <simpara>
27907 <ulink url="http://packages.debian.org/search?keywords=mlton&amp;searchon=names&amp;suite=all&amp;section=all">Debian</ulink>
27908 </simpara>
27909 </listitem>
27910 <listitem>
27911 <simpara>
27912 <ulink url="http://www.freebsd.org/cgi/ports.cgi?query=mlton&amp;stype=all">FreeBSD</ulink>
27913 </simpara>
27914 </listitem>
27915 <listitem>
27916 <simpara>
27917 <ulink url="https://admin.fedoraproject.org/pkgdb/acls/name/mlton">Fedora</ulink>
27918 </simpara>
27919 </listitem>
27920 <listitem>
27921 <simpara>
27922 <ulink url="http://packages.ubuntu.com/search?suite=default&amp;section=all&amp;arch=any&amp;searchon=names&amp;keywords=mlton">Ubuntu</ulink>
27923 </simpara>
27924 </listitem>
27925 </itemizedlist>
27926 </section>
27927 <section id="_also_see_34">
27928 <title>Also see</title>
27929 <itemizedlist>
27930 <listitem>
27931 <simpara>
27932 <link linkend="Bugs20100608">Bugs20100608</link>
27933 </simpara>
27934 </listitem>
27935 <listitem>
27936 <simpara>
27937 <ulink url="http://www.mlton.org/guide/20100608/">MLton Guide (20100608)</ulink>.
27938 </simpara>
27939 <simpara>A snapshot of the MLton wiki at the time of release.</simpara>
27940 </listitem>
27941 </itemizedlist>
27942 <simpara><?asciidoc-pagebreak?></simpara>
27943 </section>
27944 </section>
27945 <section id="Release20130715">
27946 <title>Release20130715</title>
27947 <simpara>This is an archived public release of MLton, version 20130715.</simpara>
27948 <section id="_changes_since_the_last_public_release_5">
27949 <title>Changes since the last public release</title>
27950 <itemizedlist>
27951 <listitem>
27952 <simpara>
27953 Compiler.
27954 </simpara>
27955 <itemizedlist>
27956 <listitem>
27957 <simpara>
27958 Cosmetic improvements to type-error messages.
27959 </simpara>
27960 </listitem>
27961 <listitem>
27962 <simpara>
27963 Removed features:
27964 </simpara>
27965 <itemizedlist>
27966 <listitem>
27967 <simpara>
27968 Bytecode codegen: The bytecode codegen had not seen significant use and it was not well understood by any of the active developers.
27969 </simpara>
27970 </listitem>
27971 <listitem>
27972 <simpara>
27973 Support for <literal>.cm</literal> files as input: The <link linkend="MLBasis">ML Basis system</link> provides much better infrastructure for "programming in the very large" than the (very) limited support for CM. The <literal>cm2mlb</literal> tool (available in the source distribution) can be used to convert CM projects to MLB projects, preserving the CM scoping of module identifiers.
27974 </simpara>
27975 </listitem>
27976 </itemizedlist>
27977 </listitem>
27978 <listitem>
27979 <simpara>
27980 Bug fixes: see <ulink url="https://raw.github.com/MLton/mlton/on-20130715-release/doc/changelog"><literal>changelog</literal></ulink>
27981 </simpara>
27982 </listitem>
27983 </itemizedlist>
27984 </listitem>
27985 <listitem>
27986 <simpara>
27987 Runtime.
27988 </simpara>
27989 <itemizedlist>
27990 <listitem>
27991 <simpara>
27992 Bug fixes: see <ulink url="https://raw.github.com/MLton/mlton/on-20130715-release/doc/changelog"><literal>changelog</literal></ulink>
27993 </simpara>
27994 </listitem>
27995 </itemizedlist>
27996 </listitem>
27997 <listitem>
27998 <simpara>
27999 Language.
28000 </simpara>
28001 <itemizedlist>
28002 <listitem>
28003 <simpara>
28004 Interpret <literal>(*#line line:col "file" *)</literal> directives as relative file names.
28005 </simpara>
28006 </listitem>
28007 <listitem>
28008 <simpara>
28009 <link linkend="MLBasisAnnotations">ML Basis annotations</link>.
28010 </simpara>
28011 <itemizedlist>
28012 <listitem>
28013 <simpara>
28014 Added: <literal>resolveScope</literal>
28015 </simpara>
28016 </listitem>
28017 </itemizedlist>
28018 </listitem>
28019 </itemizedlist>
28020 </listitem>
28021 <listitem>
28022 <simpara>
28023 Libraries.
28024 </simpara>
28025 <itemizedlist>
28026 <listitem>
28027 <simpara>
28028 <link linkend="BasisLibrary">Basis Library</link>.
28029 </simpara>
28030 <itemizedlist>
28031 <listitem>
28032 <simpara>
28033 Improved performance of <literal>String.concatWith</literal>.
28034 </simpara>
28035 </listitem>
28036 <listitem>
28037 <simpara>
28038 Use bit operations for <literal>REAL.class</literal> and other low-level operations.
28039 </simpara>
28040 </listitem>
28041 <listitem>
28042 <simpara>
28043 Support additional variables with <literal>Posix.ProcEnv.sysconf</literal>.
28044 </simpara>
28045 </listitem>
28046 <listitem>
28047 <simpara>
28048 Bug fixes: see <ulink url="https://raw.github.com/MLton/mlton/on-20130715-release/doc/changelog"><literal>changelog</literal></ulink>
28049 </simpara>
28050 </listitem>
28051 </itemizedlist>
28052 </listitem>
28053 <listitem>
28054 <simpara>
28055 <link linkend="MLtonStructure">MLton structure</link>.
28056 </simpara>
28057 <itemizedlist>
28058 <listitem>
28059 <simpara>
28060 Removed: <literal>MLton.Socket</literal>
28061 </simpara>
28062 </listitem>
28063 </itemizedlist>
28064 </listitem>
28065 <listitem>
28066 <simpara>
28067 Other libraries.
28068 </simpara>
28069 <itemizedlist>
28070 <listitem>
28071 <simpara>
28072 Updated: <link linkend="CKitLibrary">ckit library</link>, <link linkend="MLRISCLibrary">MLRISC library</link>, <link linkend="SMLNJLibrary">SML/NJ library</link>
28073 </simpara>
28074 </listitem>
28075 <listitem>
28076 <simpara>
28077 Added: <link linkend="MLLPTLibrary">MLLPT library</link>
28078 </simpara>
28079 </listitem>
28080 </itemizedlist>
28081 </listitem>
28082 </itemizedlist>
28083 </listitem>
28084 <listitem>
28085 <simpara>
28086 Tools.
28087 </simpara>
28088 <itemizedlist>
28089 <listitem>
28090 <simpara>
28091 <literal>mllex</literal>
28092 </simpara>
28093 <itemizedlist>
28094 <listitem>
28095 <simpara>
28096 Generate <literal>(*#line line:col "file.lex" *)</literal> directives with simple (relative) file names, rather than absolute paths.
28097 </simpara>
28098 </listitem>
28099 </itemizedlist>
28100 </listitem>
28101 <listitem>
28102 <simpara>
28103 <literal>mlyacc</literal>
28104 </simpara>
28105 <itemizedlist>
28106 <listitem>
28107 <simpara>
28108 Generate <literal>(*#line line:col "file.grm" *)</literal> directives with simple (relative) file names, rather than absolute paths.
28109 </simpara>
28110 </listitem>
28111 <listitem>
28112 <simpara>
28113 Fixed bug in comment-handling in lexer.
28114 </simpara>
28115 </listitem>
28116 </itemizedlist>
28117 </listitem>
28118 </itemizedlist>
28119 </listitem>
28120 </itemizedlist>
28121 <simpara>For a complete list of changes and bug fixes since
28122 <link linkend="Release20100608">Release20100608</link>, see the
28123 <ulink url="https://raw.github.com/MLton/mlton/on-20130715-release/doc/changelog"><literal>changelog</literal></ulink> and
28124 <link linkend="Bugs20100608">Bugs20100608</link>.</simpara>
28125 </section>
28126 <section id="_20130715_binary_packages">
28127 <title>20130715 binary packages</title>
28128 <itemizedlist>
28129 <listitem>
28130 <simpara>
28131 AMD64 (aka "x86-64" or "x64")
28132 </simpara>
28133 <itemizedlist>
28134 <listitem>
28135 <simpara>
28136 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20130715/mlton-20130715-1.amd64-darwin.gmp-macports.tgz">Darwin (.tgz)</ulink> 11.4 (Mac OS X Lion), dynamically linked against <link linkend="GnuMP">GnuMP</link> in <literal>/opt/local/lib</literal> (suitable for <ulink url="http://macports.org">MacPorts</ulink> install of <link linkend="GnuMP">GnuMP</link>)
28137 </simpara>
28138 </listitem>
28139 <listitem>
28140 <simpara>
28141 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20130715/mlton-20130715-1.amd64-darwin.gmp-static.tgz">Darwin (.tgz)</ulink> 11.4 (Mac OS X Lion), statically linked against <link linkend="GnuMP">GnuMP</link> (but requires <link linkend="GnuMP">GnuMP</link> for generated executables)
28142 </simpara>
28143 </listitem>
28144 <listitem>
28145 <simpara>
28146 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20130715/mlton-20130715-1.amd64-linux.tgz">Linux</ulink>, glibc 2.15
28147
28148 </simpara>
28149 </listitem>
28150 </itemizedlist>
28151 </listitem>
28152 <listitem>
28153 <simpara>
28154 X86
28155 </simpara>
28156 <itemizedlist>
28157 <listitem>
28158 <simpara>
28159 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20130715/mlton-20130715-1.x86-linux.tgz">Linux</ulink>, glibc 2.15
28160
28161 </simpara>
28162 </listitem>
28163 </itemizedlist>
28164 </listitem>
28165 </itemizedlist>
28166 </section>
28167 <section id="_20130715_source_packages">
28168 <title>20130715 source packages</title>
28169 <itemizedlist>
28170 <listitem>
28171 <simpara>
28172 <ulink url="http://sourceforge.net/projects/mlton/files/mlton/20130715/mlton-20130715.src.tgz">mlton-20130715.src.tgz</ulink>
28173 </simpara>
28174 </listitem>
28175 </itemizedlist>
28176 </section>
28177 <section id="_downstream_packages">
28178 <title>Downstream packages</title>
28179 <itemizedlist>
28180 <listitem>
28181 <simpara>
28182 <ulink url="http://packages.debian.org/search?keywords=mlton&amp;searchon=names&amp;suite=all&amp;section=all">Debian</ulink>
28183 </simpara>
28184 </listitem>
28185 <listitem>
28186 <simpara>
28187 <ulink url="http://www.freebsd.org/cgi/ports.cgi?query=mlton&amp;stype=all">FreeBSD</ulink>
28188 </simpara>
28189 </listitem>
28190 <listitem>
28191 <simpara>
28192 <ulink url="https://admin.fedoraproject.org/pkgdb/acls/name/mlton">Fedora</ulink>
28193 </simpara>
28194 </listitem>
28195 <listitem>
28196 <simpara>
28197 <ulink url="http://packages.ubuntu.com/search?suite=default&amp;section=all&amp;arch=any&amp;searchon=names&amp;keywords=mlton">Ubuntu</ulink>
28198 </simpara>
28199 </listitem>
28200 </itemizedlist>
28201 </section>
28202 <section id="_also_see_35">
28203 <title>Also see</title>
28204 <itemizedlist>
28205 <listitem>
28206 <simpara>
28207 <link linkend="Bugs20130715">Bugs20130715</link>
28208 </simpara>
28209 </listitem>
28210 <listitem>
28211 <simpara>
28212 <ulink url="http://www.mlton.org/guide/20130715/">MLton Guide (20130715)</ulink>.
28213 </simpara>
28214 <simpara>A snapshot of the MLton website at the time of release.</simpara>
28215 </listitem>
28216 </itemizedlist>
28217 <simpara><?asciidoc-pagebreak?></simpara>
28218 </section>
28219 </section>
28220 <section id="Release20180207">
28221 <title>Release20180207</title>
28222 <simpara>Here you can download the latest public release of MLton, version 20180207.</simpara>
28223 <section id="_changes_since_the_last_public_release_6">
28224 <title>Changes since the last public release</title>
28225 <itemizedlist>
28226 <listitem>
28227 <simpara>
28228 Compiler.
28229 </simpara>
28230 <itemizedlist>
28231 <listitem>
28232 <simpara>
28233 Added an experimental LLVM codegen (<literal>-codegen llvm</literal>); requires LLVM tools
28234 (<literal>llvm-as</literal>, <literal>opt</literal>, <literal>llc</literal>) version &ge; 3.7.
28235 </simpara>
28236 </listitem>
28237 <listitem>
28238 <simpara>
28239 Made many substantial cosmetic improvements to front-end diagnostic
28240 messages, especially with respect to source location regions, type inference
28241 for <literal>fun</literal> and <literal>val rec</literal> declarations, signature constraints applied to a
28242 structure, <literal>sharing type</literal> specifications and <literal>where type</literal> signature
28243 expressions, type constructor or type variable escaping scope, and
28244 nonexhaustive pattern matching.
28245 </simpara>
28246 </listitem>
28247 <listitem>
28248 <simpara>
28249 Fixed minor bugs with exception replication, precedence parsing of function
28250 clauses, and simultaneous <literal>sharing</literal> of multiple structures.
28251 </simpara>
28252 </listitem>
28253 <listitem>
28254 <simpara>
28255 Made compilation deterministic (eliminate output executable name from
28256 compile-time specified <literal>@MLton</literal> runtime arguments; deterministically generate
28257 magic constant for executable).
28258 </simpara>
28259 </listitem>
28260 <listitem>
28261 <simpara>
28262 Updated <literal>-show-basis</literal> (recursively expand structures in environments,
28263 displaying components with long identifiers; append <literal>(* @ region *)</literal>
28264 annotations to items shown in environment).
28265 </simpara>
28266 </listitem>
28267 <listitem>
28268 <simpara>
28269 Forced amd64 codegen to generate PIC on amd64-linux targets.
28270 </simpara>
28271 </listitem>
28272 </itemizedlist>
28273 </listitem>
28274 <listitem>
28275 <simpara>
28276 Runtime.
28277 </simpara>
28278 <itemizedlist>
28279 <listitem>
28280 <simpara>
28281 Added <literal>gc-summary-file file</literal> runtime option.
28282 </simpara>
28283 </listitem>
28284 <listitem>
28285 <simpara>
28286 Reorganized runtime support for <literal>IntInf</literal> operations so that programs that
28287 do not use <literal>IntInf</literal> compile to executables with no residual dependency on GMP.
28288 </simpara>
28289 </listitem>
28290 <listitem>
28291 <simpara>
28292 Changed heap representation to store forwarding pointer for an object in
28293 the object header (rather than in the object data and setting the header to a
28294 sentinel value).
28295 </simpara>
28296 </listitem>
28297 </itemizedlist>
28298 </listitem>
28299 <listitem>
28300 <simpara>
28301 Language.
28302 </simpara>
28303 <itemizedlist>
28304 <listitem>
28305 <simpara>
28306 Added support for selected SuccessorML features; see
28307 <ulink url="http://mlton.org/SuccessorML">http://mlton.org/SuccessorML</ulink> for details.
28308 </simpara>
28309 </listitem>
28310 <listitem>
28311 <simpara>
28312 Added <literal>(*#showBasis "file" *)</literal> directive; see
28313 <ulink url="http://mlton.org/ShowBasisDirective">http://mlton.org/ShowBasisDirective</ulink> for details.
28314 </simpara>
28315 </listitem>
28316 <listitem>
28317 <simpara>
28318 FFI:
28319 </simpara>
28320 <itemizedlist>
28321 <listitem>
28322 <simpara>
28323 Added <literal>pure</literal>, <literal>impure</literal>, and <literal>reentrant</literal> attributes to <literal>_import</literal>. An
28324 unattributed <literal>_import</literal> is treated as <literal>impure</literal>. A <literal>pure</literal> <literal>_import</literal> may be
28325 subject to more aggressive optimizations (common subexpression elimination,
28326 dead-code elimination). An <literal>_import</literal>-ed C function that (directly or
28327 indirectly) calls an <literal>_export</literal>-ed SML function should be attributed
28328 <literal>reentrant</literal>.
28329 </simpara>
28330 </listitem>
28331 </itemizedlist>
28332 </listitem>
28333 <listitem>
28334 <simpara>
28335 ML Basis annotations.
28336 </simpara>
28337 <itemizedlist>
28338 <listitem>
28339 <simpara>
28340 Added <literal>allowSuccessorML {false|true}</literal> to enable all SuccessorML features
28341 and other annotations to enable specific SuccessorML features; see
28342 <ulink url="http://mlton.org/SuccessorML">http://mlton.org/SuccessorML</ulink> for details.
28343 </simpara>
28344 </listitem>
28345 <listitem>
28346 <simpara>
28347 Split <literal>nonexhaustiveMatch {warn|error|igore}</literal> and <literal>redundantMatch
28348 {warn|error|ignore}</literal> into <literal>nonexhaustiveMatch</literal> and <literal>redundantMatch</literal>
28349 (controls diagnostics for <literal>case</literal> expressions, <literal>fn</literal> expressions, and <literal>fun</literal>
28350 declarations (which may raise <literal>Match</literal> on failure)) and <literal>nonexhaustiveBind</literal>
28351 and <literal>redundantBind</literal> (controls diagnostics for <literal>val</literal> declarations (which may
28352 raise <literal>Bind</literal> on failure)).
28353 </simpara>
28354 </listitem>
28355 <listitem>
28356 <simpara>
28357 Added <literal>valrecConstr {warn|error|ignore}</literal> to report when a <literal>val rec</literal> (or
28358 <literal>fun</literal>) declaration redefines an identifier that previously had constructor
28359 status.
28360 </simpara>
28361 </listitem>
28362 </itemizedlist>
28363 </listitem>
28364 </itemizedlist>
28365 </listitem>
28366 <listitem>
28367 <simpara>
28368 Libraries.
28369 </simpara>
28370 <itemizedlist>
28371 <listitem>
28372 <simpara>
28373 Basis Library.
28374 </simpara>
28375 <itemizedlist>
28376 <listitem>
28377 <simpara>
28378 Improved performance of <literal>Array.copy</literal>, <literal>Array.copyVec</literal>, <literal>Vector.append</literal>,
28379 <literal>String.^</literal>, <literal>String.concat</literal>, <literal>String.concatWith</literal>, and other related
28380 functions by using <literal>memmove</literal> rather than element-by-element constructions.
28381 </simpara>
28382 </listitem>
28383 </itemizedlist>
28384 </listitem>
28385 <listitem>
28386 <simpara>
28387 <literal>Unsafe</literal> structure.
28388 </simpara>
28389 <itemizedlist>
28390 <listitem>
28391 <simpara>
28392 Added unsafe operations for array uninitialization and raw arrays; see
28393 <ulink url="https://github.com/MLton/mlton/pull/207">https://github.com/MLton/mlton/pull/207</ulink> for details.
28394 </simpara>
28395 </listitem>
28396 </itemizedlist>
28397 </listitem>
28398 <listitem>
28399 <simpara>
28400 Other libraries.
28401 </simpara>
28402 <itemizedlist>
28403 <listitem>
28404 <simpara>
28405 Updated: ckit library, MLLPT library, MLRISC library, SML/NJ library
28406 </simpara>
28407 </listitem>
28408 </itemizedlist>
28409 </listitem>
28410 </itemizedlist>
28411 </listitem>
28412 <listitem>
28413 <simpara>
28414 Tools.
28415 </simpara>
28416 <itemizedlist>
28417 <listitem>
28418 <simpara>
28419 mlnlffigen
28420 </simpara>
28421 <itemizedlist>
28422 <listitem>
28423 <simpara>
28424 Updated to warn and skip (rather than abort) when encountering functions
28425 with <literal>struct</literal>/<literal>union</literal> argument or return type.
28426 </simpara>
28427 </listitem>
28428 </itemizedlist>
28429 </listitem>
28430 </itemizedlist>
28431 </listitem>
28432 </itemizedlist>
28433 <simpara>For a complete list of changes and bug fixes since
28434 <link linkend="Release20130715">Release20130715</link>, see the
28435 <ulink url="https://github.com/MLton/mlton/blob/on-20180207-release/CHANGELOG.adoc"><literal>CHANGELOG.adoc</literal></ulink> and
28436 <link linkend="Bugs20130715">Bugs20130715</link>.</simpara>
28437 </section>
28438 <section id="_20180207_binary_packages">
28439 <title>20180207 binary packages</title>
28440 <itemizedlist>
28441 <listitem>
28442 <simpara>
28443 AMD64 (aka "x86-64" or "x64")
28444 </simpara>
28445 <itemizedlist>
28446 <listitem>
28447 <simpara>
28448 <ulink url="https://sourceforge.net/projects/mlton/files/mlton/20180207/mlton-20180207-1.amd64-darwin.gmp-homebrew.tgz">Darwin (.tgz)</ulink> 16.7 (Mac OS X Sierra), dynamically linked against <link linkend="GnuMP">GnuMP</link> in <literal>/usr/local/lib</literal> (suitable for <ulink url="https://brew.sh/">Homebrew</ulink> install of <link linkend="GnuMP">GnuMP</link>)
28449 </simpara>
28450 </listitem>
28451 <listitem>
28452 <simpara>
28453 <ulink url="https://sourceforge.net/projects/mlton/files/mlton/20180207/mlton-20180207-1.amd64-darwin.gmp-static.tgz">Darwin (.tgz)</ulink> 16.7 (Mac OS X Sierra), statically linked against <link linkend="GnuMP">GnuMP</link> (but requires <link linkend="GnuMP">GnuMP</link> for generated executables)
28454 </simpara>
28455 </listitem>
28456 <listitem>
28457 <simpara>
28458 <ulink url="https://sourceforge.net/projects/mlton/files/mlton/20180207/mlton-20180207-1.amd64-linux.tgz">Linux</ulink>, glibc 2.23
28459
28460
28461
28462
28463
28464 </simpara>
28465 </listitem>
28466 </itemizedlist>
28467 </listitem>
28468 </itemizedlist>
28469 </section>
28470 <section id="_20180207_source_packages">
28471 <title>20180207 source packages</title>
28472 <itemizedlist>
28473 <listitem>
28474 <simpara>
28475 <ulink url="https://sourceforge.net/projects/mlton/files/mlton/20180207/mlton-20180207.src.tgz">mlton-20180207.src.tgz</ulink>
28476 </simpara>
28477 </listitem>
28478 </itemizedlist>
28479 </section>
28480 <section id="_also_see_36">
28481 <title>Also see</title>
28482 <itemizedlist>
28483 <listitem>
28484 <simpara>
28485 <link linkend="Bugs20180207">Bugs20180207</link>
28486 </simpara>
28487 </listitem>
28488 <listitem>
28489 <simpara>
28490 <ulink url="http://www.mlton.org/guide/20180207/">MLton Guide (20180207)</ulink>.
28491 </simpara>
28492 <simpara>A snapshot of the MLton website at the time of release.</simpara>
28493 </listitem>
28494 </itemizedlist>
28495 <simpara><?asciidoc-pagebreak?></simpara>
28496 </section>
28497 </section>
28498 <section id="ReleaseChecklist">
28499 <title>ReleaseChecklist</title>
28500 <section id="_advance_preparation_for_release">
28501 <title>Advance preparation for release</title>
28502 <itemizedlist>
28503 <listitem>
28504 <simpara>
28505 Update <literal>./CHANGELOG.adoc</literal>.
28506 </simpara>
28507 <itemizedlist>
28508 <listitem>
28509 <simpara>
28510 Write entries for missing notable commits.
28511 </simpara>
28512 </listitem>
28513 <listitem>
28514 <simpara>
28515 Write summary of changes from previous release.
28516 </simpara>
28517 </listitem>
28518 <listitem>
28519 <simpara>
28520 Update with estimated release date.
28521 </simpara>
28522 </listitem>
28523 </itemizedlist>
28524 </listitem>
28525 <listitem>
28526 <simpara>
28527 Update <literal>./README.adoc</literal>.
28528 </simpara>
28529 <itemizedlist>
28530 <listitem>
28531 <simpara>
28532 Check features and description.
28533 </simpara>
28534 </listitem>
28535 </itemizedlist>
28536 </listitem>
28537 <listitem>
28538 <simpara>
28539 Update <literal>man/{mlton,mlprof}.1</literal>.
28540 </simpara>
28541 <itemizedlist>
28542 <listitem>
28543 <simpara>
28544 Check compile-time and run-time options in <literal>man/mlton.1</literal>.
28545 </simpara>
28546 </listitem>
28547 <listitem>
28548 <simpara>
28549 Check options in <literal>man/mlprof.1</literal>.
28550 </simpara>
28551 </listitem>
28552 <listitem>
28553 <simpara>
28554 Update with estimated release date.
28555 </simpara>
28556 </listitem>
28557 </itemizedlist>
28558 </listitem>
28559 <listitem>
28560 <simpara>
28561 Update <literal>doc/guide</literal>.
28562 </simpara>
28563 <itemizedlist>
28564 <listitem>
28565 <simpara>
28566 Synchronize <link linkend="Features">Features</link> page with <literal>./README.adoc</literal>.
28567 </simpara>
28568 </listitem>
28569 <listitem>
28570 <simpara>
28571 Update <link linkend="Credits">Credits</link> page with acknowledgements.
28572 </simpara>
28573 </listitem>
28574 <listitem>
28575 <simpara>
28576 Create <emphasis role="strong">ReleaseYYYYMM??</emphasis> page (i.e., forthcoming release) based on <emphasis role="strong">ReleaseXXXXLLCC</emphasis> (i.e., previous release).
28577 </simpara>
28578 <itemizedlist>
28579 <listitem>
28580 <simpara>
28581 Update summary from <literal>./CHANGELOG.adoc</literal>.
28582 </simpara>
28583 </listitem>
28584 <listitem>
28585 <simpara>
28586 Update links to estimated release date.
28587 </simpara>
28588 </listitem>
28589 </itemizedlist>
28590 </listitem>
28591 <listitem>
28592 <simpara>
28593 Create <emphasis role="strong">BugsYYYYMM??</emphasis> page based on <emphasis role="strong">BugsXXXXLLCC</emphasis>.
28594 </simpara>
28595 <itemizedlist>
28596 <listitem>
28597 <simpara>
28598 Update links to estimated release date.
28599 </simpara>
28600 </listitem>
28601 </itemizedlist>
28602 </listitem>
28603 <listitem>
28604 <simpara>
28605 Spell check pages.
28606 </simpara>
28607 </listitem>
28608 </itemizedlist>
28609 </listitem>
28610 <listitem>
28611 <simpara>
28612 Ensure that all updates are pushed to <literal>master</literal> branch of <ulink url="https://github.com/MLton/mlton"><literal>mlton</literal></ulink>.
28613 </simpara>
28614 </listitem>
28615 </itemizedlist>
28616 </section>
28617 <section id="_prepare_sources_for_tagging">
28618 <title>Prepare sources for tagging</title>
28619 <itemizedlist>
28620 <listitem>
28621 <simpara>
28622 Update <literal>./CHANGELOG.adoc</literal>.
28623 </simpara>
28624 <itemizedlist>
28625 <listitem>
28626 <simpara>
28627 Update with proper release date.
28628 </simpara>
28629 </listitem>
28630 </itemizedlist>
28631 </listitem>
28632 <listitem>
28633 <simpara>
28634 Update <literal>man/{mlton,mlprof}.1</literal>.
28635 </simpara>
28636 <itemizedlist>
28637 <listitem>
28638 <simpara>
28639 Update with proper release date.
28640 </simpara>
28641 </listitem>
28642 </itemizedlist>
28643 </listitem>
28644 <listitem>
28645 <simpara>
28646 Update <literal>doc/guide</literal>.
28647 </simpara>
28648 <itemizedlist>
28649 <listitem>
28650 <simpara>
28651 Rename <emphasis role="strong">ReleaseYYYYMM??</emphasis> to <emphasis role="strong">ReleaseYYYYMMDD</emphasis> with proper release date.
28652 </simpara>
28653 <itemizedlist>
28654 <listitem>
28655 <simpara>
28656 Update links with proper release date.
28657 </simpara>
28658 </listitem>
28659 </itemizedlist>
28660 </listitem>
28661 <listitem>
28662 <simpara>
28663 Rename <emphasis role="strong">BugsYYYYMM??</emphasis> to <emphasis role="strong">BugsYYYYMMDD</emphasis> with proper release date.
28664 </simpara>
28665 <itemizedlist>
28666 <listitem>
28667 <simpara>
28668 Update links with proper release date.
28669 </simpara>
28670 </listitem>
28671 </itemizedlist>
28672 </listitem>
28673 <listitem>
28674 <simpara>
28675 Update <emphasis role="strong">ReleaseXXXXLLCC</emphasis>.
28676 </simpara>
28677 <itemizedlist>
28678 <listitem>
28679 <simpara>
28680 Change intro to "<literal>This is an archived public release of MLton, version XXXXLLCC.</literal>"
28681 </simpara>
28682 </listitem>
28683 </itemizedlist>
28684 </listitem>
28685 <listitem>
28686 <simpara>
28687 Update <link linkend="Home">Home</link> with note of new release.
28688 </simpara>
28689 <itemizedlist>
28690 <listitem>
28691 <simpara>
28692 Change <literal>What's new?</literal> text to <literal>Please try out our new release, &lt;:ReleaseYYYYMMDD:MLton YYYYMMDD&gt;</literal>.
28693 </simpara>
28694 </listitem>
28695 <listitem>
28696 <simpara>
28697 Update <literal>Download</literal> link with proper release date.
28698 </simpara>
28699 </listitem>
28700 </itemizedlist>
28701 </listitem>
28702 <listitem>
28703 <simpara>
28704 Update <link linkend="Releases">Releases</link> with new release.
28705 </simpara>
28706 </listitem>
28707 </itemizedlist>
28708 </listitem>
28709 <listitem>
28710 <simpara>
28711 Ensure that all updates are pushed to <literal>master</literal> branch of <ulink url="https://github.com/MLton/mlton"><literal>mlton</literal></ulink>.
28712 </simpara>
28713 </listitem>
28714 </itemizedlist>
28715 </section>
28716 <section id="_tag_sources">
28717 <title>Tag sources</title>
28718 <itemizedlist>
28719 <listitem>
28720 <simpara>
28721 Shell commands:
28722 </simpara>
28723 <screen>git clone http://github.com/MLton/mlton mlton.git
28724 cd mlton.git
28725 git checkout master
28726 git tag -a -m "Tagging YYYYMMDD release" on-YYYYMMDD-release master
28727 git push origin on-YYYYMMDD-release</screen>
28728 </listitem>
28729 </itemizedlist>
28730 </section>
28731 <section id="_packaging">
28732 <title>Packaging</title>
28733 <section id="_sourceforge_frs">
28734 <title>SourceForge FRS</title>
28735 <itemizedlist>
28736 <listitem>
28737 <simpara>
28738 Create <emphasis role="strong">YYYYMMDD</emphasis> directory:
28739 </simpara>
28740 <screen>sftp user@frs.sourceforge.net:/home/frs/project/mlton/mlton
28741 sftp&gt; mkdir YYYYMMDD
28742 sftp&gt; quit</screen>
28743 </listitem>
28744 </itemizedlist>
28745 </section>
28746 <section id="_source_release">
28747 <title>Source release</title>
28748 <itemizedlist>
28749 <listitem>
28750 <simpara>
28751 Create <literal>mlton-YYYYMMDD.src.tgz</literal>:
28752 </simpara>
28753 <screen>git clone http://github.com/MLton/mlton mlton
28754 cd mlton
28755 git checkout on-YYYYMMDD-release
28756 make MLTON_VERSION=YYYYMMDD source-release
28757 cd ..</screen>
28758 <simpara>or</simpara>
28759 <screen>wget https://github.com/MLton/mlton/archive/on-YYYYMMDD-release.tar.gz
28760 tar xzvf on-YYYYMMDD-release.tar.gz
28761 cd mlton-on-YYYYMMDD-release
28762 make MLTON_VERSION=YYYYMMDD source-release
28763 cd ..</screen>
28764 </listitem>
28765 <listitem>
28766 <simpara>
28767 Upload <literal>mlton-YYYYMMDD.src.tgz</literal>:
28768 </simpara>
28769 <screen>scp mlton-YYYYMMDD.src.tgz user@frs.sourceforge.net:/home/frs/project/mlton/mlton/YYYYMMDD/</screen>
28770 </listitem>
28771 <listitem>
28772 <simpara>
28773 Update <emphasis role="strong">ReleaseYYYYMMDD</emphasis> with <literal>mlton-YYYYMMDD.src.tgz</literal> link.
28774 </simpara>
28775 </listitem>
28776 </itemizedlist>
28777 </section>
28778 <section id="_binary_releases">
28779 <title>Binary releases</title>
28780 <itemizedlist>
28781 <listitem>
28782 <simpara>
28783 Build and create <literal>mlton-YYYYMMDD-1.ARCH-OS.tgz</literal>:
28784 </simpara>
28785 <screen>wget http://sourceforge.net/projects/mlton/files/mlton/YYYYMMDD/mlton-YYYYMMDD.src.tgz
28786 tar xzvf mlton-YYYYMMDD.src.tgz
28787 cd mlton-YYYYMMDD
28788 make binary-release
28789 cd ..</screen>
28790 </listitem>
28791 <listitem>
28792 <simpara>
28793 Upload <literal>mlton-YYYYMMDD-1.ARCH-OS.tgz</literal>:
28794 </simpara>
28795 <screen>scp mlton-YYYYMMDD-1.ARCH-OS.tgz user@frs.sourceforge.net:/home/frs/project/mlton/mlton/YYYYMMDD/</screen>
28796 </listitem>
28797 <listitem>
28798 <simpara>
28799 Update <emphasis role="strong">ReleaseYYYYMMDD</emphasis> with <literal>mlton-YYYYMMDD-1.ARCH-OS.tgz</literal> link.
28800 </simpara>
28801 </listitem>
28802 </itemizedlist>
28803 </section>
28804 </section>
28805 <section id="_website">
28806 <title>Website</title>
28807 <itemizedlist>
28808 <listitem>
28809 <simpara>
28810 <literal>guide/YYYYMMDD</literal> gets a copy of <literal>doc/guide/localhost</literal>.
28811 </simpara>
28812 </listitem>
28813 <listitem>
28814 <simpara>
28815 Shell commands:
28816 </simpara>
28817 <screen>wget http://sourceforge.net/projects/mlton/files/mlton/YYYYMMDD/mlton-YYYYMMDD.src.tgz
28818 tar xzvf mlton-YYYYMMDD.src.tgz
28819 cd mlton-YYYYMMDD
28820 cd doc/guide
28821 cp -prf localhost YYYYMMDD
28822 tar czvf guide-YYYYMMDD.tgz YYYYMMDD
28823 rsync -avzP --delete -e ssh YYYYMMDD user@web.sourceforge.net:/home/project-web/mlton/htdocs/guide/
28824 rsync -avzP --delete -e ssh guide-YYYYMMDD.tgz user@web.sourceforge.net:/home/project-web/mlton/htdocs/guide/</screen>
28825 </listitem>
28826 </itemizedlist>
28827 </section>
28828 <section id="_announce_release">
28829 <title>Announce release</title>
28830 <itemizedlist>
28831 <listitem>
28832 <simpara>
28833 Mail announcement to:
28834 </simpara>
28835 <itemizedlist>
28836 <listitem>
28837 <simpara>
28838 <ulink url="mailto:MLton-devel@mlton.org"><literal>MLton-devel@mlton.org</literal></ulink>
28839 </simpara>
28840 </listitem>
28841 <listitem>
28842 <simpara>
28843 <ulink url="mailto:MLton-user@mlton.org"><literal>MLton-user@mlton.org</literal></ulink>
28844 </simpara>
28845 </listitem>
28846 </itemizedlist>
28847 </listitem>
28848 </itemizedlist>
28849 </section>
28850 <section id="_misc">
28851 <title>Misc.</title>
28852 <itemizedlist>
28853 <listitem>
28854 <simpara>
28855 Generate new <link linkend="Performance">Performance</link> numbers.
28856 </simpara>
28857 </listitem>
28858 </itemizedlist>
28859 <simpara><?asciidoc-pagebreak?></simpara>
28860 </section>
28861 </section>
28862 <section id="Releases">
28863 <title>Releases</title>
28864 <simpara>Public releases of MLton:</simpara>
28865 <itemizedlist>
28866 <listitem>
28867 <simpara>
28868 <link linkend="Release20180207">Release20180207</link>
28869 </simpara>
28870 </listitem>
28871 <listitem>
28872 <simpara>
28873 <link linkend="Release20130715">Release20130715</link>
28874 </simpara>
28875 </listitem>
28876 <listitem>
28877 <simpara>
28878 <link linkend="Release20100608">Release20100608</link>
28879 </simpara>
28880 </listitem>
28881 <listitem>
28882 <simpara>
28883 <link linkend="Release20070826">Release20070826</link>
28884 </simpara>
28885 </listitem>
28886 <listitem>
28887 <simpara>
28888 <link linkend="Release20051202">Release20051202</link>
28889 </simpara>
28890 </listitem>
28891 <listitem>
28892 <simpara>
28893 <link linkend="Release20041109">Release20041109</link>
28894 </simpara>
28895 </listitem>
28896 <listitem>
28897 <simpara>
28898 Release20040227
28899 </simpara>
28900 </listitem>
28901 <listitem>
28902 <simpara>
28903 Release20030716
28904 </simpara>
28905 </listitem>
28906 <listitem>
28907 <simpara>
28908 Release20030711
28909 </simpara>
28910 </listitem>
28911 <listitem>
28912 <simpara>
28913 Release20030312
28914 </simpara>
28915 </listitem>
28916 <listitem>
28917 <simpara>
28918 Release20020923
28919 </simpara>
28920 </listitem>
28921 <listitem>
28922 <simpara>
28923 Release20020410
28924 </simpara>
28925 </listitem>
28926 <listitem>
28927 <simpara>
28928 Release20011006
28929 </simpara>
28930 </listitem>
28931 <listitem>
28932 <simpara>
28933 Release20010806
28934 </simpara>
28935 </listitem>
28936 <listitem>
28937 <simpara>
28938 Release20010706
28939 </simpara>
28940 </listitem>
28941 <listitem>
28942 <simpara>
28943 Release20000906
28944 </simpara>
28945 </listitem>
28946 <listitem>
28947 <simpara>
28948 Release20000712
28949 </simpara>
28950 </listitem>
28951 <listitem>
28952 <simpara>
28953 Release19990712
28954 </simpara>
28955 </listitem>
28956 <listitem>
28957 <simpara>
28958 Release19990319
28959 </simpara>
28960 </listitem>
28961 <listitem>
28962 <simpara>
28963 Release19980826
28964 </simpara>
28965 </listitem>
28966 </itemizedlist>
28967 <simpara><?asciidoc-pagebreak?></simpara>
28968 </section>
28969 <section id="RemoveUnused">
28970 <title>RemoveUnused</title>
28971 <simpara><link linkend="RemoveUnused">RemoveUnused</link> is an optimization pass for both the <link linkend="SSA">SSA</link> and
28972 <link linkend="SSA2">SSA2</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>s, invoked from <link linkend="SSASimplify">SSASimplify</link> and
28973 <link linkend="SSA2Simplify">SSA2Simplify</link>.</simpara>
28974 <section id="_description_49">
28975 <title>Description</title>
28976 <simpara>This pass aggressively removes unused:</simpara>
28977 <itemizedlist>
28978 <listitem>
28979 <simpara>
28980 datatypes
28981 </simpara>
28982 </listitem>
28983 <listitem>
28984 <simpara>
28985 datatype constructors
28986 </simpara>
28987 </listitem>
28988 <listitem>
28989 <simpara>
28990 datatype constructor arguments
28991 </simpara>
28992 </listitem>
28993 <listitem>
28994 <simpara>
28995 functions
28996 </simpara>
28997 </listitem>
28998 <listitem>
28999 <simpara>
29000 function arguments
29001 </simpara>
29002 </listitem>
29003 <listitem>
29004 <simpara>
29005 function returns
29006 </simpara>
29007 </listitem>
29008 <listitem>
29009 <simpara>
29010 blocks
29011 </simpara>
29012 </listitem>
29013 <listitem>
29014 <simpara>
29015 block arguments
29016 </simpara>
29017 </listitem>
29018 <listitem>
29019 <simpara>
29020 statements (variable bindings)
29021 </simpara>
29022 </listitem>
29023 <listitem>
29024 <simpara>
29025 handlers from non-tail calls (mayRaise analysis)
29026 </simpara>
29027 </listitem>
29028 <listitem>
29029 <simpara>
29030 continuations from non-tail calls (mayReturn analysis)
29031 </simpara>
29032 </listitem>
29033 </itemizedlist>
29034 </section>
29035 <section id="_implementation_54">
29036 <title>Implementation</title>
29037 <itemizedlist>
29038 <listitem>
29039 <simpara>
29040 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/remove-unused.fun"><literal>remove-unused.fun</literal></ulink>
29041 </simpara>
29042 </listitem>
29043 <listitem>
29044 <simpara>
29045 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/remove-unused2.fun"><literal>remove-unused2.fun</literal></ulink>
29046 </simpara>
29047 </listitem>
29048 </itemizedlist>
29049 </section>
29050 <section id="_details_and_notes_52">
29051 <title>Details and Notes</title>
29052 <simpara></simpara>
29053 <simpara><?asciidoc-pagebreak?></simpara>
29054 </section>
29055 </section>
29056 <section id="Restore">
29057 <title>Restore</title>
29058 <simpara><link linkend="Restore">Restore</link> is a rewrite pass for the <link linkend="SSA">SSA</link> and <link linkend="SSA2">SSA2</link>
29059 <link linkend="IntermediateLanguage">IntermediateLanguage</link>s, invoked from <link linkend="KnownCase">KnownCase</link> and
29060 <link linkend="LocalRef">LocalRef</link>.</simpara>
29061 <section id="_description_50">
29062 <title>Description</title>
29063 <simpara>This pass restores the SSA condition for a violating <link linkend="SSA">SSA</link> or
29064 <link linkend="SSA2">SSA2</link> program; the program must satisfy:</simpara>
29065 <blockquote>
29066 <simpara>Every path from the root to a use of a variable (excluding globals)
29067 passes through a def of that variable.</simpara>
29068 </blockquote>
29069 </section>
29070 <section id="_implementation_55">
29071 <title>Implementation</title>
29072 <itemizedlist>
29073 <listitem>
29074 <simpara>
29075 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/restore.sig"><literal>restore.sig</literal></ulink>
29076 </simpara>
29077 </listitem>
29078 <listitem>
29079 <simpara>
29080 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/restore.fun"><literal>restore.fun</literal></ulink>
29081 </simpara>
29082 </listitem>
29083 <listitem>
29084 <simpara>
29085 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/restore2.sig"><literal>restore2.sig</literal></ulink>
29086 </simpara>
29087 </listitem>
29088 <listitem>
29089 <simpara>
29090 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/restore2.fun"><literal>restore2.fun</literal></ulink>
29091 </simpara>
29092 </listitem>
29093 </itemizedlist>
29094 </section>
29095 <section id="_details_and_notes_53">
29096 <title>Details and Notes</title>
29097 <simpara>Based primarily on Section 19.1 of <link linkend="References_Appel98">Modern Compiler Implementation in ML</link>.</simpara>
29098 <simpara>The main deviation is the calculation of liveness of the violating
29099 variables, which is used to predicate the insertion of phi arguments.
29100 This is due to the algorithm&#8217;s bias towards imperative languages, for
29101 which it makes the assumption that all variables are defined in the
29102 start block and all variables are "used" at exit.</simpara>
29103 <simpara>This is "optimized" for restoration of functions with small numbers of
29104 violating variables&#8201;&#8212;&#8201;use bool vectors to represent sets of violating
29105 variables.</simpara>
29106 <simpara>Also, we use a <literal>Promise.t</literal> to suspend part of the dominance frontier
29107 computation.</simpara>
29108 <simpara><?asciidoc-pagebreak?></simpara>
29109 </section>
29110 </section>
29111 <section id="ReturnStatement">
29112 <title>ReturnStatement</title>
29113 <simpara>Programmers coming from languages that have a <literal>return</literal> statement, such
29114 as C, Java, and Python, often ask how one can translate functions that
29115 return early into SML. This page briefly describes a number of ways
29116 to translate uses of <literal>return</literal> to SML.</simpara>
29117 <section id="_conditional_iterator_function">
29118 <title>Conditional iterator function</title>
29119 <simpara>A conditional iterator function, such as
29120 <ulink url="http://www.standardml.org/Basis/list.html#SIG:LIST.find:VAL"><literal>List.find</literal></ulink>,
29121 <ulink url="http://www.standardml.org/Basis/list.html#SIG:LIST.exists:VAL"><literal>List.exists</literal></ulink>,
29122 or
29123 <ulink url="http://www.standardml.org/Basis/list.html#SIG:LIST.all:VAL"><literal>List.all</literal></ulink>
29124 is probably what you want in most cases. Unfortunately, it might be
29125 the case that the particular conditional iteration pattern that you
29126 want isn&#8217;t provided for your data structure. Usually the best
29127 alternative in such a case is to implement the desired iteration
29128 pattern as a higher-order function. For example, to implement a
29129 <literal>find</literal> function for arrays (which already exists as
29130 <ulink url="http://www.standardml.org/Basis/array.html#SIG:ARRAY.findi:VAL"><literal>Array.find</literal></ulink>)
29131 one could write</simpara>
29132 <programlisting language="sml" linenumbering="unnumbered">fun find predicate array = let
29133 fun loop i =
29134 if i = Array.length array then
29135 NONE
29136 else if predicate (Array.sub (array, i)) then
29137 SOME (Array.sub (array, i))
29138 else
29139 loop (i+1)
29140 in
29141 loop 0
29142 end</programlisting>
29143 <simpara>Of course, this technique, while probably the most common case in
29144 practice, applies only if you are essentially iterating over some data
29145 structure.</simpara>
29146 </section>
29147 <section id="_escape_handler">
29148 <title>Escape handler</title>
29149 <simpara>Probably the most direct way to translate code using <literal>return</literal>
29150 statements is to basically implement <literal>return</literal> using exception
29151 handling. The mechanism can be packaged into a reusable module with
29152 the signature
29153 (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/extended-basis/unstable/public/control/exit.sig"><literal>exit.sig</literal></ulink>):</simpara>
29154 <programlisting language="sml" linenumbering="unnumbered">(**
29155 * Signature for exit (or escape) handlers.
29156 *
29157 * Note that the implementation necessarily uses exception handling. This
29158 * is to make proper resource handling possible. Exceptions raised by the
29159 * implementation can be caught by wildcard exception handlers. Wildcard
29160 * exception handlers should generally reraise exceptions after performing
29161 * their effects.
29162 *)
29163 signature EXIT = sig
29164 type 'a t
29165 (** The type of exits. *)
29166
29167 val within : ('a t, 'a) CPS.t
29168 (**
29169 * Sets up an exit and passes it to the given function. The function
29170 * may then return normally or by calling {to} with the exit and a
29171 * return value. For example,
29172 *
29173 *&gt; Exit.within
29174 *&gt; (fn l =&gt;
29175 *&gt; if condition then
29176 *&gt; Exit.to l 1
29177 *&gt; else
29178 *&gt; 2)
29179 *
29180 * evaluates either to {1} or to {2} depending on the {condition}.
29181 *
29182 * Note that the function receiving the exit is called from a non-tail
29183 * position.
29184 *)
29185
29186 val to : 'a t -&gt; 'a -&gt; 'b
29187 (**
29188 * {to l v} returns from the {within} invocation that introduced the
29189 * exit {l} with the value {v}. Evaluating {to l v} outside of the
29190 * {within} invocation that introduced {l} is a programming error and
29191 * raises an exception.
29192 *
29193 * Note that the type variable {'b} only appears as the return type.
29194 * This means that {to} doesn't return normally to the caller and can
29195 * be called from a context of any type.
29196 *)
29197
29198 val call : ('a -&gt; 'b, 'a) CPS.t
29199 (**
29200 * Simpler, but less flexibly typed, interface to {within} and {to}.
29201 * Specifically, {call f} is equivalent to {within (f o to)}.
29202 *)
29203 end</programlisting>
29204 <simpara>(<link linkend="References_HarperEtAl93">Typing First-Class Continuations in ML</link>
29205 discusses the typing of a related construct.) The implementation
29206 (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/extended-basis/unstable/detail/control/exit.sml"><literal>exit.sml</literal></ulink>)
29207 is straightforward:</simpara>
29208 <programlisting language="sml" linenumbering="unnumbered">structure Exit :&gt; EXIT = struct
29209 type 'a t = 'a -&gt; exn
29210
29211 fun within block = let
29212 exception EscapedExit of 'a
29213 in
29214 block EscapedExit
29215 handle EscapedExit value =&gt; value
29216 end
29217
29218 fun to exit value = raise exit value
29219
29220 fun call block = within (block o to)
29221 end</programlisting>
29222 <simpara>Here is an example of how one could implement a <literal>find</literal> function given
29223 an <literal>app</literal> function:</simpara>
29224 <programlisting language="sml" linenumbering="unnumbered">fun appToFind (app : ('a -&gt; unit) -&gt; 'b -&gt; unit)
29225 (predicate : 'a -&gt; bool)
29226 (data : 'b) =
29227 Exit.call
29228 (fn return =&gt;
29229 (app (fn x =&gt;
29230 if predicate x then
29231 return (SOME x)
29232 else
29233 ())
29234 data
29235 ; NONE))</programlisting>
29236 <simpara>In the above, as soon as the expression <literal>predicate x</literal> evaluates to
29237 <literal>true</literal> the <literal>app</literal> invocation is terminated.</simpara>
29238 </section>
29239 <section id="_continuation_passing_style_cps">
29240 <title>Continuation-passing Style (CPS)</title>
29241 <simpara>A general way to implement complex control patterns is to use
29242 <ulink url="http://en.wikipedia.org/wiki/Continuation-passing_style">CPS</ulink>. In CPS,
29243 instead of returning normally, functions invoke a function passed as
29244 an argument. In general, multiple continuation functions may be
29245 passed as arguments and the ordinary return continuation may also be
29246 used. As an example, here is a function that finds the leftmost
29247 element of a binary tree satisfying a given predicate:</simpara>
29248 <programlisting language="sml" linenumbering="unnumbered">datatype 'a tree = LEAF | BRANCH of 'a tree * 'a * 'a tree
29249
29250 fun find predicate = let
29251 fun recurse continue =
29252 fn LEAF =&gt;
29253 continue ()
29254 | BRANCH (lhs, elem, rhs) =&gt;
29255 recurse
29256 (fn () =&gt;
29257 if predicate elem then
29258 SOME elem
29259 else
29260 recurse continue rhs)
29261 lhs
29262 in
29263 recurse (fn () =&gt; NONE)
29264 end</programlisting>
29265 <simpara>Note that the above function returns as soon as the leftmost element
29266 satisfying the predicate is found.</simpara>
29267 <simpara><?asciidoc-pagebreak?></simpara>
29268 </section>
29269 </section>
29270 <section id="RSSA">
29271 <title>RSSA</title>
29272 <simpara><link linkend="RSSA">RSSA</link> is an <link linkend="IntermediateLanguage">IntermediateLanguage</link>, translated from <link linkend="SSA2">SSA2</link> by
29273 <link linkend="ToRSSA">ToRSSA</link>, optimized by <link linkend="RSSASimplify">RSSASimplify</link>, and translated by
29274 <link linkend="ToMachine">ToMachine</link> to <link linkend="Machine">Machine</link>.</simpara>
29275 <section id="_description_51">
29276 <title>Description</title>
29277 <simpara><link linkend="RSSA">RSSA</link> is a <link linkend="IntermediateLanguage">IntermediateLanguage</link> that makes representation
29278 decisions explicit.</simpara>
29279 </section>
29280 <section id="_implementation_56">
29281 <title>Implementation</title>
29282 <itemizedlist>
29283 <listitem>
29284 <simpara>
29285 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/rssa.sig"><literal>rssa.sig</literal></ulink>
29286 </simpara>
29287 </listitem>
29288 <listitem>
29289 <simpara>
29290 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/rssa.fun"><literal>rssa.fun</literal></ulink>
29291 </simpara>
29292 </listitem>
29293 </itemizedlist>
29294 </section>
29295 <section id="_type_checking_4">
29296 <title>Type Checking</title>
29297 <simpara>The new type language is aimed at expressing bit-level control over
29298 layout and associated packing of data representations. There are
29299 singleton types that denote constants, other atomic types for things
29300 like integers and reals, and arbitrary sum types and sequence (tuple)
29301 types. The big change to the type system is that type checking is now
29302 based on subtyping, not type equality. So, for example, the singleton
29303 type <literal>0xFFFFEEBB</literal> whose only inhabitant is the eponymous constant is a
29304 subtype of the type <literal>Word32</literal>.</simpara>
29305 </section>
29306 <section id="_details_and_notes_54">
29307 <title>Details and Notes</title>
29308 <simpara>SSA is an abbreviation for Static Single Assignment. The <link linkend="RSSA">RSSA</link>
29309 <link linkend="IntermediateLanguage">IntermediateLanguage</link> is a variant of SSA.</simpara>
29310 <simpara><?asciidoc-pagebreak?></simpara>
29311 </section>
29312 </section>
29313 <section id="RSSAShrink">
29314 <title>RSSAShrink</title>
29315 <simpara><link linkend="RSSAShrink">RSSAShrink</link> is an optimization pass for the <link linkend="RSSA">RSSA</link>
29316 <link linkend="IntermediateLanguage">IntermediateLanguage</link>.</simpara>
29317 <section id="_description_52">
29318 <title>Description</title>
29319 <simpara>This pass implements a whole family of compile-time reductions, like:</simpara>
29320 <itemizedlist>
29321 <listitem>
29322 <simpara>
29323 constant folding, copy propagation
29324 </simpara>
29325 </listitem>
29326 <listitem>
29327 <simpara>
29328 inline the <literal>Goto</literal> to a block with a unique predecessor
29329 </simpara>
29330 </listitem>
29331 </itemizedlist>
29332 </section>
29333 <section id="_implementation_57">
29334 <title>Implementation</title>
29335 <itemizedlist>
29336 <listitem>
29337 <simpara>
29338 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/rssa.fun"><literal>rssa.fun</literal></ulink>
29339 </simpara>
29340 </listitem>
29341 </itemizedlist>
29342 </section>
29343 <section id="_details_and_notes_55">
29344 <title>Details and Notes</title>
29345 <simpara></simpara>
29346 <simpara><?asciidoc-pagebreak?></simpara>
29347 </section>
29348 </section>
29349 <section id="RSSASimplify">
29350 <title>RSSASimplify</title>
29351 <simpara>The optimization passes for the <link linkend="RSSA">RSSA</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> are
29352 collected and controlled by the <literal>Backend</literal> functor
29353 (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/backend.sig"><literal>backend.sig</literal></ulink>,
29354 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/backend.fun"><literal>backend.fun</literal></ulink>).</simpara>
29355 <simpara>The following optimization pass is implemented:</simpara>
29356 <itemizedlist>
29357 <listitem>
29358 <simpara>
29359 <link linkend="RSSAShrink">RSSAShrink</link>
29360 </simpara>
29361 </listitem>
29362 </itemizedlist>
29363 <simpara>The following implementation passes are implemented:</simpara>
29364 <itemizedlist>
29365 <listitem>
29366 <simpara>
29367 <link linkend="ImplementHandlers">ImplementHandlers</link>
29368 </simpara>
29369 </listitem>
29370 <listitem>
29371 <simpara>
29372 <link linkend="ImplementProfiling">ImplementProfiling</link>
29373 </simpara>
29374 </listitem>
29375 <listitem>
29376 <simpara>
29377 <link linkend="InsertLimitChecks">InsertLimitChecks</link>
29378 </simpara>
29379 </listitem>
29380 <listitem>
29381 <simpara>
29382 <link linkend="InsertSignalChecks">InsertSignalChecks</link>
29383 </simpara>
29384 </listitem>
29385 </itemizedlist>
29386 <simpara>The optimization passes can be controlled from the command-line by the options</simpara>
29387 <itemizedlist>
29388 <listitem>
29389 <simpara>
29390 <literal>-diag-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;keep diagnostic info for pass
29391 </simpara>
29392 </listitem>
29393 <listitem>
29394 <simpara>
29395 <literal>-drop-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;omit optimization pass
29396 </simpara>
29397 </listitem>
29398 <listitem>
29399 <simpara>
29400 <literal>-keep-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;keep the results of pass
29401 </simpara>
29402 </listitem>
29403 </itemizedlist>
29404 <simpara><?asciidoc-pagebreak?></simpara>
29405 </section>
29406 <section id="RunningOnAIX">
29407 <title>RunningOnAIX</title>
29408 <simpara>MLton runs fine on AIX.</simpara>
29409 <section id="_also_see_37">
29410 <title>Also see</title>
29411 <itemizedlist>
29412 <listitem>
29413 <simpara>
29414 <link linkend="RunningOnPowerPC">RunningOnPowerPC</link>
29415 </simpara>
29416 </listitem>
29417 <listitem>
29418 <simpara>
29419 <link linkend="RunningOnPowerPC64">RunningOnPowerPC64</link>
29420 </simpara>
29421 </listitem>
29422 </itemizedlist>
29423 <simpara><?asciidoc-pagebreak?></simpara>
29424 </section>
29425 </section>
29426 <section id="RunningOnAlpha">
29427 <title>RunningOnAlpha</title>
29428 <simpara>MLton runs fine on the Alpha architecture.</simpara>
29429 <section id="_notes_4">
29430 <title>Notes</title>
29431 <itemizedlist>
29432 <listitem>
29433 <simpara>
29434 When compiling for Alpha, MLton doesn&#8217;t support native code
29435 generation (<literal>-codegen native</literal>). Hence, performance is not as good as
29436 it might be and compile times are longer. Also, the quality of code
29437 generated by <literal>gcc</literal> is important. By default, MLton calls <literal>gcc -O1</literal>.
29438 You can change this by calling MLton with <literal>-cc-opt -O2</literal>.
29439 </simpara>
29440 </listitem>
29441 <listitem>
29442 <simpara>
29443 When compiling for Alpha, MLton uses <literal>-align 8</literal> by default.
29444 </simpara>
29445 </listitem>
29446 </itemizedlist>
29447 <simpara><?asciidoc-pagebreak?></simpara>
29448 </section>
29449 </section>
29450 <section id="RunningOnAMD64">
29451 <title>RunningOnAMD64</title>
29452 <simpara>MLton runs fine on the AMD64 (aka "x86-64" or "x64") architecture.</simpara>
29453 <section id="_notes_5">
29454 <title>Notes</title>
29455 <itemizedlist>
29456 <listitem>
29457 <simpara>
29458 When compiling for AMD64, MLton targets the 64-bit ABI.
29459 </simpara>
29460 </listitem>
29461 <listitem>
29462 <simpara>
29463 On AMD64, MLton supports native code generation (<literal>-codegen native</literal> or <literal>-codegen amd64</literal>).
29464 </simpara>
29465 </listitem>
29466 <listitem>
29467 <simpara>
29468 When compiling for AMD64, MLton uses <literal>-align 8</literal> by default. Using
29469 <literal>-align 4</literal> may be incompatible with optimized builds of the <link linkend="GnuMP">GnuMP</link>
29470 library, which assume 8-byte alignment. (See the thread at
29471 <ulink url="http://www.mlton.org/pipermail/mlton/2009-October/030674.html">http://www.mlton.org/pipermail/mlton/2009-October/030674.html</ulink> for more
29472 details.)
29473 </simpara>
29474 </listitem>
29475 </itemizedlist>
29476 <simpara><?asciidoc-pagebreak?></simpara>
29477 </section>
29478 </section>
29479 <section id="RunningOnARM">
29480 <title>RunningOnARM</title>
29481 <simpara>MLton runs fine on the ARM architecture.</simpara>
29482 <section id="_notes_6">
29483 <title>Notes</title>
29484 <itemizedlist>
29485 <listitem>
29486 <simpara>
29487 When compiling for ARM, MLton doesn&#8217;t support native code generation
29488 (<literal>-codegen native</literal>). Hence, performance is not as good as it might be
29489 and compile times are longer. Also, the quality of code generated by
29490 <literal>gcc</literal> is important. By default, MLton calls <literal>gcc -O1</literal>. You can
29491 change this by calling MLton with <literal>-cc-opt -O2</literal>.
29492 </simpara>
29493 </listitem>
29494 </itemizedlist>
29495 <simpara><?asciidoc-pagebreak?></simpara>
29496 </section>
29497 </section>
29498 <section id="RunningOnCygwin">
29499 <title>RunningOnCygwin</title>
29500 <simpara>MLton runs on the <ulink url="http://www.cygwin.com/">Cygwin</ulink> emulation layer,
29501 which provides a Posix-like environment while running on Windows. To
29502 run MLton with Cygwin, you must first install Cygwin on your Windows
29503 machine. To do this, visit the Cygwin site from your Windows machine
29504 and run their <literal>setup.exe</literal> script. Then, you can unpack the MLton
29505 binary <literal>tgz</literal> in your Cygwin environment.</simpara>
29506 <simpara>To run MLton cross-compiled executables on Windows, you must install
29507 the Cygwin <literal>dll</literal> on the Windows machine.</simpara>
29508 <section id="_known_issues_2">
29509 <title>Known issues</title>
29510 <itemizedlist>
29511 <listitem>
29512 <simpara>
29513 Time profiling is disabled.
29514 </simpara>
29515 </listitem>
29516 <listitem>
29517 <simpara>
29518 Cygwin&#8217;s <literal>mmap</literal> emulation is less than perfect. Sometimes it
29519 interacts badly with <literal>Posix.Process.fork</literal>.
29520 </simpara>
29521 </listitem>
29522 <listitem>
29523 <simpara>
29524 The <ulink url="https://raw.github.com/MLton/mlton/master/regression/socket.sml"><literal>socket.sml</literal></ulink> regression
29525 test fails. We suspect this is not a bug and is simply due to our
29526 test relying on a certain behavior when connecting to a socket that
29527 has not yet accepted, which is handled differently on Cygwin than
29528 other platforms. Any help in understanding and resolving this issue
29529 is appreciated.
29530 </simpara>
29531 </listitem>
29532 </itemizedlist>
29533 </section>
29534 <section id="_also_see_38">
29535 <title>Also see</title>
29536 <itemizedlist>
29537 <listitem>
29538 <simpara>
29539 <link linkend="RunningOnMinGW">RunningOnMinGW</link>
29540 </simpara>
29541 </listitem>
29542 </itemizedlist>
29543 <simpara><?asciidoc-pagebreak?></simpara>
29544 </section>
29545 </section>
29546 <section id="RunningOnDarwin">
29547 <title>RunningOnDarwin</title>
29548 <simpara>MLton runs fine on Darwin (and on Mac OS X).</simpara>
29549 <section id="_notes_7">
29550 <title>Notes</title>
29551 <itemizedlist>
29552 <listitem>
29553 <simpara>
29554 MLton requires the <link linkend="GnuMP">GnuMP</link> library, which is available via
29555 <ulink url="http://www.finkproject.org">Fink</ulink>, <ulink url="http://www.macports.com">MacPorts</ulink>,
29556 <ulink url="http://mxcl.github.io/homebrew/">Homebrew</ulink>.
29557 </simpara>
29558 </listitem>
29559 <listitem>
29560 <simpara>
29561 For Intel-based Macs, MLton targets the <link linkend="RunningOnAMD64">AMD64 architecture</link> on Darwin 10 (Mac OS X Snow Leopard) and higher and
29562 targets the <link linkend="RunningOnX86">x86 architecture</link> on Darwin 8 (Mac OS X
29563 Tiger) and Darwin 9 (Mac OS X Leopard).
29564 </simpara>
29565 </listitem>
29566 </itemizedlist>
29567 </section>
29568 <section id="_known_issues_3">
29569 <title>Known issues</title>
29570 <itemizedlist>
29571 <listitem>
29572 <simpara>
29573 Executables that save and load worlds on Darwin 11 (Mac OS X Lion)
29574 and higher should be compiled with <literal>-link-opt -fno-PIE</literal> ; see
29575 <link linkend="MLtonWorld">MLtonWorld</link> for more details.
29576 </simpara>
29577 </listitem>
29578 <listitem>
29579 <simpara>
29580 <link linkend="ProfilingTime">ProfilingTime</link> may give inaccurate results on multi-processor
29581 machines. The <literal>SIGPROF</literal> signal, used to sample the profiled program,
29582 is supposed to be delivered 100 times a second (i.e., at 10000us
29583 intervals), but there can be delays of over 1 minute between the
29584 delivery of consecutive <literal>SIGPROF</literal> signals. A more complete
29585 description may be found
29586 <ulink url="http://lists.apple.com/archives/Unix-porting/2007/Aug/msg00000.html">here</ulink>
29587 and
29588 <ulink url="http://lists.apple.com/archives/Darwin-dev/2007/Aug/msg00045.html">here</ulink>.
29589 </simpara>
29590 </listitem>
29591 </itemizedlist>
29592 </section>
29593 <section id="_also_see_39">
29594 <title>Also see</title>
29595 <itemizedlist>
29596 <listitem>
29597 <simpara>
29598 <link linkend="RunningOnAMD64">RunningOnAMD64</link>
29599 </simpara>
29600 </listitem>
29601 <listitem>
29602 <simpara>
29603 <link linkend="RunningOnPowerPC">RunningOnPowerPC</link>
29604 </simpara>
29605 </listitem>
29606 <listitem>
29607 <simpara>
29608 <link linkend="RunningOnX86">RunningOnX86</link>
29609 </simpara>
29610 </listitem>
29611 </itemizedlist>
29612 <simpara><?asciidoc-pagebreak?></simpara>
29613 </section>
29614 </section>
29615 <section id="RunningOnFreeBSD">
29616 <title>RunningOnFreeBSD</title>
29617 <simpara>MLton runs fine on <ulink url="http://www.freebsd.org/">FreeBSD</ulink>.</simpara>
29618 <section id="_notes_8">
29619 <title>Notes</title>
29620 <itemizedlist>
29621 <listitem>
29622 <simpara>
29623 MLton is available as a <ulink url="http://www.freebsd.org/">FreeBSD</ulink>
29624 <ulink url="http://www.freebsd.org/cgi/ports.cgi?query=mlton&amp;stype=all">port</ulink>.
29625 </simpara>
29626 </listitem>
29627 </itemizedlist>
29628 </section>
29629 <section id="_known_issues_4">
29630 <title>Known issues</title>
29631 <itemizedlist>
29632 <listitem>
29633 <simpara>
29634 Executables often run more slowly than on a comparable Linux
29635 machine. We conjecture that part of this is due to costs due to heap
29636 resizing and kernel zeroing of pages. Any help in solving the problem
29637 would be appreciated.
29638 </simpara>
29639 </listitem>
29640 <listitem>
29641 <simpara>
29642 FreeBSD defaults to a datasize limit of 512M, even if you have more
29643 than that amount of memory in the computer. Hence, your MLton process
29644 will be limited in the amount of memory it has. To fix this problem,
29645 turn up the datasize and the default datasize available to a process:
29646 Edit <literal>/boot/loader.conf</literal> to set the limits. For example, the setting
29647 </simpara>
29648 <screen> kern.maxdsiz="671088640"
29649 kern.dfldsiz="671088640"
29650 kern.maxssiz="134217728"</screen>
29651 <simpara>will give a process 640M of datasize memory, default to 640M available
29652 and set 128M of stack size memory.</simpara>
29653 </listitem>
29654 </itemizedlist>
29655 <simpara><?asciidoc-pagebreak?></simpara>
29656 </section>
29657 </section>
29658 <section id="RunningOnHPPA">
29659 <title>RunningOnHPPA</title>
29660 <simpara>MLton runs fine on the HPPA architecture.</simpara>
29661 <section id="_notes_9">
29662 <title>Notes</title>
29663 <itemizedlist>
29664 <listitem>
29665 <simpara>
29666 When compiling for HPPA, MLton targets the 32-bit HPPA architecture.
29667 </simpara>
29668 </listitem>
29669 <listitem>
29670 <simpara>
29671 When compiling for HPPA, MLton doesn&#8217;t support native code
29672 generation (<literal>-codegen native</literal>). Hence, performance is not as good as
29673 it might be and compile times are longer. Also, the quality of code
29674 generated by <literal>gcc</literal> is important. By default, MLton calls <literal>gcc -O1</literal>.
29675 You can change this by calling MLton with <literal>-cc-opt -O2</literal>.
29676 </simpara>
29677 </listitem>
29678 <listitem>
29679 <simpara>
29680 When compiling for HPPA, MLton uses <literal>-align 8</literal> by default. While
29681 this speeds up reals, it also may increase object sizes. If your
29682 program does not make significant use of reals, you might see a
29683 speedup with <literal>-align 4</literal>.
29684 </simpara>
29685 </listitem>
29686 </itemizedlist>
29687 <simpara><?asciidoc-pagebreak?></simpara>
29688 </section>
29689 </section>
29690 <section id="RunningOnHPUX">
29691 <title>RunningOnHPUX</title>
29692 <simpara>MLton runs fine on HPUX.</simpara>
29693 <section id="_also_see_40">
29694 <title>Also see</title>
29695 <itemizedlist>
29696 <listitem>
29697 <simpara>
29698 <link linkend="RunningOnHPPA">RunningOnHPPA</link>
29699 </simpara>
29700 </listitem>
29701 </itemizedlist>
29702 <simpara><?asciidoc-pagebreak?></simpara>
29703 </section>
29704 </section>
29705 <section id="RunningOnIA64">
29706 <title>RunningOnIA64</title>
29707 <simpara>MLton runs fine on the IA64 architecture.</simpara>
29708 <section id="_notes_10">
29709 <title>Notes</title>
29710 <itemizedlist>
29711 <listitem>
29712 <simpara>
29713 When compiling for IA64, MLton targets the 64-bit ABI.
29714 </simpara>
29715 </listitem>
29716 <listitem>
29717 <simpara>
29718 When compiling for IA64, MLton doesn&#8217;t support native code
29719 generation (<literal>-codegen native</literal>). Hence, performance is not as good as
29720 it might be and compile times are longer. Also, the quality of code
29721 generated by <literal>gcc</literal> is important. By default, MLton calls <literal>gcc -O1</literal>.
29722 You can change this by calling MLton with <literal>-cc-opt -O2</literal>.
29723 </simpara>
29724 </listitem>
29725 <listitem>
29726 <simpara>
29727 When compiling for IA64, MLton uses <literal>-align 8</literal> by default.
29728 </simpara>
29729 </listitem>
29730 <listitem>
29731 <simpara>
29732 On the IA64, the <link linkend="GnuMP">GnuMP</link> library supports multiple ABIs. See the
29733 <link linkend="GnuMP">GnuMP</link> page for more details.
29734 </simpara>
29735 </listitem>
29736 </itemizedlist>
29737 <simpara><?asciidoc-pagebreak?></simpara>
29738 </section>
29739 </section>
29740 <section id="RunningOnLinux">
29741 <title>RunningOnLinux</title>
29742 <simpara>MLton runs fine on Linux.</simpara>
29743 <simpara><?asciidoc-pagebreak?></simpara>
29744 </section>
29745 <section id="RunningOnMinGW">
29746 <title>RunningOnMinGW</title>
29747 <simpara>MLton runs on <ulink url="http://mingw.org">MinGW</ulink>, a library for porting Unix
29748 applications to Windows. Some library functionality is missing or
29749 changed.</simpara>
29750 <section id="_notes_11">
29751 <title>Notes</title>
29752 <itemizedlist>
29753 <listitem>
29754 <simpara>
29755 To compile MLton on MinGW:
29756 </simpara>
29757 <itemizedlist>
29758 <listitem>
29759 <simpara>
29760 The <link linkend="GnuMP">GnuMP</link> library is required.
29761 </simpara>
29762 </listitem>
29763 <listitem>
29764 <simpara>
29765 The Bash shell is required. If you are using a prebuilt MSYS, you
29766 probably want to symlink <literal>bash</literal> to <literal>sh</literal>.
29767 </simpara>
29768 </listitem>
29769 </itemizedlist>
29770 </listitem>
29771 </itemizedlist>
29772 </section>
29773 <section id="_known_issues_5">
29774 <title>Known issues</title>
29775 <itemizedlist>
29776 <listitem>
29777 <simpara>
29778 Many functions are unimplemented and will <literal>raise SysErr</literal>.
29779 </simpara>
29780 <itemizedlist>
29781 <listitem>
29782 <simpara>
29783 <literal>MLton.Itimer.set</literal>
29784 </simpara>
29785 </listitem>
29786 <listitem>
29787 <simpara>
29788 <literal>MLton.ProcEnv.setgroups</literal>
29789 </simpara>
29790 </listitem>
29791 <listitem>
29792 <simpara>
29793 <literal>MLton.Process.kill</literal>
29794 </simpara>
29795 </listitem>
29796 <listitem>
29797 <simpara>
29798 <literal>MLton.Process.reap</literal>
29799 </simpara>
29800 </listitem>
29801 <listitem>
29802 <simpara>
29803 <literal>MLton.World.load</literal>
29804 </simpara>
29805 </listitem>
29806 <listitem>
29807 <simpara>
29808 <literal>OS.FileSys.readLink</literal>
29809 </simpara>
29810 </listitem>
29811 <listitem>
29812 <simpara>
29813 <literal>OS.IO.poll</literal>
29814 </simpara>
29815 </listitem>
29816 <listitem>
29817 <simpara>
29818 <literal>OS.Process.terminate</literal>
29819 </simpara>
29820 </listitem>
29821 <listitem>
29822 <simpara>
29823 <literal>Posix.FileSys.chown</literal>
29824 </simpara>
29825 </listitem>
29826 <listitem>
29827 <simpara>
29828 <literal>Posix.FileSys.fchown</literal>
29829 </simpara>
29830 </listitem>
29831 <listitem>
29832 <simpara>
29833 <literal>Posix.FileSys.fpathconf</literal>
29834 </simpara>
29835 </listitem>
29836 <listitem>
29837 <simpara>
29838 <literal>Posix.FileSys.link</literal>
29839 </simpara>
29840 </listitem>
29841 <listitem>
29842 <simpara>
29843 <literal>Posix.FileSys.mkfifo</literal>
29844 </simpara>
29845 </listitem>
29846 <listitem>
29847 <simpara>
29848 <literal>Posix.FileSys.pathconf</literal>
29849 </simpara>
29850 </listitem>
29851 <listitem>
29852 <simpara>
29853 <literal>Posix.FileSys.readlink</literal>
29854 </simpara>
29855 </listitem>
29856 <listitem>
29857 <simpara>
29858 <literal>Posix.FileSys.symlink</literal>
29859 </simpara>
29860 </listitem>
29861 <listitem>
29862 <simpara>
29863 <literal>Posix.IO.dupfd</literal>
29864 </simpara>
29865 </listitem>
29866 <listitem>
29867 <simpara>
29868 <literal>Posix.IO.getfd</literal>
29869 </simpara>
29870 </listitem>
29871 <listitem>
29872 <simpara>
29873 <literal>Posix.IO.getfl</literal>
29874 </simpara>
29875 </listitem>
29876 <listitem>
29877 <simpara>
29878 <literal>Posix.IO.getlk</literal>
29879 </simpara>
29880 </listitem>
29881 <listitem>
29882 <simpara>
29883 <literal>Posix.IO.setfd</literal>
29884 </simpara>
29885 </listitem>
29886 <listitem>
29887 <simpara>
29888 <literal>Posix.IO.setfl</literal>
29889 </simpara>
29890 </listitem>
29891 <listitem>
29892 <simpara>
29893 <literal>Posix.IO.setlkw</literal>
29894 </simpara>
29895 </listitem>
29896 <listitem>
29897 <simpara>
29898 <literal>Posix.IO.setlk</literal>
29899 </simpara>
29900 </listitem>
29901 <listitem>
29902 <simpara>
29903 <literal>Posix.ProcEnv.ctermid</literal>
29904 </simpara>
29905 </listitem>
29906 <listitem>
29907 <simpara>
29908 <literal>Posix.ProcEnv.getegid</literal>
29909 </simpara>
29910 </listitem>
29911 <listitem>
29912 <simpara>
29913 <literal>Posix.ProcEnv.geteuid</literal>
29914 </simpara>
29915 </listitem>
29916 <listitem>
29917 <simpara>
29918 <literal>Posix.ProcEnv.getgid</literal>
29919 </simpara>
29920 </listitem>
29921 <listitem>
29922 <simpara>
29923 <literal>Posix.ProcEnv.getgroups</literal>
29924 </simpara>
29925 </listitem>
29926 <listitem>
29927 <simpara>
29928 <literal>Posix.ProcEnv.getlogin</literal>
29929 </simpara>
29930 </listitem>
29931 <listitem>
29932 <simpara>
29933 <literal>Posix.ProcEnv.getpgrp</literal>
29934 </simpara>
29935 </listitem>
29936 <listitem>
29937 <simpara>
29938 <literal>Posix.ProcEnv.getpid</literal>
29939 </simpara>
29940 </listitem>
29941 <listitem>
29942 <simpara>
29943 <literal>Posix.ProcEnv.getppid</literal>
29944 </simpara>
29945 </listitem>
29946 <listitem>
29947 <simpara>
29948 <literal>Posix.ProcEnv.getuid</literal>
29949 </simpara>
29950 </listitem>
29951 <listitem>
29952 <simpara>
29953 <literal>Posix.ProcEnv.setgid</literal>
29954 </simpara>
29955 </listitem>
29956 <listitem>
29957 <simpara>
29958 <literal>Posix.ProcEnv.setpgid</literal>
29959 </simpara>
29960 </listitem>
29961 <listitem>
29962 <simpara>
29963 <literal>Posix.ProcEnv.setsid</literal>
29964 </simpara>
29965 </listitem>
29966 <listitem>
29967 <simpara>
29968 <literal>Posix.ProcEnv.setuid</literal>
29969 </simpara>
29970 </listitem>
29971 <listitem>
29972 <simpara>
29973 <literal>Posix.ProcEnv.sysconf</literal>
29974 </simpara>
29975 </listitem>
29976 <listitem>
29977 <simpara>
29978 <literal>Posix.ProcEnv.times</literal>
29979 </simpara>
29980 </listitem>
29981 <listitem>
29982 <simpara>
29983 <literal>Posix.ProcEnv.ttyname</literal>
29984 </simpara>
29985 </listitem>
29986 <listitem>
29987 <simpara>
29988 <literal>Posix.Process.exece</literal>
29989 </simpara>
29990 </listitem>
29991 <listitem>
29992 <simpara>
29993 <literal>Posix.Process.execp</literal>
29994 </simpara>
29995 </listitem>
29996 <listitem>
29997 <simpara>
29998 <literal>Posix.Process.exit</literal>
29999 </simpara>
30000 </listitem>
30001 <listitem>
30002 <simpara>
30003 <literal>Posix.Process.fork</literal>
30004 </simpara>
30005 </listitem>
30006 <listitem>
30007 <simpara>
30008 <literal>Posix.Process.kill</literal>
30009 </simpara>
30010 </listitem>
30011 <listitem>
30012 <simpara>
30013 <literal>Posix.Process.pause</literal>
30014 </simpara>
30015 </listitem>
30016 <listitem>
30017 <simpara>
30018 <literal>Posix.Process.waitpid_nh</literal>
30019 </simpara>
30020 </listitem>
30021 <listitem>
30022 <simpara>
30023 <literal>Posix.Process.waitpid</literal>
30024 </simpara>
30025 </listitem>
30026 <listitem>
30027 <simpara>
30028 <literal>Posix.SysDB.getgrgid</literal>
30029 </simpara>
30030 </listitem>
30031 <listitem>
30032 <simpara>
30033 <literal>Posix.SysDB.getgrnam</literal>
30034 </simpara>
30035 </listitem>
30036 <listitem>
30037 <simpara>
30038 <literal>Posix.SysDB.getpwuid</literal>
30039 </simpara>
30040 </listitem>
30041 <listitem>
30042 <simpara>
30043 <literal>Posix.TTY.TC.drain</literal>
30044 </simpara>
30045 </listitem>
30046 <listitem>
30047 <simpara>
30048 <literal>Posix.TTY.TC.flow</literal>
30049 </simpara>
30050 </listitem>
30051 <listitem>
30052 <simpara>
30053 <literal>Posix.TTY.TC.flush</literal>
30054 </simpara>
30055 </listitem>
30056 <listitem>
30057 <simpara>
30058 <literal>Posix.TTY.TC.getattr</literal>
30059 </simpara>
30060 </listitem>
30061 <listitem>
30062 <simpara>
30063 <literal>Posix.TTY.TC.getpgrp</literal>
30064 </simpara>
30065 </listitem>
30066 <listitem>
30067 <simpara>
30068 <literal>Posix.TTY.TC.sendbreak</literal>
30069 </simpara>
30070 </listitem>
30071 <listitem>
30072 <simpara>
30073 <literal>Posix.TTY.TC.setattr</literal>
30074 </simpara>
30075 </listitem>
30076 <listitem>
30077 <simpara>
30078 <literal>Posix.TTY.TC.setpgrp</literal>
30079 </simpara>
30080 </listitem>
30081 <listitem>
30082 <simpara>
30083 <literal>Unix.kill</literal>
30084 </simpara>
30085 </listitem>
30086 <listitem>
30087 <simpara>
30088 <literal>Unix.reap</literal>
30089 </simpara>
30090 </listitem>
30091 <listitem>
30092 <simpara>
30093 <literal>UnixSock.fromAddr</literal>
30094 </simpara>
30095 </listitem>
30096 <listitem>
30097 <simpara>
30098 <literal>UnixSock.toAddr</literal>
30099 </simpara>
30100 </listitem>
30101 </itemizedlist>
30102 </listitem>
30103 </itemizedlist>
30104 <simpara><?asciidoc-pagebreak?></simpara>
30105 </section>
30106 </section>
30107 <section id="RunningOnNetBSD">
30108 <title>RunningOnNetBSD</title>
30109 <simpara>MLton runs fine on <ulink url="http://www.netbsd.org/">NetBSD</ulink>.</simpara>
30110 <section id="_installing_the_correct_packages_for_netbsd">
30111 <title>Installing the correct packages for NetBSD</title>
30112 <simpara>The NetBSD system installs 3rd party packages by a mechanism known as
30113 pkgsrc. This is a tree of Makefiles which when invoked downloads the
30114 source code, builds a package and installs it on the system. In order
30115 to run MLton on NetBSD, you will have to install several packages for
30116 it to work:</simpara>
30117 <itemizedlist>
30118 <listitem>
30119 <simpara>
30120 <literal>shells/bash</literal>
30121 </simpara>
30122 </listitem>
30123 <listitem>
30124 <simpara>
30125 <literal>devel/gmp</literal>
30126 </simpara>
30127 </listitem>
30128 <listitem>
30129 <simpara>
30130 <literal>devel/gmake</literal>
30131 </simpara>
30132 </listitem>
30133 </itemizedlist>
30134 <simpara>In order to get graphical call-graphs of profiling information, you
30135 will need the additional package</simpara>
30136 <itemizedlist>
30137 <listitem>
30138 <simpara>
30139 <literal>graphics/graphviz</literal>
30140 </simpara>
30141 </listitem>
30142 </itemizedlist>
30143 <simpara>To build the documentation for MLton, you will need the addtional
30144 package</simpara>
30145 <itemizedlist>
30146 <listitem>
30147 <simpara>
30148 <literal>textproc/asciidoc</literal>.
30149 </simpara>
30150 </listitem>
30151 </itemizedlist>
30152 </section>
30153 <section id="_tips_for_compiling_and_using_mlton_on_netbsd">
30154 <title>Tips for compiling and using MLton on NetBSD</title>
30155 <simpara>MLton can be a memory-hog on computers with little memory. While
30156 640Mb of RAM ought to be enough to self-compile MLton one might want
30157 to do some tuning to the NetBSD VM subsystem in order to succeed. The
30158 notes presented here is what <link linkend="JesperLouisAndersen">JesperLouisAndersen</link> uses for
30159 compiling MLton on his laptop.</simpara>
30160 <section id="_the_netbsd_vm_subsystem">
30161 <title>The NetBSD VM subsystem</title>
30162 <simpara>NetBSD uses a VM subsystem named
30163 <ulink url="http://www.ccrc.wustl.edu/pub/chuck/tech/uvm/">UVM</ulink>.
30164 <ulink url="http://www.selonen.org/arto/netbsd/vm_tune.html">Tuning the VM system</ulink>
30165 can be done via the <literal>sysctl(8)</literal>-interface with the "VM" MIB set.</simpara>
30166 </section>
30167 <section id="_tuning_the_netbsd_vm_subsystem_for_mlton">
30168 <title>Tuning the NetBSD VM subsystem for MLton</title>
30169 <simpara>MLton uses a lot of anonymous pages when it is running. Thus, we will
30170 need to tune up the default of 80 for anonymous pages. Setting</simpara>
30171 <screen>sysctl -w vm.anonmax=95
30172 sysctl -w vm.anonmin=50
30173 sysctl -w vm.filemin=2
30174 sysctl -w vm.execmin=2
30175 sysctl -w vm.filemax=4
30176 sysctl -w vm.execmax=4</screen>
30177 <simpara>makes it less likely for the VM system to swap out anonymous pages.
30178 For a full explanation of the above flags, see the documentation.</simpara>
30179 <simpara>The result is that my laptop goes from a MLton compile where it swaps
30180 a lot to a MLton compile with no swapping.</simpara>
30181 <simpara><?asciidoc-pagebreak?></simpara>
30182 </section>
30183 </section>
30184 </section>
30185 <section id="RunningOnOpenBSD">
30186 <title>RunningOnOpenBSD</title>
30187 <simpara>MLton runs fine on <ulink url="http://www.openbsd.org/">OpenBSD</ulink>.</simpara>
30188 <section id="_known_issues_6">
30189 <title>Known issues</title>
30190 <itemizedlist>
30191 <listitem>
30192 <simpara>
30193 The <ulink url="https://raw.github.com/MLton/mlton/master/regression/socket.sml"><literal>socket.sml</literal></ulink> regression
30194 test fails. We suspect this is not a bug and is simply due to our
30195 test relying on a certain behavior when connecting to a socket that
30196 has not yet accepted, which is handled differently on OpenBSD than
30197 other platforms. Any help in understanding and resolving this issue
30198 is appreciated.
30199 </simpara>
30200 </listitem>
30201 </itemizedlist>
30202 <simpara><?asciidoc-pagebreak?></simpara>
30203 </section>
30204 </section>
30205 <section id="RunningOnPowerPC">
30206 <title>RunningOnPowerPC</title>
30207 <simpara>MLton runs fine on the PowerPC architecture.</simpara>
30208 <section id="_notes_12">
30209 <title>Notes</title>
30210 <itemizedlist>
30211 <listitem>
30212 <simpara>
30213 When compiling for PowerPC, MLton targets the 32-bit PowerPC
30214 architecture.
30215 </simpara>
30216 </listitem>
30217 <listitem>
30218 <simpara>
30219 When compiling for PowerPC, MLton doesn&#8217;t support native code
30220 generation (<literal>-codegen native</literal>). Hence, performance is not as good as
30221 it might be and compile times are longer. Also, the quality of code
30222 generated by <literal>gcc</literal> is important. By default, MLton calls <literal>gcc -O1</literal>.
30223 You can change this by calling MLton with <literal>-cc-opt -O2</literal>.
30224 </simpara>
30225 </listitem>
30226 <listitem>
30227 <simpara>
30228 On the PowerPC, the <link linkend="GnuMP">GnuMP</link> library supports multiple ABIs. See
30229 the <link linkend="GnuMP">GnuMP</link> page for more details.
30230 </simpara>
30231 </listitem>
30232 </itemizedlist>
30233 <simpara><?asciidoc-pagebreak?></simpara>
30234 </section>
30235 </section>
30236 <section id="RunningOnPowerPC64">
30237 <title>RunningOnPowerPC64</title>
30238 <simpara>MLton runs fine on the PowerPC64 architecture.</simpara>
30239 <section id="_notes_13">
30240 <title>Notes</title>
30241 <itemizedlist>
30242 <listitem>
30243 <simpara>
30244 When compiling for PowerPC64, MLton targets the 64-bit PowerPC
30245 architecture.
30246 </simpara>
30247 </listitem>
30248 <listitem>
30249 <simpara>
30250 When compiling for PowerPC64, MLton doesn&#8217;t support native code
30251 generation (<literal>-codegen native</literal>). Hence, performance is not as good as
30252 it might be and compile times are longer. Also, the quality of code
30253 generated by <literal>gcc</literal> is important. By default, MLton calls <literal>gcc -O1</literal>.
30254 You can change this by calling MLton with <literal>-cc-opt -O2</literal>.
30255 </simpara>
30256 </listitem>
30257 <listitem>
30258 <simpara>
30259 On the PowerPC64, the <link linkend="GnuMP">GnuMP</link> library supports multiple ABIs. See
30260 the <link linkend="GnuMP">GnuMP</link> page for more details.
30261 </simpara>
30262 </listitem>
30263 </itemizedlist>
30264 <simpara><?asciidoc-pagebreak?></simpara>
30265 </section>
30266 </section>
30267 <section id="RunningOnS390">
30268 <title>RunningOnS390</title>
30269 <simpara>MLton runs fine on the S390 architecture.</simpara>
30270 <section id="_notes_14">
30271 <title>Notes</title>
30272 <itemizedlist>
30273 <listitem>
30274 <simpara>
30275 When compiling for S390, MLton doesn&#8217;t support native code
30276 generation (<literal>-codegen native</literal>). Hence, performance is not as good as
30277 it might be and compile times are longer. Also, the quality of code
30278 generated by <literal>gcc</literal> is important. By default, MLton calls <literal>gcc -O1</literal>.
30279 You can change this by calling MLton with <literal>-cc-opt -O2</literal>.
30280 </simpara>
30281 </listitem>
30282 </itemizedlist>
30283 <simpara><?asciidoc-pagebreak?></simpara>
30284 </section>
30285 </section>
30286 <section id="RunningOnSolaris">
30287 <title>RunningOnSolaris</title>
30288 <simpara>MLton runs fine on Solaris.</simpara>
30289 <section id="_notes_15">
30290 <title>Notes</title>
30291 <itemizedlist>
30292 <listitem>
30293 <simpara>
30294 You must install the <literal>binutils</literal>, <literal>gcc</literal>, and <literal>make</literal> packages. You
30295 can find out how to get these at
30296 <ulink url="http://www.sunfreeware.com">sunfreeware.com</ulink>.
30297 </simpara>
30298 </listitem>
30299 <listitem>
30300 <simpara>
30301 Making the documentation requires that you install <literal>latex</literal> and
30302 <literal>dvips</literal>, which are available in the <literal>tetex</literal> package.
30303 </simpara>
30304 </listitem>
30305 </itemizedlist>
30306 </section>
30307 <section id="_known_issues_7">
30308 <title>Known issues</title>
30309 <itemizedlist>
30310 <listitem>
30311 <simpara>
30312 Bootstrapping on the <link linkend="RunningOnSparc">Sparc architecture</link> is so slow
30313 as to be impractical (many hours on a 500MHz UltraSparc). For this
30314 reason, we strongly recommend building with a
30315 <link linkend="CrossCompiling">cross compiler</link>.
30316 </simpara>
30317 </listitem>
30318 </itemizedlist>
30319 </section>
30320 <section id="_also_see_41">
30321 <title>Also see</title>
30322 <itemizedlist>
30323 <listitem>
30324 <simpara>
30325 <link linkend="RunningOnAMD64">RunningOnAMD64</link>
30326 </simpara>
30327 </listitem>
30328 <listitem>
30329 <simpara>
30330 <link linkend="RunningOnSparc">RunningOnSparc</link>
30331 </simpara>
30332 </listitem>
30333 <listitem>
30334 <simpara>
30335 <link linkend="RunningOnX86">RunningOnX86</link>
30336 </simpara>
30337 </listitem>
30338 </itemizedlist>
30339 <simpara><?asciidoc-pagebreak?></simpara>
30340 </section>
30341 </section>
30342 <section id="RunningOnSparc">
30343 <title>RunningOnSparc</title>
30344 <simpara>MLton runs fine on the Sparc architecture.</simpara>
30345 <section id="_notes_16">
30346 <title>Notes</title>
30347 <itemizedlist>
30348 <listitem>
30349 <simpara>
30350 When compiling for Sparc, MLton targets the 32-bit Sparc
30351 architecture (i.e., Sparc V8).
30352 </simpara>
30353 </listitem>
30354 <listitem>
30355 <simpara>
30356 When compiling for Sparc, MLton doesn&#8217;t support native code
30357 generation (<literal>-codegen native</literal>). Hence, performance is not as good as
30358 it might be and compile times are longer. Also, the quality of code
30359 generated by <literal>gcc</literal> is important. By default, MLton calls <literal>gcc -O1</literal>.
30360 You can change this by calling MLton with <literal>-cc-opt -O2</literal>. We have seen
30361 this speed up some programs by as much as 30%, especially those
30362 involving floating point; however, it can also more than double
30363 compile times.
30364 </simpara>
30365 </listitem>
30366 <listitem>
30367 <simpara>
30368 When compiling for Sparc, MLton uses <literal>-align 8</literal> by default. While
30369 this speeds up reals, it also may increase object sizes. If your
30370 program does not make significant use of reals, you might see a
30371 speedup with <literal>-align 4</literal>.
30372 </simpara>
30373 </listitem>
30374 </itemizedlist>
30375 </section>
30376 <section id="_known_issues_8">
30377 <title>Known issues</title>
30378 <itemizedlist>
30379 <listitem>
30380 <simpara>
30381 Bootstrapping on the <link linkend="RunningOnSparc">Sparc architecture</link> is so slow
30382 as to be impractical (many hours on a 500MHz UltraSparc). For this
30383 reason, we strongly recommend building with a
30384 <link linkend="CrossCompiling">cross compiler</link>.
30385 </simpara>
30386 </listitem>
30387 </itemizedlist>
30388 </section>
30389 <section id="_also_see_42">
30390 <title>Also see</title>
30391 <itemizedlist>
30392 <listitem>
30393 <simpara>
30394 <link linkend="RunningOnSolaris">RunningOnSolaris</link>
30395 </simpara>
30396 </listitem>
30397 </itemizedlist>
30398 <simpara><?asciidoc-pagebreak?></simpara>
30399 </section>
30400 </section>
30401 <section id="RunningOnX86">
30402 <title>RunningOnX86</title>
30403 <simpara>MLton runs fine on the x86 architecture.</simpara>
30404 <section id="_notes_17">
30405 <title>Notes</title>
30406 <itemizedlist>
30407 <listitem>
30408 <simpara>
30409 On x86, MLton supports native code generation (<literal>-codegen native</literal> or
30410 <literal>-codegen x86</literal>).
30411 </simpara>
30412 </listitem>
30413 </itemizedlist>
30414 <simpara><?asciidoc-pagebreak?></simpara>
30415 </section>
30416 </section>
30417 <section id="RunTimeOptions">
30418 <title>RunTimeOptions</title>
30419 <simpara>Executables produced by MLton take command line arguments that control
30420 the runtime system. These arguments are optional, and occur before
30421 the executable&#8217;s usual arguments. To use these options, the first
30422 argument to the executable must be <literal>@MLton</literal>. The optional arguments
30423 then follow, must be terminated by <literal>--</literal>, and are followed by any
30424 arguments to the program. The optional arguments are <emphasis>not</emphasis> made
30425 available to the SML program via <literal>CommandLine.arguments</literal>. For
30426 example, a valid call to <literal>hello-world</literal> is:</simpara>
30427 <screen>hello-world @MLton gc-summary fixed-heap 10k -- a b c</screen>
30428 <simpara>In the above example,
30429 <literal>CommandLine.arguments () = ["a", "b", "c"]</literal>.</simpara>
30430 <simpara>It is allowed to have a sequence of <literal>@MLton</literal> arguments, as in:</simpara>
30431 <screen>hello-world @MLton gc-summary -- @MLton fixed-heap 10k -- a b c</screen>
30432 <simpara>Run-time options can also control MLton, as in</simpara>
30433 <screen>mlton @MLton fixed-heap 0.5g -- foo.sml</screen>
30434 <section id="_options_2">
30435 <title>Options</title>
30436 <itemizedlist>
30437 <listitem>
30438 <simpara>
30439 <literal>fixed-heap <emphasis>x</emphasis>{k|K|m|M|g|G}</literal>
30440 </simpara>
30441 <simpara>Use a fixed size heap of size <emphasis>x</emphasis>, where <emphasis>x</emphasis> is a real number and the
30442 trailing letter indicates its units.</simpara>
30443 <informaltable
30444 frame="all"
30445 rowsep="1" colsep="1"
30446 >
30447 <tgroup cols="2">
30448 <colspec colname="col_1" colwidth="25*"/>
30449 <colspec colname="col_2" colwidth="75*"/>
30450 <tbody>
30451 <row>
30452 <entry align="center" valign="top"><simpara><literal>k</literal> or <literal>K</literal></simpara></entry>
30453 <entry align="left" valign="top"><simpara>1024</simpara></entry>
30454 </row>
30455 <row>
30456 <entry align="center" valign="top"><simpara><literal>m</literal> or <literal>M</literal></simpara></entry>
30457 <entry align="left" valign="top"><simpara>1,048,576</simpara></entry>
30458 </row>
30459 <row>
30460 <entry align="center" valign="top"><simpara><literal>g</literal> or <literal>G</literal></simpara></entry>
30461 <entry align="left" valign="top"><simpara>1,073,741,824</simpara></entry>
30462 </row>
30463 </tbody>
30464 </tgroup>
30465 </informaltable>
30466 <simpara>A value of <literal>0</literal> means to use almost all the RAM present on the machine.</simpara>
30467 <simpara>The heap size used by <literal>fixed-heap</literal> includes all memory allocated by
30468 SML code, including memory for the stack (or stacks, if there are
30469 multiple threads). It does not, however, include any memory used for
30470 code itself or memory used by C globals, the C stack, or malloc.</simpara>
30471 </listitem>
30472 <listitem>
30473 <simpara>
30474 <literal>gc-messages</literal>
30475 </simpara>
30476 <simpara>Print a message at the start and end of every garbage collection.</simpara>
30477 </listitem>
30478 <listitem>
30479 <simpara>
30480 <literal>gc-summary</literal>
30481 </simpara>
30482 <simpara>Print a summary of garbage collection statistics upon program
30483 termination to standard error.</simpara>
30484 </listitem>
30485 <listitem>
30486 <simpara>
30487 <literal>gc-summary-file <emphasis>file</emphasis></literal>
30488 </simpara>
30489 <simpara>Print a summary of garbage collection statistics upon program
30490 termination to the file specified by <emphasis>file</emphasis>.</simpara>
30491 </listitem>
30492 <listitem>
30493 <simpara>
30494 <literal>load-world <emphasis>world</emphasis></literal>
30495 </simpara>
30496 <simpara>Restart the computation with the file specified by <emphasis>world</emphasis>, which must
30497 have been created by a call to <literal>MLton.World.save</literal> by the same
30498 executable. See <link linkend="MLtonWorld">MLtonWorld</link>.</simpara>
30499 </listitem>
30500 <listitem>
30501 <simpara>
30502 <literal>max-heap <emphasis>x</emphasis>{k|K|m|M|g|G}</literal>
30503 </simpara>
30504 <simpara>Run the computation with an automatically resized heap that is never
30505 larger than <emphasis>x</emphasis>, where <emphasis>x</emphasis> is a real number and the trailing letter
30506 indicates the units as with <literal>fixed-heap</literal>. The heap size for
30507 <literal>max-heap</literal> is accounted for as with <literal>fixed-heap</literal>.</simpara>
30508 </listitem>
30509 <listitem>
30510 <simpara>
30511 <literal>may-page-heap {false|true}</literal>
30512 </simpara>
30513 <simpara>Enable paging the heap to disk when unable to grow the heap to a
30514 desired size.</simpara>
30515 </listitem>
30516 <listitem>
30517 <simpara>
30518 <literal>no-load-world</literal>
30519 </simpara>
30520 <simpara>Disable <literal>load-world</literal>. This can be used as an argument to the compiler
30521 via <literal>-runtime no-load-world</literal> to create executables that will not load
30522 a world. This may be useful to ensure that set-uid executables do not
30523 load some strange world.</simpara>
30524 </listitem>
30525 <listitem>
30526 <simpara>
30527 <literal>ram-slop <emphasis>x</emphasis></literal>
30528 </simpara>
30529 <simpara>Multiply <emphasis>x</emphasis> by the amount of RAM on the machine to obtain what the
30530 runtime views as the amount of RAM it can use. Typically <emphasis>x</emphasis> is less
30531 than 1, and is used to account for space used by other programs
30532 running on the same machine.</simpara>
30533 </listitem>
30534 <listitem>
30535 <simpara>
30536 <literal>stop</literal>
30537 </simpara>
30538 <simpara>Causes the runtime to stop processing <literal>@MLton</literal> arguments once the next
30539 <literal>--</literal> is reached. This can be used as an argument to the compiler via
30540 <literal>-runtime stop</literal> to create executables that don&#8217;t process any <literal>@MLton</literal>
30541 arguments.</simpara>
30542 </listitem>
30543 </itemizedlist>
30544 <simpara><?asciidoc-pagebreak?></simpara>
30545 </section>
30546 </section>
30547 <section id="ScopeInference">
30548 <title>ScopeInference</title>
30549 <simpara>Scope inference is an analysis/rewrite pass for the <link linkend="AST">AST</link>
30550 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="Elaborate">Elaborate</link>.</simpara>
30551 <section id="_description_53">
30552 <title>Description</title>
30553 <simpara>This pass adds free type variables to the <literal>val</literal> or <literal>fun</literal>
30554 declaration where they are implicitly scoped.</simpara>
30555 </section>
30556 <section id="_implementation_58">
30557 <title>Implementation</title>
30558 <simpara><ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/scope.sig"><literal>scope.sig</literal></ulink>
30559 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/elaborate/scope.fun"><literal>scope.fun</literal></ulink></simpara>
30560 </section>
30561 <section id="_details_and_notes_56">
30562 <title>Details and Notes</title>
30563 <simpara>Scope inference determines for each type variable, the declaration
30564 where it is bound. Scope inference is a direct implementation of the
30565 specification given in section 4.6 of the
30566 <link linkend="DefinitionOfStandardML">Definition</link>. Recall that a free occurrence
30567 of a type variable <literal>'a</literal> in a declaration <literal>d</literal> is <emphasis>unguarded</emphasis>
30568 in <literal>d</literal> if <literal>'a</literal> is not part of a smaller declaration. A type
30569 variable <literal>'a</literal> is implicitly scoped at <literal>d</literal> if <literal>'a</literal> is
30570 unguarded in <literal>d</literal> and <literal>'a</literal> does not occur unguarded in any
30571 declaration containing <literal>d</literal>.</simpara>
30572 <simpara>The first pass of scope inference walks down the tree and renames all
30573 explicitly bound type variables in order to avoid name collisions. It
30574 then walks up the tree and adds to each declaration the set of
30575 unguarded type variables occurring in that declaration. At this
30576 point, if declaration <literal>d</literal> contains an unguarded type variable
30577 <literal>'a</literal> and the immediately containing declaration does not contain
30578 <literal>'a</literal>, then <literal>'a</literal> is implicitly scoped at <literal>d</literal>. The final
30579 pass walks down the tree leaving a <literal>'a</literal> at the a declaration where
30580 it is scoped and removing it from all enclosed declarations.</simpara>
30581 <simpara><?asciidoc-pagebreak?></simpara>
30582 </section>
30583 </section>
30584 <section id="SelfCompiling">
30585 <title>SelfCompiling</title>
30586 <simpara>If you want to compile MLton, you must first get the <link linkend="Sources">Sources</link>. You
30587 can compile with either MLton or SML/NJ, but we strongly recommend
30588 using MLton, since it generates a much faster and more robust
30589 executable.</simpara>
30590 <section id="_compiling_with_mlton">
30591 <title>Compiling with MLton</title>
30592 <simpara>To compile with MLton, you need the binary versions of <literal>mlton</literal>,
30593 <literal>mllex</literal>, and <literal>mlyacc</literal> that come with the MLton binary package. To be
30594 safe, you should use the same version of MLton that you are building.
30595 However, older versions may work, as long as they don&#8217;t go back too
30596 far. To build MLton, run <literal>make</literal> from within the root directory of the
30597 sources. This will build MLton first with the already installed
30598 binary version of MLton and will then rebuild MLton with itself.</simpara>
30599 <simpara>First, the <literal>Makefile</literal> calls <literal>mllex</literal> and <literal>mlyacc</literal> to build the lexer
30600 and parser, and then calls <literal>mlton</literal> to compile itself. When making
30601 MLton using another version the <literal>Makefile</literal> automatically uses
30602 <literal>mlton-stubs.mlb</literal>, which will put in enough stubs to emulate the
30603 <literal>structure MLton</literal>. Once MLton is built, the <literal>Makefile</literal> will rebuild
30604 MLton with itself, this time using <literal>mlton.mlb</literal> and the real
30605 <literal>structure MLton</literal> from the <link linkend="BasisLibrary">Basis Library</link>. This second round
30606 of compilation is essential in order to achieve a fast and robust
30607 MLton.</simpara>
30608 <simpara>Compiling MLton requires at least 1GB of RAM for 32-bit platforms (2GB is
30609 preferable) and at least 2GB RAM for 64-bit platforms (4GB is preferable).
30610 If your machine has less RAM, self-compilation will
30611 likely fail, or at least take a very long time due to paging. Even if
30612 you have enough memory, there simply may not be enough available, due
30613 to memory consumed by other processes. In this case, you may see an
30614 <literal>Out of memory</literal> message, or self-compilation may become extremely
30615 slow. The only fix is to make sure that enough memory is available.</simpara>
30616 <section id="_possible_errors">
30617 <title>Possible Errors</title>
30618 <itemizedlist>
30619 <listitem>
30620 <simpara>
30621 The C compiler may not be able to find the <link linkend="GnuMP">GnuMP</link> header file,
30622 <literal>gmp.h</literal> leading to an error like the following.
30623 </simpara>
30624 <screen> cenv.h:49:18: fatal error: gmp.h: No such file or directory</screen>
30625 <simpara>The solution is to install (or build) GnuMP on your machine. If you
30626 install it at a location not on the default seach path, then run
30627 <literal>make WITH_GMP_INC_DIR=<emphasis>/path/to/gmp/include</emphasis> WITH_GMP_LIB_DIR=<emphasis>/path/to/gmp/lib</emphasis></literal>.</simpara>
30628 </listitem>
30629 <listitem>
30630 <simpara>
30631 The following errors indicates that a binary version of MLton could
30632 not be found in your path.
30633 </simpara>
30634 <screen>/bin/sh: mlton: command not found</screen>
30635 <screen>make[2]: mlton: Command not found</screen>
30636 <simpara>You need to have <literal>mlton</literal> in your path to build MLton from source.</simpara>
30637 <simpara>During the build process, there are various times that the <literal>Makefile</literal>-s
30638 look for a <literal>mlton</literal> in your path and in <literal>src/build/bin</literal>. It is OK if
30639 the latter doesn&#8217;t exist when the build starts; it is the target being
30640 built. Failure to find a <literal>mlton</literal> in your path will abort the build.</simpara>
30641 </listitem>
30642 </itemizedlist>
30643 </section>
30644 </section>
30645 <section id="_compiling_with_sml_nj">
30646 <title>Compiling with SML/NJ</title>
30647 <simpara>To compile with SML/NJ, run <literal>make bootstrap-smlnj</literal> from within the
30648 root directory of the sources. You must use a recent version of
30649 SML/NJ. First, the <literal>Makefile</literal> calls <literal>ml-lex</literal> and <literal>ml-yacc</literal> to build
30650 the lexer and parser. Then, it calls SML/NJ with the appropriate
30651 <literal>sources.cm</literal> file. Once MLton is built with SML/NJ, the <literal>Makefile</literal>
30652 will rebuild MLton with this SML/NJ built MLton and then will rebuild
30653 MLton with the MLton built MLton. Building with SML/NJ takes
30654 significant time (particularly during the "<literal>parseAndElaborate</literal>" phase
30655 when the SML/NJ built MLton is compiling MLton). Unless you are doing
30656 compiler development and need rapid recompilation, we recommend
30657 compiling with MLton.</simpara>
30658 <simpara><?asciidoc-pagebreak?></simpara>
30659 </section>
30660 </section>
30661 <section id="Serialization">
30662 <title>Serialization</title>
30663 <simpara><link linkend="StandardML">Standard ML</link> does not have built-in support for
30664 serialization. Here are papers that describe user-level approaches:</simpara>
30665 <itemizedlist>
30666 <listitem>
30667 <simpara>
30668 <link linkend="References_Elsman04">Elsman04</link>
30669 </simpara>
30670 </listitem>
30671 <listitem>
30672 <simpara>
30673 <link linkend="References_Kennedy04">Kennedy04</link>
30674 </simpara>
30675 </listitem>
30676 </itemizedlist>
30677 <simpara>The MLton repository also contains an experimental generic programming
30678 library (see
30679 <ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/generic/unstable/README"><literal>README</literal></ulink>) that
30680 includes a pickling (serialization) generic (see
30681 <ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/generic/unstable/public/value/pickle.sig"><literal>pickle.sig</literal></ulink>).</simpara>
30682 <simpara><?asciidoc-pagebreak?></simpara>
30683 </section>
30684 <section id="ShareZeroVec">
30685 <title>ShareZeroVec</title>
30686 <simpara><link linkend="ShareZeroVec">ShareZeroVec</link> is an optimization pass for the <link linkend="SSA">SSA</link>
30687 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
30688 <section id="_description_54">
30689 <title>Description</title>
30690 <simpara>An SSA optimization to share zero-length vectors.</simpara>
30691 <simpara>From <ulink url="https://github.com/MLton/mlton/commit/be8c5f576"><literal>be8c5f576</literal></ulink>, which replaced the use of the
30692 <literal>Array_array0Const</literal> primitive in the Basis Library implementation with a
30693 (nullary) <literal>Vector_vector</literal> primitive:</simpara>
30694 <blockquote>
30695 <simpara>The original motivation for the <literal>Array_array0Const</literal> primitive was to share the
30696 heap space required for zero-length vectors among all vectors (of a given type).
30697 It was claimed that this optimization is important, e.g., in a self-compile,
30698 where vectors are used for lots of syntax tree elements and many of those
30699 vectors are empty. See:
30700 <ulink url="http://www.mlton.org/pipermail/mlton-devel/2002-February/021523.html">http://www.mlton.org/pipermail/mlton-devel/2002-February/021523.html</ulink></simpara>
30701 <simpara>Curiously, the full effect of this optimization has been missing for quite some
30702 time (perhaps since the port of <link linkend="ConstantPropagation">ConstantPropagation</link> to the SSA IL). While
30703 <link linkend="ConstantPropagation">ConstantPropagation</link> has "globalized" the nullary application of the
30704 <literal>Array_array0Const</literal> primitive, it also simultaneously transformed it to an
30705 application of the <literal>Array_uninit</literal> (previously, the <literal>Array_array</literal>) primitive to
30706 the zero constant. The hash-consing of globals, meant to create exactly one
30707 global for each distinct constant, treats <literal>Array_uninit</literal> primitives as unequal
30708 (appropriately, since <literal>Array_uninit</literal> allocates an array with identity (though
30709 the identity may be supressed by a subsequent <literal>Array_toVector</literal>)), hence each
30710 distinct <literal>Array_array0Const</literal> primitive in the program remained as distinct
30711 globals. The limited amount of inlining prior to <link linkend="ConstantPropagation">ConstantPropagation</link> meant
30712 that there were typically fewer than a dozen "copies" of the same empty vector
30713 in a program for a given type.</simpara>
30714 <simpara>As a "functional" primitive, a nullary <literal>Vector_vector</literal> is globalized by
30715 ClosureConvert, but is further recognized by ConstantPropagation and hash-consed
30716 into a unique instance for each type.</simpara>
30717 </blockquote>
30718 <simpara>However, a single, shared, global <literal>Vector_vector ()</literal> inhibits the
30719 coercion-based optimizations of <literal>Useless</literal>. For example, consider the
30720 following program:</simpara>
30721 <programlisting language="sml" linenumbering="unnumbered"> val n = valOf (Int.fromString (hd (CommandLine.arguments ())))
30722
30723 val v1 = Vector.tabulate (n, fn i =&gt;
30724 let val w = Word16.fromInt i
30725 in (w - 0wx1, w, w + 0wx1 + w)
30726 end)
30727 val v2 = Vector.map (fn (w1, w2, w3) =&gt; (w1, 0wx2 * w2, 0wx3 * w3)) v1
30728 val v3 = VectorSlice.vector (VectorSlice.slice (v1, 1, SOME (n - 2)))
30729 val ans1 = Vector.foldl (fn ((w1,w2,w3),w) =&gt; w + w1 + w2 + w3) 0wx0 v1
30730 val ans2 = Vector.foldl (fn ((_,w2,_),w) =&gt; w + w2) 0wx0 v2
30731 val ans3 = Vector.foldl (fn ((_,w2,_),w) =&gt; w + w2) 0wx0 v3
30732
30733 val _ = print (concat ["ans1 = ", Word16.toString ans1, " ",
30734 "ans2 = ", Word16.toString ans2, " ",
30735 "ans3 = ", Word16.toString ans3, "\n"])</programlisting>
30736 <simpara>We would like <literal>v2</literal> and <literal>v3</literal> to be optimized from
30737 <literal>(word16 * word16 * word16) vector</literal> to <literal>word16 vector</literal> because only
30738 the 2nd component of the elements is needed to compute the answer.</simpara>
30739 <simpara>With <literal>Array_array0Const</literal>, each distinct occurrence of
30740 <literal>Array_array0Const((word16 * word16 * word16))</literal> arising from
30741 polyvariance and inlining remained a distinct
30742 <literal>Array_uninit((word16 * word16 * word16)) (0x0)</literal> global, which
30743 resulted in distinct occurrences for the
30744 <literal>val v1 = Vector.tabulate ...</literal> and for the
30745 <literal>val v2 = Vector.map ...</literal>. The latter could be optimized to
30746 <literal>Array_uninit(word16) (0x0)</literal> by <literal>Useless</literal>, because its result only
30747 flows to places requiring the 2nd component of the elements.</simpara>
30748 <simpara>With <literal>Vector_vector ()</literal>, the distinct occurrences of
30749 <literal>Vector_vector((word16 * word16 * word16)) ()</literal> arising from
30750 polyvariance are globalized during <literal>ClosureConvert</literal>, those global
30751 references may be further duplicated by inlining, but the distinct
30752 occurrences of <literal>Vector_vector((word16 * word16 * word16)) ()</literal> are
30753 merged to a single occurrence. Because this result flows to places
30754 requiring all three components of the elements, it remains
30755 <literal>Vector_vector((word16 * word16 * word16)) ()</literal> after
30756 <literal>Useless</literal>. Furthermore, because one cannot (in constant time) coerce a
30757 <literal>(word16 * word16 * word16) vector</literal> to a <literal>word16 vector</literal>, the <literal>v2</literal>
30758 value remains of type <literal>(word16 * word16 * word16) vector</literal>.</simpara>
30759 <simpara>One option would be to drop the 0-element vector "optimization"
30760 entirely. This costs some space (no sharing of empty vectors) and
30761 some time (allocation and garbage collection of empty vectors).</simpara>
30762 <simpara>Another option would be to reinstate the <literal>Array_array0Const</literal> primitive
30763 and associated <literal>ConstantPropagation</literal> treatment. But, the semantics
30764 and purpose of <literal>Array_array0Const</literal> was poorly understood, resulting in
30765 this break.</simpara>
30766 <simpara>The <link linkend="ShareZeroVec">ShareZeroVec</link> pass pursues a different approach: perform the 0-element
30767 vector "optimization" as a separate optimization, after
30768 <literal>ConstantPropagation</literal> and <literal>Useless</literal>. A trivial static analysis is
30769 used to match <literal>val v: t vector = Array_toVector(t) (a)</literal> with
30770 corresponding <literal>val a: array = Array_uninit(t) (l)</literal> and the later are
30771 expanded to
30772 <literal>val a: t array = if 0 = l then zeroArr_[t] else Array_uninit(t) (l)</literal>
30773 with a single global <literal>val zeroArr_[t] = Array_uninit(t) (0)</literal> created
30774 for each distinct type (after coercion-based optimizations).</simpara>
30775 <simpara>One disadvantage of this approach, compared to the <literal>Vector_vector(t) ()</literal>
30776 approach, is that <literal>Array_toVector</literal> is applied each time a vector
30777 is created, even if it is being applied to the <literal>zeroArr_[t]</literal>
30778 zero-length array. (Although, this was the behavior of the
30779 <literal>Array_array0Const</literal> approach.) This updates the object header each
30780 time, whereas the <literal>Vector_vector(t) ()</literal> approach would have updated
30781 the object header once, when the global was created, and the
30782 <literal>zeroVec_[t]</literal> global and the <literal>Array_toVector</literal> result would flow to the
30783 join point.</simpara>
30784 <simpara>It would be possible to properly share zero-length vectors, but doing
30785 so is a more sophisticated analysis and transformation, because there
30786 can be arbitrary code between the
30787 <literal>val a: t array = Array_uninit(t) (l)</literal> and the corresponding
30788 <literal>val v: v vector = Array_toVector(t) (a)</literal>, although, in practice,
30789 nothing happens when a zero-length vector is created. It may be best
30790 to pursue a more general "array to vector" optimization that
30791 transforms creations of static-length vectors (e.g., all the
30792 <literal>Vector.new&lt;N&gt;</literal> functions) into <literal>Vector_vector</literal> primitives (some of
30793 which could be globalized).</simpara>
30794 </section>
30795 <section id="_implementation_59">
30796 <title>Implementation</title>
30797 <itemizedlist>
30798 <listitem>
30799 <simpara>
30800 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/share-zero-vec.fun"><literal>share-zero-vec.fun</literal></ulink>
30801 </simpara>
30802 </listitem>
30803 </itemizedlist>
30804 </section>
30805 <section id="_details_and_notes_57">
30806 <title>Details and Notes</title>
30807 <simpara></simpara>
30808 <simpara><?asciidoc-pagebreak?></simpara>
30809 </section>
30810 </section>
30811 <section id="ShowBasis">
30812 <title>ShowBasis</title>
30813 <simpara>MLton has a flag, <literal>-show-basis &lt;file&gt;</literal>, that causes MLton to pretty
30814 print to <emphasis>file</emphasis> the basis defined by the input program. For example,
30815 if <literal>foo.sml</literal> contains</simpara>
30816 <programlisting language="sml" linenumbering="unnumbered">fun f x = x + 1</programlisting>
30817 <simpara>then <literal>mlton -show-basis foo.basis foo.sml</literal> will create <literal>foo.basis</literal>
30818 with the following contents.</simpara>
30819 <screen>val f: int -&gt; int</screen>
30820 <simpara>If you only want to see the basis and do not wish to compile the
30821 program, you can call MLton with <literal>-stop tc</literal>.</simpara>
30822 <section id="_displaying_signatures">
30823 <title>Displaying signatures</title>
30824 <simpara>When displaying signatures, MLton prefixes types defined in the
30825 signature them with <literal>_sig.</literal> to distinguish them from types defined in the
30826 environment. For example,</simpara>
30827 <programlisting language="sml" linenumbering="unnumbered">signature SIG =
30828 sig
30829 type t
30830 val x: t * int -&gt; unit
30831 end</programlisting>
30832 <simpara>is displayed as</simpara>
30833 <screen>signature SIG =
30834 sig
30835 type t
30836 val x: _sig.t * int -&gt; unit
30837 end</screen>
30838 <simpara>Notice that <literal>int</literal> occurs without the <literal>_sig.</literal> prefix.</simpara>
30839 <simpara>MLton also uses a canonical name for each type in the signature, and
30840 that name is used everywhere for that type, no matter what the input
30841 signature looked like. For example:</simpara>
30842 <programlisting language="sml" linenumbering="unnumbered">signature SIG =
30843 sig
30844 type t
30845 type u = t
30846 val x: t
30847 val y: u
30848 end</programlisting>
30849 <simpara>is displayed as</simpara>
30850 <screen>signature SIG =
30851 sig
30852 type t
30853 type u = _sig.t
30854 val x: _sig.t
30855 val y: _sig.t
30856 end</screen>
30857 <simpara>Canonical names are always relative to the "top" of the signature,
30858 even when used in nested substructures. For example:</simpara>
30859 <programlisting language="sml" linenumbering="unnumbered">signature S =
30860 sig
30861 type t
30862 val w: t
30863 structure U:
30864 sig
30865 type u
30866 val x: t
30867 val y: u
30868 end
30869 val z: U.u
30870 end</programlisting>
30871 <simpara>is displayed as</simpara>
30872 <screen>signature S =
30873 sig
30874 type t
30875 val w: _sig.t
30876 val z: _sig.U.u
30877 structure U:
30878 sig
30879 type u
30880 val x: _sig.t
30881 val y: _sig.U.u
30882 end
30883 end</screen>
30884 </section>
30885 <section id="_displaying_structures">
30886 <title>Displaying structures</title>
30887 <simpara>When displaying structures, MLton uses signature constraints wherever
30888 possible, combined with <literal>where type</literal> clauses to specify the meanings
30889 of the types defined within the signature. For example:</simpara>
30890 <programlisting language="sml" linenumbering="unnumbered">signature SIG =
30891 sig
30892 type t
30893 val x: t
30894 end
30895 structure S: SIG =
30896 struct
30897 type t = int
30898 val x = 13
30899 end
30900 structure S2:&gt; SIG = S</programlisting>
30901 <simpara>is displayed as</simpara>
30902 <screen>signature SIG =
30903 sig
30904 type t
30905 val x: _sig.t
30906 end
30907 structure S: SIG
30908 where type t = int
30909 structure S2: SIG
30910 where type t = S2.t</screen>
30911 <simpara><?asciidoc-pagebreak?></simpara>
30912 </section>
30913 </section>
30914 <section id="ShowBasisDirective">
30915 <title>ShowBasisDirective</title>
30916 <simpara>A comment of the form <literal>(*#showBasis "&lt;file&gt;"*)</literal> is recognized as a directive to
30917 save the current basis (i.e., environment) to <literal>&lt;file&gt;</literal> (in the same format as
30918 the <literal>-show-basis &lt;file&gt;</literal> <link linkend="CompileTimeOptions">compile-time option</link>). The
30919 <literal>&lt;file&gt;</literal> is interpreted relative to the source file in which it appears. The
30920 comment is lexed as a distinct token and is parsed as a structure-level
30921 declaration. [Note that treating the directive as a top-level declaration would
30922 prohibit using it inside a functor body, which would make the feature
30923 significantly less useful in the context of the MLton compiler sources (with its
30924 nearly fully functorial style).]</simpara>
30925 <simpara>This feature is meant to facilitate auto-completion via
30926 <ulink url="https://github.com/MatthewFluet/company-mlton"><literal>company-mlton</literal></ulink> and similar
30927 tools.</simpara>
30928 <simpara><?asciidoc-pagebreak?></simpara>
30929 </section>
30930 <section id="ShowProf">
30931 <title>ShowProf</title>
30932 <simpara>If an executable is compiled for <link linkend="Profiling">profiling</link>, then it
30933 accepts a special command-line runtime system argument, <literal>show-prof</literal>,
30934 that outputs information about the source functions that are profiled.
30935 Normally, this information is used by <literal>mlprof</literal>. This page documents
30936 the <literal>show-prof</literal> output format, and is intended for those working on
30937 the profiler internals.</simpara>
30938 <simpara>The <literal>show-prof</literal> output is ASCII, and consists of a sequence of lines.</simpara>
30939 <itemizedlist>
30940 <listitem>
30941 <simpara>
30942 The magic number of the executable.
30943 </simpara>
30944 </listitem>
30945 <listitem>
30946 <simpara>
30947 The number of source names in the executable.
30948 </simpara>
30949 </listitem>
30950 <listitem>
30951 <simpara>
30952 A line for each source name giving the name of the function, a tab,
30953 the filename of the file containing the function, a colon, a space,
30954 and the line number that the function starts on in that file.
30955 </simpara>
30956 </listitem>
30957 <listitem>
30958 <simpara>
30959 The number of (split) source functions.
30960 </simpara>
30961 </listitem>
30962 <listitem>
30963 <simpara>
30964 A line for each (split) source function, where each line consists of
30965 a source-name index (into the array of source names) and a successors
30966 index (into the array of split-source sequences, defined below).
30967 </simpara>
30968 </listitem>
30969 <listitem>
30970 <simpara>
30971 The number of split-source sequences.
30972 </simpara>
30973 </listitem>
30974 <listitem>
30975 <simpara>
30976 A line for each split-source sequence, where each line is a space
30977 separated list of (split) source functions.
30978 </simpara>
30979 </listitem>
30980 </itemizedlist>
30981 <simpara>The latter two arrays, split sources and split-source sequences,
30982 define a directed graph, which is the call-graph of the program.</simpara>
30983 <simpara><?asciidoc-pagebreak?></simpara>
30984 </section>
30985 <section id="Shrink">
30986 <title>Shrink</title>
30987 <simpara><link linkend="Shrink">Shrink</link> is a rewrite pass for the <link linkend="SSA">SSA</link> and <link linkend="SSA2">SSA2</link>
30988 <link linkend="IntermediateLanguage">IntermediateLanguage</link>s, invoked from every optimization pass (see
30989 <link linkend="SSASimplify">SSASimplify</link> and <link linkend="SSA2Simplify">SSA2Simplify</link>).</simpara>
30990 <section id="_description_55">
30991 <title>Description</title>
30992 <simpara>This pass implements a whole family of compile-time reductions, like:</simpara>
30993 <itemizedlist>
30994 <listitem>
30995 <simpara>
30996 <literal>#1(a, b)</literal> &#8658; <literal>a</literal>
30997 </simpara>
30998 </listitem>
30999 <listitem>
31000 <simpara>
31001 <literal>case C x of C y =&gt; e</literal> &#8658; <literal>let y = x in e</literal>
31002 </simpara>
31003 </listitem>
31004 <listitem>
31005 <simpara>
31006 constant folding, copy propagation
31007 </simpara>
31008 </listitem>
31009 <listitem>
31010 <simpara>
31011 eta blocks
31012 </simpara>
31013 </listitem>
31014 <listitem>
31015 <simpara>
31016 tuple reconstruction elimination
31017 </simpara>
31018 </listitem>
31019 </itemizedlist>
31020 </section>
31021 <section id="_implementation_60">
31022 <title>Implementation</title>
31023 <itemizedlist>
31024 <listitem>
31025 <simpara>
31026 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/shrink.sig"><literal>shrink.sig</literal></ulink>
31027 </simpara>
31028 </listitem>
31029 <listitem>
31030 <simpara>
31031 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/shrink.fun"><literal>shrink.fun</literal></ulink>
31032 </simpara>
31033 </listitem>
31034 <listitem>
31035 <simpara>
31036 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/shrink2.sig"><literal>shrink2.sig</literal></ulink>
31037 </simpara>
31038 </listitem>
31039 <listitem>
31040 <simpara>
31041 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/shrink2.fun"><literal>shrink2.fun</literal></ulink>
31042 </simpara>
31043 </listitem>
31044 </itemizedlist>
31045 </section>
31046 <section id="_details_and_notes_58">
31047 <title>Details and Notes</title>
31048 <simpara>The <link linkend="Shrink">Shrink</link> pass is run after every <link linkend="SSA">SSA</link> and <link linkend="SSA2">SSA2</link>
31049 optimization pass.</simpara>
31050 <simpara>The <link linkend="Shrink">Shrink</link> implementation also includes functions to eliminate
31051 unreachable blocks from a <link linkend="SSA">SSA</link> or <link linkend="SSA2">SSA2</link> program or function.
31052 The <link linkend="Shrink">Shrink</link> pass does not guarantee to eliminate all unreachable
31053 blocks. Doing so would unduly complicate the implementation, and it
31054 is almost always the case that all unreachable blocks are eliminated.
31055 However, a small number of optimization passes require that the input
31056 have no unreachable blocks (essentially, when the analysis works on
31057 the control flow graph and the rewrite iterates on the vector of
31058 blocks). These passes explicitly call <literal>eliminateDeadBlocks</literal>.</simpara>
31059 <simpara>The <link linkend="Shrink">Shrink</link> pass has a special case to turn a non-tail call where
31060 the continuation and handler only do <literal>Profile</literal> statements into a tail
31061 call where the <literal>Profile</literal> statements precede the tail call.</simpara>
31062 <simpara><?asciidoc-pagebreak?></simpara>
31063 </section>
31064 </section>
31065 <section id="SimplifyTypes">
31066 <title>SimplifyTypes</title>
31067 <simpara><link linkend="SimplifyTypes">SimplifyTypes</link> is an optimization pass for the <link linkend="SSA">SSA</link>
31068 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
31069 <section id="_description_56">
31070 <title>Description</title>
31071 <simpara>This pass computes a "cardinality" of each datatype, which is an
31072 abstraction of the number of values of the datatype.</simpara>
31073 <itemizedlist>
31074 <listitem>
31075 <simpara>
31076 <literal>Zero</literal> means the datatype has no values (except for bottom).
31077 </simpara>
31078 </listitem>
31079 <listitem>
31080 <simpara>
31081 <literal>One</literal> means the datatype has one value (except for bottom).
31082 </simpara>
31083 </listitem>
31084 <listitem>
31085 <simpara>
31086 <literal>Many</literal> means the datatype has many values.
31087 </simpara>
31088 </listitem>
31089 </itemizedlist>
31090 <simpara>This pass removes all datatypes whose cardinality is <literal>Zero</literal> or <literal>One</literal>
31091 and removes:</simpara>
31092 <itemizedlist>
31093 <listitem>
31094 <simpara>
31095 components of tuples
31096 </simpara>
31097 </listitem>
31098 <listitem>
31099 <simpara>
31100 function args
31101 </simpara>
31102 </listitem>
31103 <listitem>
31104 <simpara>
31105 constructor args
31106 </simpara>
31107 </listitem>
31108 </itemizedlist>
31109 <simpara>which are such datatypes.</simpara>
31110 <simpara>This pass marks constructors as one of:</simpara>
31111 <itemizedlist>
31112 <listitem>
31113 <simpara>
31114 <literal>Useless</literal>: it never appears in a <literal>ConApp</literal>.
31115 </simpara>
31116 </listitem>
31117 <listitem>
31118 <simpara>
31119 <literal>Transparent</literal>: it is the only variant in its datatype and its argument type does not contain any uses of <literal>array</literal> or <literal>vector</literal>.
31120 </simpara>
31121 </listitem>
31122 <listitem>
31123 <simpara>
31124 <literal>Useful</literal>: otherwise
31125 </simpara>
31126 </listitem>
31127 </itemizedlist>
31128 <simpara>This pass also removes <literal>Useless</literal> and <literal>Transparent</literal> constructors.</simpara>
31129 </section>
31130 <section id="_implementation_61">
31131 <title>Implementation</title>
31132 <itemizedlist>
31133 <listitem>
31134 <simpara>
31135 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/simplify-types.fun"><literal>simplify-types.fun</literal></ulink>
31136 </simpara>
31137 </listitem>
31138 </itemizedlist>
31139 </section>
31140 <section id="_details_and_notes_59">
31141 <title>Details and Notes</title>
31142 <simpara>This pass must happen before polymorphic equality is implemented because</simpara>
31143 <itemizedlist>
31144 <listitem>
31145 <simpara>
31146 it will make polymorphic equality faster because some types are simpler
31147 </simpara>
31148 </listitem>
31149 <listitem>
31150 <simpara>
31151 it removes uses of polymorphic equality that must return true
31152 </simpara>
31153 </listitem>
31154 </itemizedlist>
31155 <simpara>We must keep track of <literal>Transparent</literal> constructors whose argument type
31156 uses <literal>array</literal> because of datatypes like the following:</simpara>
31157 <programlisting language="sml" linenumbering="unnumbered">datatype t = T of t array</programlisting>
31158 <simpara>Such a datatype has <literal>Cardinality.Many</literal>, but we cannot eliminate the
31159 datatype and replace the lhs by the rhs, i.e. we must keep the
31160 circularity around.</simpara>
31161 <simpara>Must do similar things for <literal>vectors</literal>.</simpara>
31162 <simpara>Also, to eliminate as many <literal>Transparent</literal> constructors as possible, for
31163 something like the following,</simpara>
31164 <programlisting language="sml" linenumbering="unnumbered">datatype t = T of u array
31165 and u = U of t vector</programlisting>
31166 <simpara>we (arbitrarily) expand one of the datatypes first. The result will
31167 be something like</simpara>
31168 <programlisting language="sml" linenumbering="unnumbered">datatype u = U of u array array</programlisting>
31169 <simpara>where all uses of <literal>t</literal> are replaced by <literal>u array</literal>.</simpara>
31170 <simpara><?asciidoc-pagebreak?></simpara>
31171 </section>
31172 </section>
31173 <section id="SML3d">
31174 <title>SML3d</title>
31175 <simpara>The <ulink url="http://sml3d.cs.uchicago.edu/">SML3d Project</ulink> is a collection of
31176 libraries to support 3D graphics programming using Standard ML and the
31177 <ulink url="http://www.opengl.org/">OpenGL</ulink> graphics API. It currently requires the
31178 MLton implementation of SML and is supported on Linux, Mac OS X, and
31179 Microsoft Windows. There is also support for
31180 <ulink url="http://www.khronos.org/opencl/">OpenCL</ulink>.</simpara>
31181 <simpara><?asciidoc-pagebreak?></simpara>
31182 </section>
31183 <section id="SMLNET">
31184 <title>SMLNET</title>
31185 <simpara><ulink url="http://www.cl.cam.ac.uk/research/tsg/SMLNET">SML.NET</ulink> is a
31186 <link linkend="StandardMLImplementations">Standard ML implementation</link> that
31187 targets the .NET Common Language Runtime.</simpara>
31188 <simpara>SML.NET is based on the <link linkend="MLj">MLj</link> compiler.</simpara>
31189 <section id="_also_see_43">
31190 <title>Also see</title>
31191 <itemizedlist>
31192 <listitem>
31193 <simpara>
31194 <link linkend="References_BentonEtAl04">BentonEtAl04</link>
31195 </simpara>
31196 </listitem>
31197 </itemizedlist>
31198 <simpara><?asciidoc-pagebreak?></simpara>
31199 </section>
31200 </section>
31201 <section id="SMLNJ">
31202 <title>SMLNJ</title>
31203 <simpara><ulink url="http://www.smlnj.org/">SML/NJ</ulink> is a
31204 <link linkend="StandardMLImplementations">Standard ML implementation</link>. It is a
31205 native code compiler that runs on a variety of platforms and has a
31206 number of libraries and tools.</simpara>
31207 <simpara>We maintain a list of SML/NJ&#8217;s <link linkend="SMLNJDeviations">deviations</link> from
31208 <link linkend="DefinitionOfStandardML">The Definition of Standard ML</link>.</simpara>
31209 <simpara>MLton has support for some features of SML/NJ in order to ease porting
31210 between MLton and SML/NJ.</simpara>
31211 <itemizedlist>
31212 <listitem>
31213 <simpara>
31214 <link linkend="CompilationManager">CompilationManager</link> (CM)
31215 </simpara>
31216 </listitem>
31217 <listitem>
31218 <simpara>
31219 <link linkend="LineDirective">LineDirective</link>s
31220 </simpara>
31221 </listitem>
31222 <listitem>
31223 <simpara>
31224 <link linkend="SMLofNJStructure">SMLofNJStructure</link>
31225 </simpara>
31226 </listitem>
31227 <listitem>
31228 <simpara>
31229 <link linkend="UnsafeStructure">UnsafeStructure</link>
31230 </simpara>
31231 </listitem>
31232 </itemizedlist>
31233 <simpara><?asciidoc-pagebreak?></simpara>
31234 </section>
31235 <section id="SMLNJDeviations">
31236 <title>SMLNJDeviations</title>
31237 <simpara>Here are some deviations of <link linkend="SMLNJ">SML/NJ</link> from
31238 <link linkend="DefinitionOfStandardML">The Definition of Standard ML (Revised)</link>.
31239 Some of these are documented in the
31240 <ulink url="http://www.smlnj.org/doc/Conversion/index.html">SML '97 Conversion Guide</ulink>.
31241 Since MLton does not deviate from the Definition, you should look here
31242 if you are having trouble porting a program from MLton to SML/NJ or
31243 vice versa. If you discover other deviations of SML/NJ that aren&#8217;t
31244 listed here, please send mail to
31245 <ulink url="mailto:MLton-devel@mlton.org"><literal>MLton-devel@mlton.org</literal></ulink>.</simpara>
31246 <itemizedlist>
31247 <listitem>
31248 <simpara>
31249 SML/NJ allows spaces in long identifiers, as in <literal>S . x</literal>. Section
31250 2.5 of the Definition implies that <literal>S . x</literal> should be treated as three
31251 separate lexical items.
31252 </simpara>
31253 </listitem>
31254 <listitem>
31255 <simpara>
31256 SML/NJ allows <literal>op</literal> to appear in <literal>val</literal> specifications:
31257 </simpara>
31258 <programlisting language="sml" linenumbering="unnumbered">signature FOO = sig
31259 val op + : int * int -&gt; int
31260 end</programlisting>
31261 <simpara>The grammar on page 14 of the Definition does not allow it. Recent
31262 versions of SML/NJ do give a warning.</simpara>
31263 </listitem>
31264 <listitem>
31265 <simpara>
31266 SML/NJ rejects
31267 </simpara>
31268 <programlisting language="sml" linenumbering="unnumbered">(op *)</programlisting>
31269 <simpara>as an unmatched close comment.</simpara>
31270 </listitem>
31271 <listitem>
31272 <simpara>
31273 SML/NJ allows <literal>=</literal> to be rebound by the declaration:
31274 </simpara>
31275 <programlisting language="sml" linenumbering="unnumbered">val op = = 13</programlisting>
31276 <simpara>This is explicitly forbidden on page 5 of the Definition. Recent
31277 versions of SML/NJ do give a warning.</simpara>
31278 </listitem>
31279 <listitem>
31280 <simpara>
31281 SML/NJ allows rebinding <literal>true</literal>, <literal>false</literal>, <literal>nil</literal>, <literal>::</literal>, and <literal>ref</literal> by
31282 the declarations:
31283 </simpara>
31284 <programlisting language="sml" linenumbering="unnumbered">fun true () = ()
31285 fun false () = ()
31286 fun nil () = ()
31287 fun op :: () = ()
31288 fun ref () = ()</programlisting>
31289 <simpara>This is explicitly forbidden on page 9 of the Definition.</simpara>
31290 </listitem>
31291 <listitem>
31292 <simpara>
31293 SML/NJ extends the syntax of the language to allow vector
31294 expressions and patterns like the following:
31295 </simpara>
31296 <programlisting language="sml" linenumbering="unnumbered">val v = #[1,2,3]
31297 val #[x,y,z] = v</programlisting>
31298 <simpara>MLton supports vector expressions and patterns with the <link linkend="SuccessorML_VectorExpsAndPats"><literal>allowVectorExpsAndPats</literal></link> <link linkend="MLBasisAnnotations">ML Basis annotation</link>.</simpara>
31299 </listitem>
31300 <listitem>
31301 <simpara>
31302 SML/NJ extends the syntax of the language to allow <emphasis>or patterns</emphasis>
31303 like the following:
31304 </simpara>
31305 <programlisting language="sml" linenumbering="unnumbered">datatype foo = Foo of int | Bar of int
31306 val (Foo x | Bar x) = Foo 13</programlisting>
31307 <simpara>MLton supports or patterns with the <link linkend="SuccessorML_OrPats"><literal>allowOrPats</literal></link> <link linkend="MLBasisAnnotations">ML Basis annotation</link>.</simpara>
31308 </listitem>
31309 <listitem>
31310 <simpara>
31311 SML/NJ allows higher-order functors, that is, functors can be
31312 components of structures and can be passed as functor arguments and
31313 returned as functor results. As a consequence, SML/NJ allows
31314 abbreviated functor definitions, as in the following:
31315 </simpara>
31316 <programlisting language="sml" linenumbering="unnumbered">signature S =
31317 sig
31318 type t
31319 val x: t
31320 end
31321 functor F (structure A: S): S =
31322 struct
31323 type t = A.t * A.t
31324 val x = (A.x, A.x)
31325 end
31326 functor G = F</programlisting>
31327 </listitem>
31328 <listitem>
31329 <simpara>
31330 SML/NJ extends the syntax of the language to allow <literal>functor</literal> and
31331 <literal>signature</literal> declarations to occur within the scope of <literal>local</literal> and
31332 <literal>structure</literal> declarations.
31333 </simpara>
31334 </listitem>
31335 <listitem>
31336 <simpara>
31337 SML/NJ allows duplicate type specifications in signatures when the
31338 duplicates are introduced by <literal>include</literal>, as in the following:
31339 </simpara>
31340 <programlisting language="sml" linenumbering="unnumbered">signature SIG1 =
31341 sig
31342 type t
31343 type u
31344 end
31345 signature SIG2 =
31346 sig
31347 type t
31348 type v
31349 end
31350 signature SIG =
31351 sig
31352 include SIG1
31353 include SIG2
31354 end</programlisting>
31355 <simpara>This is disallowed by rule 77 of the Definition.</simpara>
31356 </listitem>
31357 <listitem>
31358 <simpara>
31359 SML/NJ allows sharing constraints between type abbreviations in
31360 signatures, as in the following:
31361 </simpara>
31362 <programlisting language="sml" linenumbering="unnumbered">signature SIG =
31363 sig
31364 type t = int * int
31365 type u = int * int
31366 sharing type t = u
31367 end</programlisting>
31368 <simpara>These are disallowed by rule 78 of the Definition. Recent versions of
31369 SML/NJ correctly disallow sharing constraints between type
31370 abbreviations in signatures.</simpara>
31371 </listitem>
31372 <listitem>
31373 <simpara>
31374 SML/NJ disallows multiple <literal>where type</literal> specifications of the same
31375 type name, as in the following
31376 </simpara>
31377 <programlisting language="sml" linenumbering="unnumbered">signature S =
31378 sig
31379 type t
31380 type u = t
31381 end
31382 where type u = int</programlisting>
31383 <simpara>This is allowed by rule 64 of the Definition.</simpara>
31384 </listitem>
31385 <listitem>
31386 <simpara>
31387 SML/NJ allows <literal>and</literal> in <literal>sharing</literal> specs in signatures, as in
31388 </simpara>
31389 <programlisting language="sml" linenumbering="unnumbered">signature S =
31390 sig
31391 type t
31392 type u
31393 type v
31394 sharing type t = u
31395 and type u = v
31396 end</programlisting>
31397 </listitem>
31398 <listitem>
31399 <simpara>
31400 SML/NJ does not expand the <literal>withtype</literal> derived form as described by
31401 the Definition. According to page 55 of the Definition, the type
31402 bindings of a <literal>withtype</literal> declaration are substituted simultaneously in
31403 the connected datatype. Consider the following program.
31404 </simpara>
31405 <programlisting language="sml" linenumbering="unnumbered">type u = real ;
31406 datatype a =
31407 A of t
31408 | B of u
31409 withtype u = int
31410 and t = u</programlisting>
31411 <simpara>According to the Definition, it should be expanded to the following.</simpara>
31412 <programlisting language="sml" linenumbering="unnumbered">type u = real ;
31413 datatype a =
31414 A of u
31415 | B of int ;
31416 type u = int
31417 and t = u</programlisting>
31418 <simpara>However, SML/NJ expands <literal>withtype</literal> bindings sequentially, meaning that
31419 earlier bindings are expanded within later ones. Hence, the above
31420 program is expanded to the following.</simpara>
31421 <programlisting language="sml" linenumbering="unnumbered">type u = real ;
31422 datatype a =
31423 A of int
31424 | B of int ;
31425 type u = int
31426 type t = int</programlisting>
31427 </listitem>
31428 <listitem>
31429 <simpara>
31430 SML/NJ allows <literal>withtype</literal> specifications in signatures.
31431 </simpara>
31432 <simpara>MLton supports <literal>withtype</literal> specifications in signatures with the <link linkend="SuccessorML_SigWithtype"><literal>allowSigWithtype</literal></link> <link linkend="MLBasisAnnotations">ML Basis annotation</link>.</simpara>
31433 </listitem>
31434 <listitem>
31435 <simpara>
31436 SML/NJ allows a <literal>where</literal> structure specification that is similar to a
31437 <literal>where type</literal> specification. For example:
31438 </simpara>
31439 <programlisting language="sml" linenumbering="unnumbered">structure S = struct type t = int end
31440 signature SIG =
31441 sig
31442 structure T : sig type t end
31443 end where T = S</programlisting>
31444 <simpara>This is equivalent to:</simpara>
31445 <programlisting language="sml" linenumbering="unnumbered">structure S = struct type t = int end
31446 signature SIG =
31447 sig
31448 structure T : sig type t end
31449 end where type T.t = S.t</programlisting>
31450 <simpara>SML/NJ also allows a definitional structure specification that is
31451 similar to a definitional type specification. For example:</simpara>
31452 <programlisting language="sml" linenumbering="unnumbered">structure S = struct type t = int end
31453 signature SIG =
31454 sig
31455 structure T : sig type t end = S
31456 end</programlisting>
31457 <simpara>This is equivalent to the previous examples and to:</simpara>
31458 <programlisting language="sml" linenumbering="unnumbered">structure S = struct type t = int end
31459 signature SIG =
31460 sig
31461 structure T : sig type t end where type t = S.t
31462 end</programlisting>
31463 </listitem>
31464 <listitem>
31465 <simpara>
31466 SML/NJ disallows binding non-datatypes with datatype replication.
31467 For example, it rejects the following program that should be allowed
31468 according to the Definition.
31469 </simpara>
31470 <programlisting language="sml" linenumbering="unnumbered">type ('a, 'b) t = 'a * 'b
31471 datatype u = datatype t</programlisting>
31472 <simpara>This idiom can be useful when one wants to rename a type without
31473 rewriting all the type arguments. For example, the above would have
31474 to be written in SML/NJ as follows.</simpara>
31475 <programlisting language="sml" linenumbering="unnumbered">type ('a, 'b) t = 'a * 'b
31476 type ('a, 'b) u = ('a, 'b) t</programlisting>
31477 </listitem>
31478 <listitem>
31479 <simpara>
31480 SML/NJ disallows sharing a structure with one of its substructures.
31481 For example, SML/NJ disallows the following.
31482 </simpara>
31483 <programlisting language="sml" linenumbering="unnumbered">signature SIG =
31484 sig
31485 structure S:
31486 sig
31487 type t
31488 structure T: sig type t end
31489 end
31490 sharing S = S.T
31491 end</programlisting>
31492 <simpara>This signature is allowed by the Definition.</simpara>
31493 </listitem>
31494 <listitem>
31495 <simpara>
31496 SML/NJ disallows polymorphic generalization of refutable
31497 patterns. For example, SML/NJ disallows the following.
31498 </simpara>
31499 <programlisting language="sml" linenumbering="unnumbered">val [x] = [[]]
31500 val _ = (1 :: x, "one" :: x)</programlisting>
31501 <simpara>Recent versions of SML/NJ correctly allow polymorphic generalization
31502 of refutable patterns.</simpara>
31503 </listitem>
31504 <listitem>
31505 <simpara>
31506 SML/NJ uses an overly restrictive context for type inference. For
31507 example, SML/NJ rejects both of the following.
31508 </simpara>
31509 <programlisting language="sml" linenumbering="unnumbered">structure S =
31510 struct
31511 val z = (fn x =&gt; x) []
31512 val y = z :: [true] :: nil
31513 end</programlisting>
31514 <programlisting language="sml" linenumbering="unnumbered">structure S : sig val z : bool list end =
31515 struct
31516 val z = (fn x =&gt; x) []
31517 end</programlisting>
31518 <simpara>These structures are allowed by the Definition.</simpara>
31519 </listitem>
31520 </itemizedlist>
31521 <section id="_deviations_from_the_basis_library_specification">
31522 <title>Deviations from the Basis Library Specification</title>
31523 <simpara>Here are some deviations of SML/NJ from the <link linkend="BasisLibrary">Basis Library</link>
31524 <ulink url="http://www.standardml.org/Basis">specification</ulink>.</simpara>
31525 <itemizedlist>
31526 <listitem>
31527 <simpara>
31528 SML/NJ exposes the equality of the <literal>vector</literal> type in structures such
31529 as <literal>Word8Vector</literal> that abstractly match <literal>MONO_VECTOR</literal>, which says
31530 <literal>type vector</literal>, not <literal>eqtype vector</literal>. So, for example, SML/NJ accepts
31531 the following program:
31532 </simpara>
31533 <programlisting language="sml" linenumbering="unnumbered">fun f (v: Word8Vector.vector) = v = v</programlisting>
31534 </listitem>
31535 <listitem>
31536 <simpara>
31537 SML/NJ exposes the equality property of the type <literal>status</literal> in
31538 <literal>OS.Process</literal>. This means that programs which directly compare two
31539 values of type <literal>status</literal> will work with SML/NJ but not MLton.
31540 </simpara>
31541 </listitem>
31542 <listitem>
31543 <simpara>
31544 Under SML/NJ on Windows, <literal>OS.Path.validVolume</literal> incorrectly considers
31545 absolute empty volumes to be valid. In other words, when the
31546 expression
31547 </simpara>
31548 <programlisting language="sml" linenumbering="unnumbered">OS.Path.validVolume { isAbs = true, vol = "" }</programlisting>
31549 <simpara>is evaluated by SML/NJ on Windows, the result is <literal>true</literal>. MLton, on
31550 the other hand, correctly follows the Basis Library Specification,
31551 which states that on Windows, <literal>OS.Path.validVolume</literal> should return
31552 <literal>false</literal> whenever <literal>isAbs = true</literal> and <literal>vol = ""</literal>.</simpara>
31553 <simpara>This incorrect behavior causes other <literal>OS.Path</literal> functions to behave
31554 differently. For example, when the expression</simpara>
31555 <programlisting language="sml" linenumbering="unnumbered">OS.Path.toString (OS.Path.fromString "\\usr\\local")</programlisting>
31556 <simpara>is evaluated by SML/NJ on Windows, the result is <literal>"\\usr\\local"</literal>,
31557 whereas under MLton on Windows, evaluating this expression (correctly)
31558 causes an <literal>OS.Path.Path</literal> exception to be raised.</simpara>
31559 </listitem>
31560 </itemizedlist>
31561 <simpara><?asciidoc-pagebreak?></simpara>
31562 </section>
31563 </section>
31564 <section id="SMLNJLibrary">
31565 <title>SMLNJLibrary</title>
31566 <simpara>The <ulink url="http://www.smlnj.org/doc/smlnj-lib/index.html">SML/NJ Library</ulink> is a
31567 collection of libraries that are distributed with SML/NJ. Due to
31568 differences between SML/NJ and MLton, these libraries will not work
31569 out-of-the box with MLton.</simpara>
31570 <simpara>As of 20180119, MLton includes a port of the SML/NJ Library
31571 synchronized with SML/NJ version 110.82.</simpara>
31572 <section id="_usage_8">
31573 <title>Usage</title>
31574 <itemizedlist>
31575 <listitem>
31576 <simpara>
31577 You can import a sub-library of the SML/NJ Library into an MLB file with:
31578 </simpara>
31579 <informaltable
31580 frame="all"
31581 rowsep="1" colsep="1"
31582 >
31583 <tgroup cols="2">
31584 <colspec colname="col_1" colwidth="50*"/>
31585 <colspec colname="col_2" colwidth="50*"/>
31586 <thead>
31587 <row>
31588 <entry align="left" valign="top">MLB file</entry>
31589 <entry align="left" valign="top">Description</entry>
31590 </row>
31591 </thead>
31592 <tbody>
31593 <row>
31594 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/Util/smlnj-lib.mlb</literal></simpara></entry>
31595 <entry align="left" valign="top"><simpara>Various utility modules, included collections, simple formating, &#8230;</simpara></entry>
31596 </row>
31597 <row>
31598 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/Controls/controls-lib.mlb</literal></simpara></entry>
31599 <entry align="left" valign="top"><simpara>A library for managing control flags in an application.</simpara></entry>
31600 </row>
31601 <row>
31602 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/HashCons/hash-cons-lib.mlb</literal></simpara></entry>
31603 <entry align="left" valign="top"><simpara>Support for implementing hash-consed data structures.</simpara></entry>
31604 </row>
31605 <row>
31606 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/HTML/html-lib.mlb</literal></simpara></entry>
31607 <entry align="left" valign="top"><simpara>HTML 3.2 parsing and pretty-printing library.</simpara></entry>
31608 </row>
31609 <row>
31610 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/HTML4/html4-lib.mlb</literal></simpara></entry>
31611 <entry align="left" valign="top"><simpara>HTML 4.01 parsing and pretty-printing library.</simpara></entry>
31612 </row>
31613 <row>
31614 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/INet/inet-lib.mlb</literal></simpara></entry>
31615 <entry align="left" valign="top"><simpara>Networking utilities; supported on both Unix and Windows systems.</simpara></entry>
31616 </row>
31617 <row>
31618 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/JSON/json-lib.mlb</literal></simpara></entry>
31619 <entry align="left" valign="top"><simpara>JavaScript Object Notation (JSON) reading and writing library.</simpara></entry>
31620 </row>
31621 <row>
31622 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/PP/pp-lib.mlb</literal></simpara></entry>
31623 <entry align="left" valign="top"><simpara>Pretty-printing library.</simpara></entry>
31624 </row>
31625 <row>
31626 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/Reactive/reactive-lib.mlb</literal></simpara></entry>
31627 <entry align="left" valign="top"><simpara>Reactive scripting library.</simpara></entry>
31628 </row>
31629 <row>
31630 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/RegExp/regexp-lib.mlb</literal></simpara></entry>
31631 <entry align="left" valign="top"><simpara>Regular expression library.</simpara></entry>
31632 </row>
31633 <row>
31634 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/SExp/sexp-lib.mlb</literal></simpara></entry>
31635 <entry align="left" valign="top"><simpara>S-expression library.</simpara></entry>
31636 </row>
31637 <row>
31638 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/Unix/unix-lib.mlb</literal></simpara></entry>
31639 <entry align="left" valign="top"><simpara>Utilities for Unix-based operating systems.</simpara></entry>
31640 </row>
31641 <row>
31642 <entry align="left" valign="top"><simpara><literal>$(SML_LIB)/smlnj-lib/XML/xml-lib.mlb</literal></simpara></entry>
31643 <entry align="left" valign="top"><simpara>XML library.</simpara></entry>
31644 </row>
31645 </tbody>
31646 </tgroup>
31647 </informaltable>
31648 </listitem>
31649 <listitem>
31650 <simpara>
31651 If you are porting a project from SML/NJ&#8217;s <link linkend="CompilationManager">CompilationManager</link> to
31652 MLton&#8217;s <link linkend="MLBasis">ML Basis system</link> using <literal>cm2mlb</literal>, note that the
31653 following maps are included by default:
31654 </simpara>
31655 <screen># SMLNJ Library
31656 $SMLNJ-LIB $(SML_LIB)/smlnj-lib
31657 $smlnj-lib.cm $(SML_LIB)/smlnj-lib/Util
31658 $controls-lib.cm $(SML_LIB)/smlnj-lib/Controls
31659 $hash-cons-lib.cm $(SML_LIB)/smlnj-lib/HashCons
31660 $html-lib.cm $(SML_LIB)/smlnj-lib/HTML
31661 $html4-lib.cm $(SML_LIB)/smlnj-lib/HTML4
31662 $inet-lib.cm $(SML_LIB)/smlnj-lib/INet
31663 $json-lib.cm $(SML_LIB)/smlnj-lib/JSON
31664 $pp-lib.cm $(SML_LIB)/smlnj-lib/PP
31665 $reactive-lib.cm $(SML_LIB)/smlnj-lib/Reactive
31666 $regexp-lib.cm $(SML_LIB)/smlnj-lib/RegExp
31667 $sexp-lib.cm $(SML_LIB)/smlnj-lib/SExp
31668 $unix-lib.cm $(SML_LIB)/smlnj-lib/Unix
31669 $xml-lib.cm $(SML_LIB)/smlnj-lib/XML</screen>
31670 <simpara>This will automatically convert a <literal>$/smlnj-lib.cm</literal> import in an input
31671 <literal>.cm</literal> file into a <literal>$(SML_LIB)/smlnj-lib/Util/smlnj-lib.mlb</literal> import in
31672 the output <literal>.mlb</literal> file.</simpara>
31673 </listitem>
31674 </itemizedlist>
31675 </section>
31676 <section id="_details_4">
31677 <title>Details</title>
31678 <simpara>The following changes were made to the SML/NJ Library, in addition to
31679 deriving the <literal>.mlb</literal> files from the <literal>.cm</literal> files:</simpara>
31680 <itemizedlist>
31681 <listitem>
31682 <simpara>
31683 <literal>HTML4/pp-init.sml</literal> (added): Implements <literal>structure PrettyPrint</literal> using the SML/NJ PP Library. This implementation is taken from the SML/NJ compiler source, since the SML/NJ HTML4 Library used the <literal>structure PrettyPrint</literal> provided by the SML/NJ compiler itself.
31684 </simpara>
31685 </listitem>
31686 <listitem>
31687 <simpara>
31688 <literal>Util/base64.sml</literal> (modified): Rewrote use of <literal>Unsafe.CharVector.create</literal> and <literal>Unsafe.CharVector.update</literal>; MLton assumes that vectors are immutable.
31689 </simpara>
31690 </listitem>
31691 <listitem>
31692 <simpara>
31693 <literal>Util/engine.mlton.sml</literal> (added, not exported): Implements <literal>structure Engine</literal>, providing time-limited, resumable computations using <link linkend="MLtonThread">MLtonThread</link>, <link linkend="MLtonSignal">MLtonSignal</link>, and <link linkend="MLtonItimer">MLtonItimer</link>.
31694 </simpara>
31695 </listitem>
31696 <listitem>
31697 <simpara>
31698 <literal>Util/graph-scc-fn.sml</literal> (modified): Rewrote use of <literal>where</literal> structure specification.
31699 </simpara>
31700 </listitem>
31701 <listitem>
31702 <simpara>
31703 <literal>Util/redblack-map-fn.sml</literal> (modified): Rewrote use of <literal>where</literal> structure specification.
31704 </simpara>
31705 </listitem>
31706 <listitem>
31707 <simpara>
31708 <literal>Util/redblack-set-fn.sml</literal> (modified): Rewrote use of <literal>where</literal> structure specification.
31709 </simpara>
31710 </listitem>
31711 <listitem>
31712 <simpara>
31713 <literal>Util/time-limit.mlb</literal> (added): Exports <literal>structure TimeLimit</literal>, which is <emphasis>not</emphasis> exported by <literal>smlnj-lib.mlb</literal>. Since MLton is very conservative in the presence of threads and signals, program performance may be adversely affected by unnecessarily including <literal>structure TimeLimit</literal>.
31714 </simpara>
31715 </listitem>
31716 <listitem>
31717 <simpara>
31718 <literal>Util/time-limit.mlton.sml</literal> (added): Implements <literal>structure TimeLimit</literal> using <literal>structure Engine</literal>. The SML/NJ implementation of <literal>structure TimeLimit</literal> uses SML/NJ&#8217;s first-class continuations, signals, and interval timer.
31719 </simpara>
31720 </listitem>
31721 </itemizedlist>
31722 </section>
31723 <section id="_patch_4">
31724 <title>Patch</title>
31725 <itemizedlist>
31726 <listitem>
31727 <simpara>
31728 <ulink url="https://github.com/MLton/mlton/blob/master/lib/smlnj-lib/smlnj-lib.patch"><literal>smlnj-lib.patch</literal></ulink>
31729 </simpara>
31730 </listitem>
31731 </itemizedlist>
31732 <simpara><?asciidoc-pagebreak?></simpara>
31733 </section>
31734 </section>
31735 <section id="SMLofNJStructure">
31736 <title>SMLofNJStructure</title>
31737 <programlisting language="sml" linenumbering="unnumbered">signature SML_OF_NJ =
31738 sig
31739 structure Cont:
31740 sig
31741 type 'a cont
31742 val callcc: ('a cont -&gt; 'a) -&gt; 'a
31743 val isolate: ('a -&gt; unit) -&gt; 'a cont
31744 val throw: 'a cont -&gt; 'a -&gt; 'b
31745 end
31746 structure SysInfo:
31747 sig
31748 exception UNKNOWN
31749 datatype os_kind = BEOS | MACOS | OS2 | UNIX | WIN32
31750
31751 val getHostArch: unit -&gt; string
31752 val getOSKind: unit -&gt; os_kind
31753 val getOSName: unit -&gt; string
31754 end
31755
31756 val exnHistory: exn -&gt; string list
31757 val exportFn: string * (string * string list -&gt; OS.Process.status) -&gt; unit
31758 val exportML: string -&gt; bool
31759 val getAllArgs: unit -&gt; string list
31760 val getArgs: unit -&gt; string list
31761 val getCmdName: unit -&gt; string
31762 end</programlisting>
31763 <simpara><literal>SMLofNJ</literal> implements a subset of the structure of the same name
31764 provided in <link linkend="SMLNJ">Standard ML of New Jersey</link>. It is included to
31765 make it easier to port programs between the two systems. The
31766 semantics of these functions may be different than in SML/NJ.</simpara>
31767 <itemizedlist>
31768 <listitem>
31769 <simpara>
31770 <literal>structure Cont</literal>
31771 </simpara>
31772 <simpara>implements continuations.</simpara>
31773 </listitem>
31774 <listitem>
31775 <simpara>
31776 <literal>SysInfo.getHostArch ()</literal>
31777 </simpara>
31778 <simpara>returns the string for the architecture.</simpara>
31779 </listitem>
31780 <listitem>
31781 <simpara>
31782 <literal>SysInfo.getOSKind</literal>
31783 </simpara>
31784 <simpara>returns the OS kind.</simpara>
31785 </listitem>
31786 <listitem>
31787 <simpara>
31788 <literal>SysInfo.getOSName ()</literal>
31789 </simpara>
31790 <simpara>returns the string for the host.</simpara>
31791 </listitem>
31792 <listitem>
31793 <simpara>
31794 <literal>exnHistory</literal>
31795 </simpara>
31796 <simpara>the same as <literal>MLton.Exn.history</literal>.</simpara>
31797 </listitem>
31798 <listitem>
31799 <simpara>
31800 <literal>getCmdName ()</literal>
31801 </simpara>
31802 <simpara>the same as <literal>CommandLine.name ()</literal>.</simpara>
31803 </listitem>
31804 <listitem>
31805 <simpara>
31806 <literal>getArgs ()</literal>
31807 </simpara>
31808 <simpara>the same as <literal>CommandLine.arguments ()</literal>.</simpara>
31809 </listitem>
31810 <listitem>
31811 <simpara>
31812 <literal>getAllArgs ()</literal>
31813 </simpara>
31814 <simpara>the same as <literal>getCmdName()::getArgs()</literal>.</simpara>
31815 </listitem>
31816 <listitem>
31817 <simpara>
31818 <literal>exportFn f</literal>
31819 </simpara>
31820 <simpara>saves the state of the computation to a file that will apply <literal>f</literal> to
31821 the command-line arguments upon restart.</simpara>
31822 </listitem>
31823 <listitem>
31824 <simpara>
31825 <literal>exportML f</literal>
31826 </simpara>
31827 <simpara>saves the state of the computation to file <literal>f</literal> and continue. Returns
31828 <literal>true</literal> in the restarted computation and <literal>false</literal> in the continuing
31829 computation.</simpara>
31830 </listitem>
31831 </itemizedlist>
31832 <simpara><?asciidoc-pagebreak?></simpara>
31833 </section>
31834 <section id="SMLSharp">
31835 <title>SMLSharp</title>
31836 <simpara><ulink url="http://www.pllab.riec.tohoku.ac.jp/smlsharp/">SML#</ulink> is an
31837 <link linkend="StandardMLImplementations">implementation</link> of an extension of SML.</simpara>
31838 <simpara>It includes some
31839 <ulink url="http://www.pllab.riec.tohoku.ac.jp/smlsharp/?Tools">generally useful SML tools</ulink>
31840 including a pretty printer generator, a document generator, and a
31841 regression testing framework, and
31842 <ulink url="http://www.pllab.riec.tohoku.ac.jp/smlsharp/?Library%2FScripting">scripting library</ulink>.</simpara>
31843 <simpara><?asciidoc-pagebreak?></simpara>
31844 </section>
31845 <section id="Sources">
31846 <title>Sources</title>
31847 <simpara>We maintain our sources with <link linkend="Git">Git</link>. You can
31848 <ulink url="https://github.com/MLton/mlton/">view them on the web</ulink> or access
31849 them with a git client.</simpara>
31850 <simpara>Anonymous read-only access is available via</simpara>
31851 <screen>https://github.com/MLton/mlton.git</screen>
31852 <simpara>or</simpara>
31853 <screen>git://github.com/MLton/mlton.git</screen>
31854 <section id="_commit_email">
31855 <title>Commit email</title>
31856 <simpara>All commits are sent to
31857 <ulink url="mailto:MLton-commit@mlton.org"><literal>MLton-commit@mlton.org</literal></ulink>
31858 (<ulink url="https://lists.sourceforge.net/lists/listinfo/mlton-commit">subscribe</ulink>,
31859 <ulink url="https://sourceforge.net/mailarchive/forum.php?forum_name=mlton-commit">archive</ulink>,
31860 <ulink url="http://www.mlton.org/pipermail/mlton-commit/">archive</ulink>) which is a
31861 read-only mailing list for commit emails. Discussion should go to
31862 <ulink url="mailto:MLton-devel@mlton.org"><literal>MLton-devel@mlton.org</literal></ulink>.</simpara>
31863 </section>
31864 <section id="_changelog">
31865 <title>Changelog</title>
31866 <simpara>See <ulink url="https://github.com/MLton/mlton/blob/master/CHANGELOG.adoc"><literal>CHANGELOG.adoc</literal></ulink> for a list of
31867 changes and bug fixes.</simpara>
31868 </section>
31869 <section id="_subversion">
31870 <title>Subversion</title>
31871 <simpara>Prior to 20130308, we used <link linkend="Subversion">Subversion</link>.</simpara>
31872 </section>
31873 <section id="_cvs">
31874 <title>CVS</title>
31875 <simpara>Prior to 20050730, we used <link linkend="CVS">CVS</link>.</simpara>
31876 <simpara><?asciidoc-pagebreak?></simpara>
31877 </section>
31878 </section>
31879 <section id="SpaceSafety">
31880 <title>SpaceSafety</title>
31881 <simpara>Informally, space safety is a property of a language implementation
31882 that asymptotically bounds the space used by a running program.</simpara>
31883 <section id="_also_see_44">
31884 <title>Also see</title>
31885 <itemizedlist>
31886 <listitem>
31887 <simpara>
31888 Chapter 12 of <link linkend="References_Appel92">Appel92</link>
31889 </simpara>
31890 </listitem>
31891 <listitem>
31892 <simpara>
31893 <link linkend="References_Clinger98">Clinger98</link>
31894 </simpara>
31895 </listitem>
31896 </itemizedlist>
31897 <simpara><?asciidoc-pagebreak?></simpara>
31898 </section>
31899 </section>
31900 <section id="SSA">
31901 <title>SSA</title>
31902 <simpara><link linkend="SSA">SSA</link> is an <link linkend="IntermediateLanguage">IntermediateLanguage</link>, translated from <link linkend="SXML">SXML</link> by
31903 <link linkend="ClosureConvert">ClosureConvert</link>, optimized by <link linkend="SSASimplify">SSASimplify</link>, and translated by
31904 <link linkend="ToSSA2">ToSSA2</link> to <link linkend="SSA2">SSA2</link>.</simpara>
31905 <section id="_description_57">
31906 <title>Description</title>
31907 <simpara><link linkend="SSA">SSA</link> is a <link linkend="FirstOrder">FirstOrder</link>, <link linkend="SimplyTyped">SimplyTyped</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>.
31908 It is the main <link linkend="IntermediateLanguage">IntermediateLanguage</link> used for optimizations.</simpara>
31909 <simpara>An <link linkend="SSA">SSA</link> program consists of a collection of datatype declarations,
31910 a sequence of global statements, and a collection of functions, along
31911 with a distinguished "main" function. Each function consists of a
31912 collection of basic blocks, where each basic block is a sequence of
31913 statements ending with some control transfer.</simpara>
31914 </section>
31915 <section id="_implementation_62">
31916 <title>Implementation</title>
31917 <itemizedlist>
31918 <listitem>
31919 <simpara>
31920 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ssa.sig"><literal>ssa.sig</literal></ulink>
31921 </simpara>
31922 </listitem>
31923 <listitem>
31924 <simpara>
31925 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ssa.fun"><literal>ssa.fun</literal></ulink>
31926 </simpara>
31927 </listitem>
31928 <listitem>
31929 <simpara>
31930 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ssa-tree.sig"><literal>ssa-tree.sig</literal></ulink>
31931 </simpara>
31932 </listitem>
31933 <listitem>
31934 <simpara>
31935 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ssa-tree.fun"><literal>ssa-tree.fun</literal></ulink>
31936 </simpara>
31937 </listitem>
31938 </itemizedlist>
31939 </section>
31940 <section id="_type_checking_5">
31941 <title>Type Checking</title>
31942 <simpara>Type checking (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/type-check.sig"><literal>type-check.sig</literal></ulink>,
31943 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/type-check.fun"><literal>type-check.fun</literal></ulink>) of a <link linkend="SSA">SSA</link> program
31944 verifies the following:</simpara>
31945 <itemizedlist>
31946 <listitem>
31947 <simpara>
31948 no duplicate definitions (tycons, cons, vars, labels, funcs)
31949 </simpara>
31950 </listitem>
31951 <listitem>
31952 <simpara>
31953 no out of scope references (tycons, cons, vars, labels, funcs)
31954 </simpara>
31955 </listitem>
31956 <listitem>
31957 <simpara>
31958 variable definitions dominate variable uses
31959 </simpara>
31960 </listitem>
31961 <listitem>
31962 <simpara>
31963 case transfers are exhaustive and irredundant
31964 </simpara>
31965 </listitem>
31966 <listitem>
31967 <simpara>
31968 <literal>Enter</literal>/<literal>Leave</literal> profile statements match
31969 </simpara>
31970 </listitem>
31971 <listitem>
31972 <simpara>
31973 "traditional" well-typedness
31974 </simpara>
31975 </listitem>
31976 </itemizedlist>
31977 </section>
31978 <section id="_details_and_notes_60">
31979 <title>Details and Notes</title>
31980 <simpara>SSA is an abbreviation for Static Single Assignment.</simpara>
31981 <simpara>For some initial design discussion, see the thread at:</simpara>
31982 <itemizedlist>
31983 <listitem>
31984 <simpara>
31985 <ulink url="http://mlton.org/pipermail/mlton/2001-August/019689.html">http://mlton.org/pipermail/mlton/2001-August/019689.html</ulink>
31986 </simpara>
31987 </listitem>
31988 </itemizedlist>
31989 <simpara>For some retrospectives, see the threads at:</simpara>
31990 <itemizedlist>
31991 <listitem>
31992 <simpara>
31993 <ulink url="http://mlton.org/pipermail/mlton/2003-January/023054.html">http://mlton.org/pipermail/mlton/2003-January/023054.html</ulink>
31994 </simpara>
31995 </listitem>
31996 <listitem>
31997 <simpara>
31998 <ulink url="http://mlton.org/pipermail/mlton/2007-February/029597.html">http://mlton.org/pipermail/mlton/2007-February/029597.html</ulink>
31999 </simpara>
32000 </listitem>
32001 </itemizedlist>
32002 <simpara><?asciidoc-pagebreak?></simpara>
32003 </section>
32004 </section>
32005 <section id="SSA2">
32006 <title>SSA2</title>
32007 <simpara><link linkend="SSA2">SSA2</link> is an <link linkend="IntermediateLanguage">IntermediateLanguage</link>, translated from <link linkend="SSA">SSA</link> by
32008 <link linkend="ToSSA2">ToSSA2</link>, optimized by <link linkend="SSA2Simplify">SSA2Simplify</link>, and translated by
32009 <link linkend="ToRSSA">ToRSSA</link> to <link linkend="RSSA">RSSA</link>.</simpara>
32010 <section id="_description_58">
32011 <title>Description</title>
32012 <simpara><link linkend="SSA2">SSA2</link> is a <link linkend="FirstOrder">FirstOrder</link>, <link linkend="SimplyTyped">SimplyTyped</link>
32013 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, a slight variant of the <link linkend="SSA">SSA</link>
32014 <link linkend="IntermediateLanguage">IntermediateLanguage</link>,</simpara>
32015 <simpara>Like <link linkend="SSA">SSA</link>, an <link linkend="SSA2">SSA2</link> program consists of a collection of datatype
32016 declarations, a sequence of global statements, and a collection of
32017 functions, along with a distinguished "main" function. Each function
32018 consists of a collection of basic blocks, where each basic block is a
32019 sequence of statements ending with some control transfer.</simpara>
32020 <simpara>Unlike <link linkend="SSA">SSA</link>, <link linkend="SSA2">SSA2</link> includes mutable fields in objects and makes
32021 the vector type constructor n-ary instead of unary. This allows
32022 optimizations like <link linkend="RefFlatten">RefFlatten</link> and <link linkend="DeepFlatten">DeepFlatten</link> to be expressed.</simpara>
32023 </section>
32024 <section id="_implementation_63">
32025 <title>Implementation</title>
32026 <itemizedlist>
32027 <listitem>
32028 <simpara>
32029 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ssa2.sig"><literal>ssa2.sig</literal></ulink>
32030 </simpara>
32031 </listitem>
32032 <listitem>
32033 <simpara>
32034 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ssa2.fun"><literal>ssa2.fun</literal></ulink>
32035 </simpara>
32036 </listitem>
32037 <listitem>
32038 <simpara>
32039 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ssa-tree2.sig"><literal>ssa-tree2.sig</literal></ulink>
32040 </simpara>
32041 </listitem>
32042 <listitem>
32043 <simpara>
32044 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ssa-tree2.fun"><literal>ssa-tree2.fun</literal></ulink>
32045 </simpara>
32046 </listitem>
32047 </itemizedlist>
32048 </section>
32049 <section id="_type_checking_6">
32050 <title>Type Checking</title>
32051 <simpara>Type checking (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/type-check2.sig"><literal>type-check2.sig</literal></ulink>,
32052 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/type-check2.fun"><literal>type-check2.fun</literal></ulink>) of a <link linkend="SSA2">SSA2</link>
32053 program verifies the following:</simpara>
32054 <itemizedlist>
32055 <listitem>
32056 <simpara>
32057 no duplicate definitions (tycons, cons, vars, labels, funcs)
32058 </simpara>
32059 </listitem>
32060 <listitem>
32061 <simpara>
32062 no out of scope references (tycons, cons, vars, labels, funcs)
32063 </simpara>
32064 </listitem>
32065 <listitem>
32066 <simpara>
32067 variable definitions dominate variable uses
32068 </simpara>
32069 </listitem>
32070 <listitem>
32071 <simpara>
32072 case transfers are exhaustive and irredundant
32073 </simpara>
32074 </listitem>
32075 <listitem>
32076 <simpara>
32077 <literal>Enter</literal>/<literal>Leave</literal> profile statements match
32078 </simpara>
32079 </listitem>
32080 <listitem>
32081 <simpara>
32082 "traditional" well-typedness
32083 </simpara>
32084 </listitem>
32085 </itemizedlist>
32086 </section>
32087 <section id="_details_and_notes_61">
32088 <title>Details and Notes</title>
32089 <simpara>SSA is an abbreviation for Static Single Assignment.</simpara>
32090 <simpara><?asciidoc-pagebreak?></simpara>
32091 </section>
32092 </section>
32093 <section id="SSA2Simplify">
32094 <title>SSA2Simplify</title>
32095 <simpara>The optimization passes for the <link linkend="SSA2">SSA2</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> are
32096 collected and controlled by the <literal>Simplify2</literal> functor
32097 (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/simplify2.sig"><literal>simplify2.sig</literal></ulink>,
32098 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/simplify2.fun"><literal>simplify2.fun</literal></ulink>).</simpara>
32099 <simpara>The following optimization passes are implemented:</simpara>
32100 <itemizedlist>
32101 <listitem>
32102 <simpara>
32103 <link linkend="DeepFlatten">DeepFlatten</link>
32104 </simpara>
32105 </listitem>
32106 <listitem>
32107 <simpara>
32108 <link linkend="RefFlatten">RefFlatten</link>
32109 </simpara>
32110 </listitem>
32111 <listitem>
32112 <simpara>
32113 <link linkend="RemoveUnused">RemoveUnused</link>
32114 </simpara>
32115 </listitem>
32116 <listitem>
32117 <simpara>
32118 <link linkend="Zone">Zone</link>
32119 </simpara>
32120 </listitem>
32121 </itemizedlist>
32122 <simpara>There are additional analysis and rewrite passes that augment many of the other optimization passes:</simpara>
32123 <itemizedlist>
32124 <listitem>
32125 <simpara>
32126 <link linkend="Restore">Restore</link>
32127 </simpara>
32128 </listitem>
32129 <listitem>
32130 <simpara>
32131 <link linkend="Shrink">Shrink</link>
32132 </simpara>
32133 </listitem>
32134 </itemizedlist>
32135 <simpara>The optimization passes can be controlled from the command-line by the options</simpara>
32136 <itemizedlist>
32137 <listitem>
32138 <simpara>
32139 <literal>-diag-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;keep diagnostic info for pass
32140 </simpara>
32141 </listitem>
32142 <listitem>
32143 <simpara>
32144 <literal>-disable-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;skip optimization pass (if normally performed)
32145 </simpara>
32146 </listitem>
32147 <listitem>
32148 <simpara>
32149 <literal>-enable-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;perform optimization pass (if normally skipped)
32150 </simpara>
32151 </listitem>
32152 <listitem>
32153 <simpara>
32154 <literal>-keep-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;keep the results of pass
32155 </simpara>
32156 </listitem>
32157 <listitem>
32158 <simpara>
32159 <literal>-loop-passes &lt;n&gt;</literal>&#8201;&#8212;&#8201;loop optimization passes
32160 </simpara>
32161 </listitem>
32162 <listitem>
32163 <simpara>
32164 <literal>-ssa2-passes &lt;passes&gt;</literal>&#8201;&#8212;&#8201;ssa optimization passes
32165 </simpara>
32166 </listitem>
32167 </itemizedlist>
32168 <simpara><?asciidoc-pagebreak?></simpara>
32169 </section>
32170 <section id="SSASimplify">
32171 <title>SSASimplify</title>
32172 <simpara>The optimization passes for the <link linkend="SSA">SSA</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> are
32173 collected and controlled by the <literal>Simplify</literal> functor
32174 (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/simplify.sig"><literal>simplify.sig</literal></ulink>,
32175 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/simplify.fun"><literal>simplify.fun</literal></ulink>).</simpara>
32176 <simpara>The following optimization passes are implemented:</simpara>
32177 <itemizedlist>
32178 <listitem>
32179 <simpara>
32180 <link linkend="CombineConversions">CombineConversions</link>
32181 </simpara>
32182 </listitem>
32183 <listitem>
32184 <simpara>
32185 <link linkend="CommonArg">CommonArg</link>
32186 </simpara>
32187 </listitem>
32188 <listitem>
32189 <simpara>
32190 <link linkend="CommonBlock">CommonBlock</link>
32191 </simpara>
32192 </listitem>
32193 <listitem>
32194 <simpara>
32195 <link linkend="CommonSubexp">CommonSubexp</link>
32196 </simpara>
32197 </listitem>
32198 <listitem>
32199 <simpara>
32200 <link linkend="ConstantPropagation">ConstantPropagation</link>
32201 </simpara>
32202 </listitem>
32203 <listitem>
32204 <simpara>
32205 <link linkend="Contify">Contify</link>
32206 </simpara>
32207 </listitem>
32208 <listitem>
32209 <simpara>
32210 <link linkend="Flatten">Flatten</link>
32211 </simpara>
32212 </listitem>
32213 <listitem>
32214 <simpara>
32215 <link linkend="Inline">Inline</link>
32216 </simpara>
32217 </listitem>
32218 <listitem>
32219 <simpara>
32220 <link linkend="IntroduceLoops">IntroduceLoops</link>
32221 </simpara>
32222 </listitem>
32223 <listitem>
32224 <simpara>
32225 <link linkend="KnownCase">KnownCase</link>
32226 </simpara>
32227 </listitem>
32228 <listitem>
32229 <simpara>
32230 <link linkend="LocalFlatten">LocalFlatten</link>
32231 </simpara>
32232 </listitem>
32233 <listitem>
32234 <simpara>
32235 <link linkend="LocalRef">LocalRef</link>
32236 </simpara>
32237 </listitem>
32238 <listitem>
32239 <simpara>
32240 <link linkend="LoopInvariant">LoopInvariant</link>
32241 </simpara>
32242 </listitem>
32243 <listitem>
32244 <simpara>
32245 <link linkend="LoopUnfoll">LoopUnfoll</link>
32246 </simpara>
32247 </listitem>
32248 <listitem>
32249 <simpara>
32250 <link linkend="LoopUnswitch">LoopUnswitch</link>
32251 </simpara>
32252 </listitem>
32253 <listitem>
32254 <simpara>
32255 <link linkend="Redundant">Redundant</link>
32256 </simpara>
32257 </listitem>
32258 <listitem>
32259 <simpara>
32260 <link linkend="RedundantTests">RedundantTests</link>
32261 </simpara>
32262 </listitem>
32263 <listitem>
32264 <simpara>
32265 <link linkend="RemoveUnused">RemoveUnused</link>
32266 </simpara>
32267 </listitem>
32268 <listitem>
32269 <simpara>
32270 <link linkend="ShareZeroVec">ShareZeroVec</link>
32271 </simpara>
32272 </listitem>
32273 <listitem>
32274 <simpara>
32275 <link linkend="SimplifyTypes">SimplifyTypes</link>
32276 </simpara>
32277 </listitem>
32278 <listitem>
32279 <simpara>
32280 <link linkend="Useless">Useless</link>
32281 </simpara>
32282 </listitem>
32283 </itemizedlist>
32284 <simpara>The following implementation passes are implemented:</simpara>
32285 <itemizedlist>
32286 <listitem>
32287 <simpara>
32288 <link linkend="PolyEqual">PolyEqual</link>
32289 </simpara>
32290 </listitem>
32291 <listitem>
32292 <simpara>
32293 <link linkend="PolyHash">PolyHash</link>
32294 </simpara>
32295 </listitem>
32296 </itemizedlist>
32297 <simpara>There are additional analysis and rewrite passes that augment many of the other optimization passes:</simpara>
32298 <itemizedlist>
32299 <listitem>
32300 <simpara>
32301 <link linkend="Multi">Multi</link>
32302 </simpara>
32303 </listitem>
32304 <listitem>
32305 <simpara>
32306 <link linkend="Restore">Restore</link>
32307 </simpara>
32308 </listitem>
32309 <listitem>
32310 <simpara>
32311 <link linkend="Shrink">Shrink</link>
32312 </simpara>
32313 </listitem>
32314 </itemizedlist>
32315 <simpara>The optimization passes can be controlled from the command-line by the options:</simpara>
32316 <itemizedlist>
32317 <listitem>
32318 <simpara>
32319 <literal>-diag-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;keep diagnostic info for pass
32320 </simpara>
32321 </listitem>
32322 <listitem>
32323 <simpara>
32324 <literal>-disable-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;skip optimization pass (if normally performed)
32325 </simpara>
32326 </listitem>
32327 <listitem>
32328 <simpara>
32329 <literal>-enable-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;perform optimization pass (if normally skipped)
32330 </simpara>
32331 </listitem>
32332 <listitem>
32333 <simpara>
32334 <literal>-keep-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;keep the results of pass
32335 </simpara>
32336 </listitem>
32337 <listitem>
32338 <simpara>
32339 <literal>-loop-passes &lt;n&gt;</literal>&#8201;&#8212;&#8201;loop optimization passes
32340 </simpara>
32341 </listitem>
32342 <listitem>
32343 <simpara>
32344 <literal>-ssa-passes &lt;passes&gt;</literal>&#8201;&#8212;&#8201;ssa optimization passes
32345 </simpara>
32346 </listitem>
32347 </itemizedlist>
32348 <simpara><?asciidoc-pagebreak?></simpara>
32349 </section>
32350 <section id="Stabilizers">
32351 <title>Stabilizers</title>
32352 <section id="_installation">
32353 <title>Installation</title>
32354 <itemizedlist>
32355 <listitem>
32356 <simpara>
32357 Stabilizers currently require the MLton sources, this should be fixed by the next release
32358 </simpara>
32359 </listitem>
32360 </itemizedlist>
32361 </section>
32362 <section id="_license">
32363 <title>License</title>
32364 <itemizedlist>
32365 <listitem>
32366 <simpara>
32367 Stabilizers are released under the MLton License
32368 </simpara>
32369 </listitem>
32370 </itemizedlist>
32371 </section>
32372 <section id="_instructions">
32373 <title>Instructions</title>
32374 <itemizedlist>
32375 <listitem>
32376 <simpara>
32377 Download and build a source copy of MLton
32378 </simpara>
32379 </listitem>
32380 <listitem>
32381 <simpara>
32382 Extract the tar.gz file attached to this page
32383 </simpara>
32384 </listitem>
32385 <listitem>
32386 <simpara>
32387 Some examples are provided in the "examples/" sub directory, more examples will be added to this page in the following week
32388 </simpara>
32389 </listitem>
32390 </itemizedlist>
32391 </section>
32392 <section id="_bug_reports_suggestions">
32393 <title>Bug reports / Suggestions</title>
32394 <itemizedlist>
32395 <listitem>
32396 <simpara>
32397 Please send any errors you encounter to schatzp and lziarek at cs.purdue.edu
32398 </simpara>
32399 </listitem>
32400 <listitem>
32401 <simpara>
32402 We are looking to expand the usability of stabilizers
32403 </simpara>
32404 </listitem>
32405 <listitem>
32406 <simpara>
32407 Please send any suggestions and desired functionality to the above email addresses
32408 </simpara>
32409 </listitem>
32410 </itemizedlist>
32411 </section>
32412 <section id="_note">
32413 <title>Note</title>
32414 <itemizedlist>
32415 <listitem>
32416 <simpara>
32417 This is an alpha release. We expect to have another release shortly with added functionality soon
32418 </simpara>
32419 </listitem>
32420 <listitem>
32421 <simpara>
32422 More documentation, such as signatures and descriptions of functionality, will be forthcoming
32423 </simpara>
32424 </listitem>
32425 </itemizedlist>
32426 </section>
32427 <section id="_documentation">
32428 <title>Documentation</title>
32429 <programlisting language="sml" linenumbering="unnumbered">signature STABLE =
32430 sig
32431 type checkpoint
32432
32433 val stable: ('a -&gt; 'b) -&gt; ('a -&gt; 'b)
32434 val stabilize: unit -&gt; 'a
32435
32436 val stableCP: (('a -&gt; 'b) * (unit -&gt; unit)) -&gt;
32437 (('a -&gt; 'b) * checkpoint)
32438 val stabilizeCP: checkpoint -&gt; unit
32439
32440 val unmonitoredAssign: ('a ref * 'a) -&gt; unit
32441 val monitoredAssign: ('a ref * 'a) -&gt; unit
32442 end</programlisting>
32443 <simpara><literal>Stable</literal> provides functions to manage stable sections.</simpara>
32444 <itemizedlist>
32445 <listitem>
32446 <simpara>
32447 <literal>type checkpoint</literal>
32448 </simpara>
32449 <simpara>handle used to stabilize contexts other than the current one.</simpara>
32450 </listitem>
32451 <listitem>
32452 <simpara>
32453 <literal>stable f</literal>
32454 </simpara>
32455 <simpara>returns a function identical to <literal>f</literal> that will execute within a stable section.</simpara>
32456 </listitem>
32457 <listitem>
32458 <simpara>
32459 <literal>stabilize ()</literal>
32460 </simpara>
32461 <simpara>unrolls the effects made up to the current context to at least the
32462 nearest enclosing <emphasis>stable</emphasis> section. These effects may have propagated
32463 to other threads, so all affected threads are returned to a globally
32464 consistent previous state. The return is undefined because control
32465 cannot resume after stabilize is called.</simpara>
32466 </listitem>
32467 <listitem>
32468 <simpara>
32469 <literal>stableCP (f, comp)</literal>
32470 </simpara>
32471 <simpara>returns a function <literal>f'</literal> and checkpoint tag <literal>cp</literal>. Function <literal>f'</literal> is
32472 identical to <literal>f</literal> but when applied will execute within a stable
32473 section. <literal>comp</literal> will be executed if <literal>f'</literal> is later stabilized. <literal>cp</literal>
32474 is used by <literal>stabilizeCP</literal> to stabilize a given checkpoint.</simpara>
32475 </listitem>
32476 <listitem>
32477 <simpara>
32478 <literal>stabilizeCP cp</literal>
32479 </simpara>
32480 <simpara>same as stabilize except that the (possibly current) checkpoint to
32481 stabilize is provided.</simpara>
32482 </listitem>
32483 <listitem>
32484 <simpara>
32485 <literal>unmonitoredAssign (r, v)</literal>
32486 </simpara>
32487 <simpara>standard assignment (<literal>:=</literal>). The version of CML distributed rebinds
32488 <literal>:=</literal> to a monitored version so interesting effects can be recorded.</simpara>
32489 </listitem>
32490 <listitem>
32491 <simpara>
32492 <literal>monitoredAssign (r, v)</literal>
32493 </simpara>
32494 <simpara>the assignment operator that should be used in programs that use
32495 stabilizers. <literal>:=</literal> is rebound to this by including CML.</simpara>
32496 </listitem>
32497 </itemizedlist>
32498 </section>
32499 <section id="_download_7">
32500 <title>Download</title>
32501 <itemizedlist>
32502 <listitem>
32503 <simpara>
32504 <ulink url="guide/Stabilizers.attachments/stabilizers_alpha_2006-10-09.tar.gz"><literal>stabilizers_alpha_2006-10-09.tar.gz</literal></ulink>
32505 </simpara>
32506 </listitem>
32507 </itemizedlist>
32508 </section>
32509 <section id="_also_see_45">
32510 <title>Also see</title>
32511 <itemizedlist>
32512 <listitem>
32513 <simpara>
32514 <link linkend="References_ZiarekEtAl06">ZiarekEtAl06</link>
32515 </simpara>
32516 </listitem>
32517 </itemizedlist>
32518 <simpara><?asciidoc-pagebreak?></simpara>
32519 </section>
32520 </section>
32521 <section id="StandardML">
32522 <title>StandardML</title>
32523 <simpara>Standard ML (SML) is a programming language that combines excellent
32524 support for rapid prototyping, modularity, and development of large
32525 programs, with performance approaching that of C.</simpara>
32526 <section id="_sml_resources">
32527 <title>SML Resources</title>
32528 <itemizedlist>
32529 <listitem>
32530 <simpara>
32531 <link linkend="StandardMLTutorials">Tutorials</link>
32532 </simpara>
32533 </listitem>
32534 <listitem>
32535 <simpara>
32536 <link linkend="StandardMLBooks">Books</link>
32537 </simpara>
32538 </listitem>
32539 <listitem>
32540 <simpara>
32541 <link linkend="StandardMLImplementations">Implementations</link>
32542 </simpara>
32543 </listitem>
32544 </itemizedlist>
32545 </section>
32546 <section id="_aspects_of_sml">
32547 <title>Aspects of SML</title>
32548 <itemizedlist>
32549 <listitem>
32550 <simpara>
32551 <link linkend="DefineTypeBeforeUse">DefineTypeBeforeUse</link>
32552 </simpara>
32553 </listitem>
32554 <listitem>
32555 <simpara>
32556 <link linkend="EqualityType">EqualityType</link>
32557 </simpara>
32558 </listitem>
32559 <listitem>
32560 <simpara>
32561 <link linkend="EqualityTypeVariable">EqualityTypeVariable</link>
32562 </simpara>
32563 </listitem>
32564 <listitem>
32565 <simpara>
32566 <link linkend="GenerativeDatatype">GenerativeDatatype</link>
32567 </simpara>
32568 </listitem>
32569 <listitem>
32570 <simpara>
32571 <link linkend="GenerativeException">GenerativeException</link>
32572 </simpara>
32573 </listitem>
32574 <listitem>
32575 <simpara>
32576 <link linkend="Identifier">Identifier</link>
32577 </simpara>
32578 </listitem>
32579 <listitem>
32580 <simpara>
32581 <link linkend="OperatorPrecedence">OperatorPrecedence</link>
32582 </simpara>
32583 </listitem>
32584 <listitem>
32585 <simpara>
32586 <link linkend="Overloading">Overloading</link>
32587 </simpara>
32588 </listitem>
32589 <listitem>
32590 <simpara>
32591 <link linkend="PolymorphicEquality">PolymorphicEquality</link>
32592 </simpara>
32593 </listitem>
32594 <listitem>
32595 <simpara>
32596 <link linkend="TypeVariableScope">TypeVariableScope</link>
32597 </simpara>
32598 </listitem>
32599 <listitem>
32600 <simpara>
32601 <link linkend="ValueRestriction">ValueRestriction</link>
32602 </simpara>
32603 </listitem>
32604 </itemizedlist>
32605 </section>
32606 <section id="_using_sml">
32607 <title>Using SML</title>
32608 <itemizedlist>
32609 <listitem>
32610 <simpara>
32611 <link linkend="Fixpoints">Fixpoints</link>
32612 </simpara>
32613 </listitem>
32614 <listitem>
32615 <simpara>
32616 <link linkend="ForLoops">ForLoops</link>
32617 </simpara>
32618 </listitem>
32619 <listitem>
32620 <simpara>
32621 <link linkend="FunctionalRecordUpdate">FunctionalRecordUpdate</link>
32622 </simpara>
32623 </listitem>
32624 <listitem>
32625 <simpara>
32626 <link linkend="InfixingOperators">InfixingOperators</link>
32627 </simpara>
32628 </listitem>
32629 <listitem>
32630 <simpara>
32631 <link linkend="Lazy">Lazy</link>
32632 </simpara>
32633 </listitem>
32634 <listitem>
32635 <simpara>
32636 <link linkend="ObjectOrientedProgramming">ObjectOrientedProgramming</link>
32637 </simpara>
32638 </listitem>
32639 <listitem>
32640 <simpara>
32641 <link linkend="OptionalArguments">OptionalArguments</link>
32642 </simpara>
32643 </listitem>
32644 <listitem>
32645 <simpara>
32646 <link linkend="Printf">Printf</link>
32647 </simpara>
32648 </listitem>
32649 <listitem>
32650 <simpara>
32651 <link linkend="PropertyList">PropertyList</link>
32652 </simpara>
32653 </listitem>
32654 <listitem>
32655 <simpara>
32656 <link linkend="ReturnStatement">ReturnStatement</link>
32657 </simpara>
32658 </listitem>
32659 <listitem>
32660 <simpara>
32661 <link linkend="Serialization">Serialization</link>
32662 </simpara>
32663 </listitem>
32664 <listitem>
32665 <simpara>
32666 <link linkend="StandardMLGotchas">StandardMLGotchas</link>
32667 </simpara>
32668 </listitem>
32669 <listitem>
32670 <simpara>
32671 <link linkend="StyleGuide">StyleGuide</link>
32672 </simpara>
32673 </listitem>
32674 <listitem>
32675 <simpara>
32676 <link linkend="TipsForWritingConciseSML">TipsForWritingConciseSML</link>
32677 </simpara>
32678 </listitem>
32679 <listitem>
32680 <simpara>
32681 <link linkend="UniversalType">UniversalType</link>
32682 </simpara>
32683 </listitem>
32684 </itemizedlist>
32685 </section>
32686 <section id="_programming_in_sml">
32687 <title>Programming in SML</title>
32688 <itemizedlist>
32689 <listitem>
32690 <simpara>
32691 <link linkend="Emacs">Emacs</link>
32692 </simpara>
32693 </listitem>
32694 <listitem>
32695 <simpara>
32696 <link linkend="Enscript">Enscript</link>
32697 </simpara>
32698 </listitem>
32699 <listitem>
32700 <simpara>
32701 <link linkend="Pygments">Pygments</link>
32702 </simpara>
32703 </listitem>
32704 </itemizedlist>
32705 </section>
32706 <section id="_notes_18">
32707 <title>Notes</title>
32708 <itemizedlist>
32709 <listitem>
32710 <simpara>
32711 <link linkend="StandardMLHistory">History of SML</link>
32712 </simpara>
32713 </listitem>
32714 <listitem>
32715 <simpara>
32716 <link linkend="Regions">Regions</link>
32717 </simpara>
32718 </listitem>
32719 </itemizedlist>
32720 </section>
32721 <section id="_related_languages">
32722 <title>Related Languages</title>
32723 <itemizedlist>
32724 <listitem>
32725 <simpara>
32726 <link linkend="Alice">Alice</link>
32727 </simpara>
32728 </listitem>
32729 <listitem>
32730 <simpara>
32731 <link linkend="FSharp">F#</link>
32732 </simpara>
32733 </listitem>
32734 <listitem>
32735 <simpara>
32736 <link linkend="OCaml">OCaml</link>
32737 </simpara>
32738 </listitem>
32739 </itemizedlist>
32740 <simpara><?asciidoc-pagebreak?></simpara>
32741 </section>
32742 </section>
32743 <section id="StandardMLBooks">
32744 <title>StandardMLBooks</title>
32745 <section id="_introductory_books">
32746 <title>Introductory Books</title>
32747 <itemizedlist>
32748 <listitem>
32749 <simpara>
32750 <link linkend="References_Ullman98">Elements of ML Programming</link>
32751 </simpara>
32752 </listitem>
32753 <listitem>
32754 <simpara>
32755 <link linkend="References_Paulson96">ML For the Working Programmer</link>
32756 </simpara>
32757 </listitem>
32758 <listitem>
32759 <simpara>
32760 <link linkend="References_HansenRichel99">Introduction to Programming using SML</link>
32761 </simpara>
32762 </listitem>
32763 <listitem>
32764 <simpara>
32765 <link linkend="References_FelleisenFreidman98">The Little MLer</link>
32766 </simpara>
32767 </listitem>
32768 </itemizedlist>
32769 </section>
32770 <section id="_applications_3">
32771 <title>Applications</title>
32772 <itemizedlist>
32773 <listitem>
32774 <simpara>
32775 <link linkend="References_Shipman02">Unix System Programming with Standard ML</link>
32776 </simpara>
32777 </listitem>
32778 </itemizedlist>
32779 </section>
32780 <section id="_reference_books">
32781 <title>Reference Books</title>
32782 <itemizedlist>
32783 <listitem>
32784 <simpara>
32785 <link linkend="References_GansnerReppy04">The Standard ML Basis Library</link>
32786 </simpara>
32787 </listitem>
32788 <listitem>
32789 <simpara>
32790 <link linkend="DefinitionOfStandardML">The Definition of Standard ML (Revised)</link>
32791 </simpara>
32792 </listitem>
32793 </itemizedlist>
32794 </section>
32795 <section id="_related_topics">
32796 <title>Related Topics</title>
32797 <itemizedlist>
32798 <listitem>
32799 <simpara>
32800 <link linkend="References_Reppy07">Concurrent Programming in ML</link>
32801 </simpara>
32802 </listitem>
32803 <listitem>
32804 <simpara>
32805 <link linkend="References_Okasaki99">Purely Functional Data Structures</link>
32806 </simpara>
32807 </listitem>
32808 </itemizedlist>
32809 <simpara><?asciidoc-pagebreak?></simpara>
32810 </section>
32811 </section>
32812 <section id="StandardMLGotchas">
32813 <title>StandardMLGotchas</title>
32814 <simpara>This page contains brief explanations of some recurring sources of
32815 confusion and problems that SML newbies encounter.</simpara>
32816 <simpara>Many confusions about the syntax of SML seem to arise from the use of
32817 an interactive REPL (Read-Eval Print Loop) while trying to learn the
32818 basics of the language. While writing your first SML programs, you
32819 should keep the source code of your programs in a form that is
32820 accepted by an SML compiler as a whole.</simpara>
32821 <section id="_the_literal_and_literal_keyword">
32822 <title>The <literal>and</literal> keyword</title>
32823 <simpara>It is a common mistake to misuse the <literal>and</literal> keyword or to not know how
32824 to introduce mutually recursive definitions. The purpose of the <literal>and</literal>
32825 keyword is to introduce mutually recursive definitions of functions
32826 and datatypes. For example,</simpara>
32827 <programlisting language="sml" linenumbering="unnumbered">fun isEven 0w0 = true
32828 | isEven 0w1 = false
32829 | isEven n = isOdd (n-0w1)
32830 and isOdd 0w0 = false
32831 | isOdd 0w1 = true
32832 | isOdd n = isEven (n-0w1)</programlisting>
32833 <simpara>and</simpara>
32834 <programlisting language="sml" linenumbering="unnumbered">datatype decl = VAL of id * pat * expr
32835 (* | ... *)
32836 and expr = LET of decl * expr
32837 (* | ... *)</programlisting>
32838 <simpara>You can also use <literal>and</literal> as a shorthand in a couple of other places, but
32839 it is not necessary.</simpara>
32840 </section>
32841 <section id="_constructed_patterns">
32842 <title>Constructed patterns</title>
32843 <simpara>It is a common mistake to forget to parenthesize constructed patterns
32844 in <literal>fun</literal> bindings. Consider the following invalid definition:</simpara>
32845 <programlisting language="sml" linenumbering="unnumbered">fun length nil = 0
32846 | length h :: t = 1 + length t</programlisting>
32847 <variablelist>
32848 <varlistentry>
32849 <term>
32850 The pattern `h
32851 </term>
32852 <listitem>
32853 <simpara>
32854 t` needs to be parenthesized:
32855 </simpara>
32856 </listitem>
32857 </varlistentry>
32858 </variablelist>
32859 <programlisting language="sml" linenumbering="unnumbered">fun length nil = 0
32860 | length (h :: t) = 1 + length t</programlisting>
32861 <simpara>The parentheses are needed, because a <literal>fun</literal> definition may have
32862 multiple consecutive constructed patterns through currying.</simpara>
32863 <simpara>The same applies to nonfix constructors. For example, the parentheses
32864 in</simpara>
32865 <programlisting language="sml" linenumbering="unnumbered">fun valOf NONE = raise Option
32866 | valOf (SOME x) = x</programlisting>
32867 <simpara>are required. However, the outermost constructed pattern in a <literal>fn</literal> or
32868 <literal>case</literal> expression need not be parenthesized, because in those cases
32869 there is always just one constructed pattern. So, both</simpara>
32870 <programlisting language="sml" linenumbering="unnumbered">val valOf = fn NONE =&gt; raise Option
32871 | SOME x =&gt; x</programlisting>
32872 <simpara>and</simpara>
32873 <programlisting language="sml" linenumbering="unnumbered">fun valOf x = case x of
32874 NONE =&gt; raise Option
32875 | SOME x =&gt; x</programlisting>
32876 <simpara>are fine.</simpara>
32877 </section>
32878 <section id="_declarations_and_expressions">
32879 <title>Declarations and expressions</title>
32880 <simpara>It is a common mistake to confuse expressions and declarations.
32881 Normally an SML source file should only contain declarations. The
32882 following are declarations:</simpara>
32883 <programlisting language="sml" linenumbering="unnumbered">datatype dt = ...
32884 fun f ... = ...
32885 functor Fn (...) = ...
32886 infix ...
32887 infixr ...
32888 local ... in ... end
32889 nonfix ...
32890 open ...
32891 signature SIG = ...
32892 structure Struct = ...
32893 type t = ...
32894 val v = ...</programlisting>
32895 <simpara>Note that</simpara>
32896 <programlisting language="sml" linenumbering="unnumbered">let ... in ... end</programlisting>
32897 <simpara>isn&#8217;t a declaration.</simpara>
32898 <simpara>To specify a side-effecting computation in a source file, you can write:</simpara>
32899 <programlisting language="sml" linenumbering="unnumbered">val () = ...</programlisting>
32900 </section>
32901 <section id="_equality_types">
32902 <title>Equality types</title>
32903 <simpara>SML has a fairly intricate built-in notion of equality. See
32904 <link linkend="EqualityType">EqualityType</link> and <link linkend="EqualityTypeVariable">EqualityTypeVariable</link> for a thorough
32905 discussion.</simpara>
32906 </section>
32907 <section id="_nested_cases">
32908 <title>Nested cases</title>
32909 <simpara>It is a common mistake to write nested case expressions without the
32910 necessary parentheses. See <link linkend="UnresolvedBugs">UnresolvedBugs</link> for a discussion.</simpara>
32911 </section>
32912 <section id="_op">
32913 <title>(op *)</title>
32914 <simpara>It used to be a common mistake to parenthesize <literal>op *</literal> as <literal>(op *)</literal>.
32915 Before SML&#8217;97, <literal>*)</literal> was considered a comment terminator in SML and
32916 caused a syntax error. At the time of writing, <link linkend="SMLNJ">SML/NJ</link> still
32917 rejects the code. An extra space may be used for portability:
32918 <literal>(op * )</literal>. However, parenthesizing <literal>op</literal> is redundant, even though it
32919 is a widely used convention.</simpara>
32920 </section>
32921 <section id="_overloading">
32922 <title>Overloading</title>
32923 <simpara>A number of standard operators (<literal>+</literal>, <literal>-</literal>, <literal>~</literal>, <literal>*</literal>, <literal>&lt;</literal>, <literal>&gt;</literal>, &#8230;) and
32924 numeric constants are overloaded for some of the numeric types (<literal>int</literal>,
32925 <literal>real</literal>, <literal>word</literal>). It is a common surprise that definitions using
32926 overloaded operators such as</simpara>
32927 <programlisting language="sml" linenumbering="unnumbered">fun min (x, y) = if y &lt; x then y else x</programlisting>
32928 <simpara>are not overloaded themselves. SML doesn&#8217;t really support
32929 (user-defined) overloading or other forms of ad hoc polymorphism. In
32930 cases such as the above where the context doesn&#8217;t resolve the
32931 overloading, expressions using overloaded operators or constants get
32932 assigned a default type. The above definition gets the type</simpara>
32933 <programlisting language="sml" linenumbering="unnumbered">val min : int * int -&gt; int</programlisting>
32934 <simpara>See <link linkend="Overloading">Overloading</link> and <link linkend="TypeIndexedValues">TypeIndexedValues</link> for further discussion.</simpara>
32935 </section>
32936 <section id="_semicolons">
32937 <title>Semicolons</title>
32938 <simpara>It is a common mistake to use redundant semicolons in SML code. This
32939 is probably caused by the fact that in an SML REPL, a semicolon (and
32940 enter) is used to signal the REPL that it should evaluate the
32941 preceding chunk of code as a unit. In SML source files, semicolons
32942 are really needed in only two places. Namely, in expressions of the
32943 form</simpara>
32944 <programlisting language="sml" linenumbering="unnumbered">(exp ; ... ; exp)</programlisting>
32945 <simpara>and</simpara>
32946 <programlisting language="sml" linenumbering="unnumbered">let ... in exp ; ... ; exp end</programlisting>
32947 <simpara>Note that semicolons act as expression (or declaration) separators
32948 rather than as terminators.</simpara>
32949 </section>
32950 <section id="_stale_bindings">
32951 <title>Stale bindings</title>
32952 <simpara></simpara>
32953 </section>
32954 <section id="_unresolved_records">
32955 <title>Unresolved records</title>
32956 <simpara></simpara>
32957 </section>
32958 <section id="_value_restriction">
32959 <title>Value restriction</title>
32960 <simpara>See <link linkend="ValueRestriction">ValueRestriction</link>.</simpara>
32961 </section>
32962 <section id="_type_variable_scope">
32963 <title>Type Variable Scope</title>
32964 <simpara>See <link linkend="TypeVariableScope">TypeVariableScope</link>.</simpara>
32965 <simpara><?asciidoc-pagebreak?></simpara>
32966 </section>
32967 </section>
32968 <section id="StandardMLHistory">
32969 <title>StandardMLHistory</title>
32970 <simpara><link linkend="StandardML">Standard ML</link> grew out of <link linkend="ML">ML</link> in the early 1980s.</simpara>
32971 <simpara>For an excellent overview of SML&#8217;s history, see Appendix F of the
32972 <link linkend="DefinitionOfStandardML">Definition</link>.</simpara>
32973 <simpara>For an overview if its history before 1982, see <link linkend="References_Milner82">How ML Evolved</link>.</simpara>
32974 <simpara><?asciidoc-pagebreak?></simpara>
32975 </section>
32976 <section id="StandardMLImplementations">
32977 <title>StandardMLImplementations</title>
32978 <simpara>There are a number of implementations of <link linkend="StandardML">Standard ML</link>,
32979 from interpreters, to byte-code compilers, to incremental compilers,
32980 to whole-program compilers.</simpara>
32981 <itemizedlist>
32982 <listitem>
32983 <simpara>
32984 <link linkend="Alice">Alice ML</link>
32985 </simpara>
32986 </listitem>
32987 <listitem>
32988 <simpara>
32989 <link linkend="HaMLet">HaMLet</link>
32990 </simpara>
32991 </listitem>
32992 <listitem>
32993 <simpara>
32994 <link linkend="MLKit">ML Kit</link>
32995 </simpara>
32996 </listitem>
32997 <listitem>
32998 <simpara>
32999 <link linkend="Home">MLton</link>
33000 </simpara>
33001 </listitem>
33002 <listitem>
33003 <simpara>
33004 <link linkend="MoscowML">Moscow ML</link>
33005 </simpara>
33006 </listitem>
33007 <listitem>
33008 <simpara>
33009 <link linkend="PolyML">Poly/ML</link>
33010 </simpara>
33011 </listitem>
33012 <listitem>
33013 <simpara>
33014 <link linkend="SMLSharp">SML#</link>
33015 </simpara>
33016 </listitem>
33017 <listitem>
33018 <simpara>
33019 <link linkend="SMLNJ">SML/NJ</link>
33020 </simpara>
33021 </listitem>
33022 <listitem>
33023 <simpara>
33024 <link linkend="SMLNET">SML.NET</link>
33025 </simpara>
33026 </listitem>
33027 <listitem>
33028 <simpara>
33029 <link linkend="TILT">TILT</link>
33030 </simpara>
33031 </listitem>
33032 </itemizedlist>
33033 <section id="_not_actively_maintained">
33034 <title>Not Actively Maintained</title>
33035 <itemizedlist>
33036 <listitem>
33037 <simpara>
33038 <ulink url="http://www.dcs.ed.ac.uk/home/edml/">Edinburgh ML</ulink>
33039 </simpara>
33040 </listitem>
33041 <listitem>
33042 <simpara>
33043 <link linkend="MLj">MLj</link>
33044 </simpara>
33045 </listitem>
33046 <listitem>
33047 <simpara>
33048 MLWorks
33049 </simpara>
33050 </listitem>
33051 <listitem>
33052 <simpara>
33053 <link linkend="Poplog">Poplog</link>
33054 </simpara>
33055 </listitem>
33056 <listitem>
33057 <simpara>
33058 <ulink url="http://www.cs.cornell.edu/Info/People/jgm/til.tar.Z">TIL</ulink>
33059 </simpara>
33060 </listitem>
33061 </itemizedlist>
33062 <simpara><?asciidoc-pagebreak?></simpara>
33063 </section>
33064 </section>
33065 <section id="StandardMLPortability">
33066 <title>StandardMLPortability</title>
33067 <simpara>Technically, SML&#8217;97 as defined in the
33068 <link linkend="DefinitionOfStandardML">Definition</link>
33069 requires only a minimal initial basis, which, while including the
33070 types <literal>int</literal>, <literal>real</literal>, <literal>char</literal>, and <literal>string</literal>, need have
33071 no operations on those base types. Hence, the only observable output
33072 of an SML&#8217;97 program is termination or raising an exception. Most SML
33073 compilers should agree there, to the degree each agrees with the
33074 Definition. See <link linkend="UnresolvedBugs">UnresolvedBugs</link> for MLton&#8217;s very few corner cases.</simpara>
33075 <simpara>Realistically, a program needs to make use of the
33076 <link linkend="BasisLibrary">Basis Library</link>.
33077 Within the Basis Library, there are numerous places where the behavior
33078 is implementation dependent. For a trivial example:</simpara>
33079 <programlisting language="sml" linenumbering="unnumbered">val _ = valOf (Int.maxInt)</programlisting>
33080 <simpara>may either raise the <literal>Option</literal> exception (if
33081 <literal>Int.maxInt == NONE</literal>) or may terminate normally. The default
33082 Int/Real/Word sizes are the biggest implementation dependent aspect;
33083 so, one implementation may raise <literal>Overflow</literal> while another can
33084 accommodate the result. Also, maximum array and vector lengths are
33085 implementation dependent. Interfacing with the operating system is a
33086 bit murky, and implementations surely differ in handling of errors
33087 there.</simpara>
33088 <simpara><?asciidoc-pagebreak?></simpara>
33089 </section>
33090 <section id="StandardMLTutorials">
33091 <title>StandardMLTutorials</title>
33092 <itemizedlist>
33093 <listitem>
33094 <simpara>
33095 <ulink url="http://www.dcs.napier.ac.uk/course-notes/sml/manual.html">A Gentle Introduction to ML</ulink>.
33096 Andrew Cummings.
33097 </simpara>
33098 </listitem>
33099 <listitem>
33100 <simpara>
33101 <ulink url="http://www.dcs.ed.ac.uk/home/stg/NOTES/">Programming in Standard ML '97: An Online Tutorial</ulink>.
33102 Stephen Gilmore.
33103 </simpara>
33104 </listitem>
33105 <listitem>
33106 <simpara>
33107 <link linkend="References_Harper11">Programming in Standard ML</link>.
33108 Robert Harper.
33109 </simpara>
33110 </listitem>
33111 <listitem>
33112 <simpara>
33113 <link linkend="References_Tofte96">Essentials of Standard ML Modules</link>.
33114 Mads Tofte.
33115 </simpara>
33116 </listitem>
33117 <listitem>
33118 <simpara>
33119 <link linkend="References_Tofte09">Tips for Computer Scientists on Standard ML (Revised)</link>.
33120 Mads Tofte.
33121 </simpara>
33122 </listitem>
33123 </itemizedlist>
33124 <simpara><?asciidoc-pagebreak?></simpara>
33125 </section>
33126 <section id="StaticSum">
33127 <title>StaticSum</title>
33128 <simpara>While SML makes it impossible to write functions whose types would
33129 depend on the values of their arguments, or so called dependently
33130 typed functions, it is possible, and arguably commonplace, to write
33131 functions whose types depend on the types of their arguments. Indeed,
33132 the types of parametrically polymorphic functions like <literal>map</literal> and
33133 <literal>foldl</literal> can be said to depend on the types of their arguments. What
33134 is less commonplace, however, is to write functions whose behavior
33135 would depend on the types of their arguments. Nevertheless, there are
33136 several techniques for writing such functions.
33137 <link linkend="TypeIndexedValues">Type-indexed values</link> and <link linkend="Fold">fold</link> are two such
33138 techniques. This page presents another such technique dubbed static
33139 sums.</simpara>
33140 <section id="_ordinary_sums">
33141 <title>Ordinary Sums</title>
33142 <simpara>Consider the sum type as defined below:</simpara>
33143 <programlisting language="sml" linenumbering="unnumbered">structure Sum = struct
33144 datatype ('a, 'b) t = INL of 'a | INR of 'b
33145 end</programlisting>
33146 <simpara>While a generic sum type such as defined above is very useful, it has
33147 a number of limitations. As an example, we could write the function
33148 <literal>out</literal> to extract the value from a sum as follows:</simpara>
33149 <programlisting language="sml" linenumbering="unnumbered">fun out (s : ('a, 'a) Sum.t) : 'a =
33150 case s
33151 of Sum.INL a =&gt; a
33152 | Sum.INR a =&gt; a</programlisting>
33153 <simpara>As can be seen from the type of <literal>out</literal>, it is limited in the sense that
33154 it requires both variants of the sum to have the same type. So, <literal>out</literal>
33155 cannot be used to extract the value of a sum of two different types,
33156 such as the type <literal>(int, real) Sum.t</literal>. As another example of a
33157 limitation, consider the following attempt at a <literal>succ</literal> function:</simpara>
33158 <programlisting language="sml" linenumbering="unnumbered">fun succ (s : (int, real) Sum.t) : ??? =
33159 case s
33160 of Sum.INL i =&gt; i + 1
33161 | Sum.INR r =&gt; Real.nextAfter (r, Real.posInf)</programlisting>
33162 <simpara>The above definition of <literal>succ</literal> cannot be typed, because there is no
33163 type for the codomain within SML.</simpara>
33164 </section>
33165 <section id="_static_sums">
33166 <title>Static Sums</title>
33167 <simpara>Interestingly, it is possible to define values <literal>inL</literal>, <literal>inR</literal>, and
33168 <literal>match</literal> that satisfy the laws</simpara>
33169 <screen>match (inL x) (f, g) = f x
33170 match (inR x) (f, g) = g x</screen>
33171 <simpara>and do not suffer from the same limitions. The definitions are
33172 actually quite trivial:</simpara>
33173 <programlisting language="sml" linenumbering="unnumbered">structure StaticSum = struct
33174 fun inL x (f, _) = f x
33175 fun inR x (_, g) = g x
33176 fun match x = x
33177 end</programlisting>
33178 <simpara>Now, given the <literal>succ</literal> function defined as</simpara>
33179 <programlisting language="sml" linenumbering="unnumbered">fun succ s =
33180 StaticSum.match s
33181 (fn i =&gt; i + 1,
33182 fn r =&gt; Real.nextAfter (r, Real.posInf))</programlisting>
33183 <simpara>we get</simpara>
33184 <programlisting language="sml" linenumbering="unnumbered">succ (StaticSum.inL 1) = 2
33185 succ (StaticSum.inR Real.maxFinite) = Real.posInf</programlisting>
33186 <simpara>To better understand how this works, consider the following signature
33187 for static sums:</simpara>
33188 <programlisting language="sml" linenumbering="unnumbered">structure StaticSum :&gt; sig
33189 type ('dL, 'cL, 'dR, 'cR, 'c) t
33190 val inL : 'dL -&gt; ('dL, 'cL, 'dR, 'cR, 'cL) t
33191 val inR : 'dR -&gt; ('dL, 'cL, 'dR, 'cR, 'cR) t
33192 val match : ('dL, 'cL, 'dR, 'cR, 'c) t -&gt; ('dL -&gt; 'cL) * ('dR -&gt; 'cR) -&gt; 'c
33193 end = struct
33194 type ('dL, 'cL, 'dR, 'cR, 'c) t = ('dL -&gt; 'cL) * ('dR -&gt; 'cR) -&gt; 'c
33195 open StaticSum
33196 end</programlisting>
33197 <simpara>Above, <literal>'d</literal> stands for domain and <literal>'c</literal> for codomain. The key
33198 difference between an ordinary sum type, like <literal>(int, real) Sum.t</literal>, and
33199 a static sum type, like <literal>(int, real, real, int, real) StaticSum.t</literal>, is
33200 that the ordinary sum type says nothing about the type of the result
33201 of deconstructing a sum while the static sum type specifies the type.</simpara>
33202 <simpara>With the sealed static sum module, we get the type</simpara>
33203 <programlisting language="sml" linenumbering="unnumbered">val succ : (int, int, real, real, 'a) StaticSum.t -&gt; 'a</programlisting>
33204 <simpara>for the previously defined <literal>succ</literal> function. The type specifies that
33205 <literal>succ</literal> maps a left <literal>int</literal> to an <literal>int</literal> and a right <literal>real</literal> to a <literal>real</literal>.
33206 For example, the type of <literal>StaticSum.inL 1</literal> is
33207 <literal>(int, 'cL, 'dR, 'cR, 'cL) StaticSum.t</literal>. Unifying this with the
33208 argument type of <literal>succ</literal> gives the type <literal>(int, int, real, real, int)
33209 StaticSum.t -&gt; int</literal>.</simpara>
33210 <simpara>The <literal>out</literal> function is quite useful on its own. Here is how it can be
33211 defined:</simpara>
33212 <programlisting language="sml" linenumbering="unnumbered">structure StaticSum = struct
33213 open StaticSum
33214 val out : ('a, 'a, 'b, 'b, 'c) t -&gt; 'c =
33215 fn s =&gt; match s (fn x =&gt; x, fn x =&gt; x)
33216 end</programlisting>
33217 <simpara>Due to the value restriction, lack of first class polymorphism and
33218 polymorphic recursion, the usefulness and convenience of static sums
33219 is somewhat limited in SML. So, don&#8217;t throw away the ordinary sum
33220 type just yet. Static sums can nevertheless be quite useful.</simpara>
33221 <section id="_example_send_and_receive_with_argument_type_dependent_result_types">
33222 <title>Example: Send and Receive with Argument Type Dependent Result Types</title>
33223 <simpara>In some situations it would seem useful to define functions whose
33224 result type would depend on some of the arguments. Traditionally such
33225 functions have been thought to be impossible in SML and the solution
33226 has been to define multiple functions. For example, the
33227 <ulink url="http://www.standardml.org/Basis/socket.html"><literal>Socket</literal> structure</ulink> of the
33228 Basis library defines 16 <literal>send</literal> and 16 <literal>recv</literal> functions. In contrast,
33229 the Net structure
33230 (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/sweeks/basic/unstable/net.sig"><literal>net.sig</literal></ulink>) of the
33231 Basic library designed by Stephen Weeks defines only a single <literal>send</literal>
33232 and a single <literal>receive</literal> and the result types of the functions depend on
33233 their arguments. The implementation
33234 (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/sweeks/basic/unstable/net.sml"><literal>net.sml</literal></ulink>) uses
33235 static sums (with a slighly different signature:
33236 <ulink url="https://github.com/MLton/mltonlib/blob/master/com/sweeks/basic/unstable/static-sum.sig"><literal>static-sum.sig</literal></ulink>).</simpara>
33237 </section>
33238 <section id="_example_picking_monad_results">
33239 <title>Example: Picking Monad Results</title>
33240 <simpara>Suppose that we need to write a parser that accepts a pair of integers
33241 and returns their sum given a monadic parsing combinator library. A
33242 part of the signature of such library could look like this</simpara>
33243 <programlisting language="sml" linenumbering="unnumbered">signature PARSING = sig
33244 include MONAD
33245 val int : int t
33246 val lparen : unit t
33247 val rparen : unit t
33248 val comma : unit t
33249 (* ... *)
33250 end</programlisting>
33251 <simpara>where the <literal>MONAD</literal> signature could be defined as</simpara>
33252 <programlisting language="sml" linenumbering="unnumbered">signature MONAD = sig
33253 type 'a t
33254 val return : 'a -&gt; 'a t
33255 val &gt;&gt;= : 'a t * ('a -&gt; 'b t) -&gt; 'b t
33256 end
33257 infix &gt;&gt;=</programlisting>
33258 <simpara>The straightforward, but tedious, way to write the desired parser is:</simpara>
33259 <programlisting language="sml" linenumbering="unnumbered">val p = lparen &gt;&gt;= (fn _ =&gt;
33260 int &gt;&gt;= (fn x =&gt;
33261 comma &gt;&gt;= (fn _ =&gt;
33262 int &gt;&gt;= (fn y =&gt;
33263 rparen &gt;&gt;= (fn _ =&gt;
33264 return (x + y))))))</programlisting>
33265 <simpara>In Haskell, the parser could be written using the <literal>do</literal> notation
33266 considerably less verbosely as:</simpara>
33267 <programlisting language="haskell" linenumbering="unnumbered">p = do { lparen ; x &lt;- int ; comma ; y &lt;- int ; rparen ; return $ x + y }</programlisting>
33268 <simpara>SML doesn&#8217;t provide a <literal>do</literal> notation, so we need another solution.</simpara>
33269 <simpara>Suppose we would have a "pick" notation for monads that would allows
33270 us to write the parser as</simpara>
33271 <programlisting language="sml" linenumbering="unnumbered">val p = `lparen ^ \int ^ `comma ^ \int ^ `rparen @ (fn x &amp; y =&gt; x + y)</programlisting>
33272 <simpara>using four auxiliary combinators: <literal>&grave;</literal>, <literal>\</literal>, <literal>^</literal>, and <literal>@</literal>.</simpara>
33273 <simpara>Roughly speaking</simpara>
33274 <itemizedlist>
33275 <listitem>
33276 <simpara>
33277 <literal>&grave;p</literal> means that the result of <literal>p</literal> is dropped,
33278 </simpara>
33279 </listitem>
33280 <listitem>
33281 <simpara>
33282 <literal>\p</literal> means that the result of <literal>p</literal> is taken,
33283 </simpara>
33284 </listitem>
33285 <listitem>
33286 <simpara>
33287 <literal>p ^ q</literal> means that results of <literal>p</literal> and <literal>q</literal> are taken as a product, and
33288 </simpara>
33289 </listitem>
33290 <listitem>
33291 <simpara>
33292 <literal>p @ a</literal> means that the results of <literal>p</literal> are passed to the function <literal>a</literal> and that result is returned.
33293 </simpara>
33294 </listitem>
33295 </itemizedlist>
33296 <simpara>The difficulty is in implementing the concatenation combinator <literal>^</literal>.
33297 The type of the result of the concatenation depends on the types of
33298 the arguments.</simpara>
33299 <simpara>Using static sums and the <link linkend="ProductType">product type</link>, the pick
33300 notation for monads can be implemented as follows:</simpara>
33301 <programlisting language="sml" linenumbering="unnumbered">functor MkMonadPick (include MONAD) = let
33302 open StaticSum
33303 in
33304 struct
33305 fun `a = inL (a &gt;&gt;= (fn _ =&gt; return ()))
33306 val \ = inR
33307 fun a @ f = out a &gt;&gt;= (return o f)
33308 fun a ^ b =
33309 (match b o match a)
33310 (fn a =&gt;
33311 (fn b =&gt; inL (a &gt;&gt;= (fn _ =&gt; b)),
33312 fn b =&gt; inR (a &gt;&gt;= (fn _ =&gt; b))),
33313 fn a =&gt;
33314 (fn b =&gt; inR (a &gt;&gt;= (fn a =&gt; b &gt;&gt;= (fn _ =&gt; return a))),
33315 fn b =&gt; inR (a &gt;&gt;= (fn a =&gt; b &gt;&gt;= (fn b =&gt; return (a &amp; b))))))
33316 end
33317 end</programlisting>
33318 <simpara>The above implementation is inefficient, however. It uses many more
33319 bind operations, <literal>&gt;&gt;=</literal>, than necessary. That can be solved with an
33320 additional level of abstraction:</simpara>
33321 <programlisting language="sml" linenumbering="unnumbered">functor MkMonadPick (include MONAD) = let
33322 open StaticSum
33323 in
33324 struct
33325 fun `a = inL (fn b =&gt; a &gt;&gt;= (fn _ =&gt; b ()))
33326 fun \a = inR (fn b =&gt; a &gt;&gt;= b)
33327 fun a @ f = out a (return o f)
33328 fun a ^ b =
33329 (match b o match a)
33330 (fn a =&gt; (fn b =&gt; inL (fn c =&gt; a (fn () =&gt; b c)),
33331 fn b =&gt; inR (fn c =&gt; a (fn () =&gt; b c))),
33332 fn a =&gt; (fn b =&gt; inR (fn c =&gt; a (fn a =&gt; b (fn () =&gt; c a))),
33333 fn b =&gt; inR (fn c =&gt; a (fn a =&gt; b (fn b =&gt; c (a &amp; b))))))
33334 end
33335 end</programlisting>
33336 <simpara>After instantiating and opening either of the above monad pick
33337 implementations, the previously given definition of <literal>p</literal> can be
33338 compiled and results in a parser whose result is of type <literal>int</literal>. Here
33339 is a functor to test the theory:</simpara>
33340 <programlisting language="sml" linenumbering="unnumbered">functor Test (Arg : PARSING) = struct
33341 local
33342 structure Pick = MkMonadPick (Arg)
33343 open Pick Arg
33344 in
33345 val p : int t =
33346 `lparen ^ \int ^ `comma ^ \int ^ `rparen @ (fn x &amp; y =&gt; x + y)
33347 end
33348 end</programlisting>
33349 </section>
33350 </section>
33351 <section id="_also_see_46">
33352 <title>Also see</title>
33353 <simpara>There are a number of related techniques. Here are some of them.</simpara>
33354 <itemizedlist>
33355 <listitem>
33356 <simpara>
33357 <link linkend="Fold">Fold</link>
33358 </simpara>
33359 </listitem>
33360 <listitem>
33361 <simpara>
33362 <link linkend="TypeIndexedValues">TypeIndexedValues</link>
33363 </simpara>
33364 </listitem>
33365 </itemizedlist>
33366 <simpara><?asciidoc-pagebreak?></simpara>
33367 </section>
33368 </section>
33369 <section id="StephenWeeks">
33370 <title>StephenWeeks</title>
33371 <simpara>I live in the New York City area and work at <ulink url="http://janestcapital.com">Jane Street Capital</ulink>.</simpara>
33372 <simpara>My <ulink url="http://sweeks.com/">home page</ulink>.</simpara>
33373 <simpara>You can email me at <ulink url="mailto:sweeks@sweeks.com">sweeks@sweeks.com</ulink>.</simpara>
33374 <simpara><?asciidoc-pagebreak?></simpara>
33375 </section>
33376 <section id="StyleGuide">
33377 <title>StyleGuide</title>
33378 <simpara>These conventions are chosen so that inertia is towards modularity, code reuse and finding bugs early, <emphasis>not</emphasis> to save typing.</simpara>
33379 <itemizedlist>
33380 <listitem>
33381 <simpara>
33382 <link linkend="SyntacticConventions">SyntacticConventions</link>
33383 </simpara>
33384 </listitem>
33385 </itemizedlist>
33386 <simpara><?asciidoc-pagebreak?></simpara>
33387 </section>
33388 <section id="Subversion">
33389 <title>Subversion</title>
33390 <simpara><ulink url="http://subversion.apache.org/">Subversion</ulink> is a version control system.
33391 The MLton project used Subversion to maintain its
33392 <link linkend="Sources">source code</link>, but switched to <link linkend="Git">Git</link> on 20130308.</simpara>
33393 <simpara>Here are some online Subversion resources.</simpara>
33394 <itemizedlist>
33395 <listitem>
33396 <simpara>
33397 <ulink url="http://svnbook.red-bean.com">Version Control with Subversion</ulink>
33398 </simpara>
33399 </listitem>
33400 </itemizedlist>
33401 <simpara><?asciidoc-pagebreak?></simpara>
33402 </section>
33403 <section id="SuccessorML">
33404 <title>SuccessorML</title>
33405 <simpara>The purpose of <ulink url="http://sml-family.org/successor-ml/">successor ML</ulink>, or
33406 sML for short, is to provide a vehicle for the continued evolution of
33407 ML, using Standard ML as a starting point. The intention is for
33408 successor ML to be a living, evolving dialect of ML that is responsive
33409 to community needs and advances in language design, implementation,
33410 and semantics.</simpara>
33411 <section id="_successorml_features_in_mlton">
33412 <title>SuccessorML Features in MLton</title>
33413 <simpara>The following SuccessorML features have been implemented in MLton.
33414 The features are disabled by default, and may be enabled utilizing the
33415 feature&#8217;s corresponding <link linkend="MLBasisAnnotations">ML Basis annotation</link>
33416 which is listed directly after the feature name. In addition, the
33417 <literal>allowSuccessorML {false|true}</literal> annotation can be used to
33418 simultaneously enable all of the features.</simpara>
33419 <itemizedlist>
33420 <listitem>
33421 <simpara>
33422 <anchor id="SuccessorML_DoDecls" xreflabel="[SuccessorML_DoDecls]"/>
33423 <literal>do</literal> Declarations: <literal>allowDoDecls {false|true}</literal>
33424 </simpara>
33425 <simpara>Allow a <literal>do <emphasis>exp</emphasis></literal> declaration form, which evaluates <emphasis>exp</emphasis> for its
33426 side effects. The following example uses a <literal>do</literal> declaration:</simpara>
33427 <programlisting language="sml" linenumbering="unnumbered">do print "Hello world.\n"</programlisting>
33428 <simpara>and is equivalent to:</simpara>
33429 <programlisting language="sml" linenumbering="unnumbered">val () = print "Hello world.\n"</programlisting>
33430 </listitem>
33431 <listitem>
33432 <simpara>
33433 <anchor id="SuccessorML_ExtendedConsts" xreflabel="[SuccessorML_ExtendedConsts]"/>
33434 Extended Constants: <literal>allowExtendedConsts {false|true}</literal>
33435 </simpara>
33436 <simpara>Allow or disallow all of the extended constants features. This is a
33437 proxy for all of the following annotations.</simpara>
33438 <itemizedlist>
33439 <listitem>
33440 <simpara>
33441 <anchor id="SuccessorML_ExtendedNumConsts" xreflabel="[SuccessorML_ExtendedNumConsts]"/>
33442 Extended Numeric Constants: <literal>allowExtendedNumConsts {false|true}</literal>
33443 </simpara>
33444 <simpara>Allow underscores as a separator in numeric constants and allow binary
33445 integer and word constants.</simpara>
33446 <simpara>Underscores in a numeric constant must occur between digits and
33447 consecutive underscores are allowed.</simpara>
33448 <simpara>Binary integer constants use the prefix <literal>0b</literal> and binary word constants
33449 use the prefix <literal>0wb</literal>.</simpara>
33450 <simpara>The following example uses extended numeric constants (although it may
33451 be incorrectly syntax highlighted):</simpara>
33452 <programlisting language="sml" linenumbering="unnumbered">val pb = 0b10101
33453 val nb = ~0b10_10_10
33454 val wb = 0wb1010
33455 val i = 4__327__829
33456 val r = 6.022_140_9e23</programlisting>
33457 </listitem>
33458 <listitem>
33459 <simpara>
33460 <anchor id="SuccessorML_ExtendedTextConsts" xreflabel="[SuccessorML_ExtendedTextConsts]"/> Extended Text Constants: <literal>allowExtendedTextConsts {false|true}</literal>
33461 </simpara>
33462 <simpara>Allow characters with integer codes &ge; 128 and &le; 247 that
33463 correspond to syntactically well-formed UTF-8 byte sequences in text
33464 constants.</simpara>
33465 <simpara>Any 1, 2, 3, or 4 byte sequence that can be properly decoded to a
33466 binary number according to the UTF-8 encoding/decoding scheme is
33467 allowed in a text constant (but invalid sequences are not explicitly
33468 rejected) and denotes the corresponding sequence of characters with
33469 integer codes &ge; 128 and &le; 247. This feature enables "UTF-8
33470 convenience" (but not comprehensive Unicode support); in particular,
33471 it allows one to copy text from a browser and paste it into a string
33472 constant in an editor and, furthermore, if the string is printed to a
33473 terminal, then will (typically) appear as the original text. The
33474 following example uses UTF-8 byte sequences:</simpara>
33475 <programlisting language="sml" linenumbering="unnumbered">val s1 : String.string = "\240\159\130\161"
33476 val s2 : String.string = "🂡"
33477 val _ = print ("s1 --&gt; " ^ s1 ^ "\n")
33478 val _ = print ("s2 --&gt; " ^ s2 ^ "\n")
33479 val _ = print ("String.size s1 --&gt; " ^ Int.toString (String.size s1) ^ "\n")
33480 val _ = print ("String.size s2 --&gt; " ^ Int.toString (String.size s2) ^ "\n")
33481 val _ = print ("s1 = s2 --&gt; " ^ Bool.toString (s1 = s2) ^ "\n")</programlisting>
33482 <simpara>and, when compiled and executed, will display:</simpara>
33483 <screen>s1 --&gt; 🂡
33484 s2 --&gt; 🂡
33485 String.size s1 --&gt; 4
33486 String.size s2 --&gt; 4
33487 s1 = s2 --&gt; true</screen>
33488 <simpara>Note that the <literal>String.string</literal> type corresponds to any sequence of
33489 8-bit values, including invalid UTF-8 sequences; hence the string
33490 constant <literal>"\192"</literal> (a UTF-8 leading byte with no UTF-8 continuation
33491 byte) is valid. Similarly, the <literal>Char.char</literal> type corresponds to a
33492 single 8-bit value; hence the char constant <literal>#"α"</literal> is not valid, as
33493 the text constant <literal>"α"</literal> denotes a sequence of two 8-bit values.</simpara>
33494 </listitem>
33495 </itemizedlist>
33496 </listitem>
33497 <listitem>
33498 <simpara>
33499 <anchor id="SuccessorML_LineComments" xreflabel="[SuccessorML_LineComments]"/>
33500 Line Comments: <literal>allowLineComments {false|true}</literal>
33501 </simpara>
33502 <simpara>Allow line comments beginning with the token <literal>(*)</literal>. The following
33503 example uses a line comment:</simpara>
33504 <programlisting language="sml" linenumbering="unnumbered">(*) This is a line comment</programlisting>
33505 <simpara>Line comments properly nest within block comments. The following
33506 example uses line comments nested within block comments:</simpara>
33507 <programlisting language="sml" linenumbering="unnumbered">(*
33508 val x = 4 (*) This is a line comment
33509 *)
33510
33511 (*
33512 val y = 5 (*) This is a line comment *)
33513 *)</programlisting>
33514 </listitem>
33515 <listitem>
33516 <simpara>
33517 <anchor id="SuccessorML_OptBar" xreflabel="[SuccessorML_OptBar]"/>
33518 Optional Pattern Bars: <literal>allowOptBar {false|true}</literal>
33519 </simpara>
33520 <simpara>Allow a bar to appear before the first match rule of a <literal>case</literal>, <literal>fn</literal>,
33521 or <literal>handle</literal> expression, allow a bar to appear before the first
33522 function-value binding of a <literal>fun</literal> declaration, and allow a bar to
33523 appear before the first constructor binding or description of a
33524 <literal>datatype</literal> declaration or specification. The following example uses
33525 leading bars in a <literal>datatype</literal> declaration, a <literal>fun</literal> declaration, and a
33526 <literal>case</literal> expression:</simpara>
33527 <programlisting language="sml" linenumbering="unnumbered">datatype t =
33528 | C
33529 | B
33530 | A
33531
33532 fun
33533 | f NONE = 0
33534 | f (SOME t) =
33535 (case t of
33536 | A =&gt; 1
33537 | B =&gt; 2
33538 | C =&gt; 3)</programlisting>
33539 <simpara>By eliminating the special case of the first element, this feature
33540 allows for simpler refactoring (e.g., sorting the lines of the
33541 <literal>datatype</literal> declaration&#8217;s constructor bindings to put the constructors
33542 in alphabetical order).</simpara>
33543 </listitem>
33544 <listitem>
33545 <simpara>
33546 <anchor id="SuccessorML_OptSemicolon" xreflabel="[SuccessorML_OptSemicolon]"/>
33547 Optional Semicolons: <literal>allowOptSemicolon {false|true}</literal>
33548 </simpara>
33549 <simpara>Allow a semicolon to appear after the last expression in a sequence or
33550 <literal>let</literal>-body expression. The following example uses a trailing
33551 semicolon in the body of a <literal>let</literal> expression:</simpara>
33552 <programlisting language="sml" linenumbering="unnumbered">fun h z =
33553 let
33554 val x = 3 * z
33555 in
33556 f x ;
33557 g x ;
33558 end</programlisting>
33559 <simpara>By eliminating the special case of the last element, this feature
33560 allows for simpler refactoring.</simpara>
33561 </listitem>
33562 <listitem>
33563 <simpara>
33564 <anchor id="SuccessorML_OrPats" xreflabel="[SuccessorML_OrPats]"/>
33565 Disjunctive (Or) Patterns: <literal>allowOrPats {false|true}</literal>
33566 </simpara>
33567 <simpara>Allow disjunctive (a.k.a., "or") patterns of the form <literal><emphasis>pat<subscript>1</subscript></emphasis> |
33568 <emphasis>pat<subscript>2</subscript></emphasis></literal>, which matches a value that matches either <literal><emphasis>pat<subscript>1</subscript></emphasis></literal> or
33569 <literal><emphasis>pat<subscript>2</subscript></emphasis></literal>. Disjunctive patterns have lower precedence than <literal>as</literal>
33570 patterns and constraint patterns, much as <literal>orelse</literal> expressions have
33571 lower precedence than <literal>andalso</literal> expressions and constraint
33572 expressions. Both sub-patterns of a disjunctive pattern must bind the
33573 same variables with the same types. The following example uses
33574 disjunctive patterns:</simpara>
33575 <programlisting language="sml" linenumbering="unnumbered">datatype t = A of int | B of int | C of int | D of int * int | E of int * int
33576
33577 fun f t =
33578 case t of
33579 A x | B x | C x =&gt; x + 1
33580 | D (x, _) | E (_, x) =&gt; x * 2</programlisting>
33581 </listitem>
33582 <listitem>
33583 <simpara>
33584 <anchor id="SuccessorML_RecordPunExps" xreflabel="[SuccessorML_RecordPunExps]"/>
33585 Record Punning Expressions: <literal>allowRecordPunExps {false|true}</literal>
33586 </simpara>
33587 <simpara>Allow record punning expressions, whereby an identifier <literal><emphasis>vid</emphasis></literal> as an
33588 expression row in a record expression denotes the expression row
33589 <literal><emphasis>vid</emphasis> = <emphasis>vid</emphasis></literal> (i.e., treating a label as a variable). The following
33590 example uses record punning expressions (and also record punning
33591 patterns):</simpara>
33592 <programlisting language="sml" linenumbering="unnumbered">fun incB r =
33593 case r of {a, b, c} =&gt; {a, b = b + 1, c}</programlisting>
33594 <simpara>and is equivalent to:</simpara>
33595 <programlisting language="sml" linenumbering="unnumbered">fun incB r =
33596 case r of {a = a, b = b, c = c} =&gt; {a = a, b = b + 1, c = c}</programlisting>
33597 </listitem>
33598 <listitem>
33599 <simpara>
33600 <anchor id="SuccessorML_SigWithtype" xreflabel="[SuccessorML_SigWithtype]"/>
33601 <literal>withtype</literal> in Signatures: <literal>allowSigWithtype {false|true}</literal>
33602 </simpara>
33603 <simpara>Allow <literal>withtype</literal> to modify a <literal>datatype</literal> specification in a signature.
33604 The following example uses <literal>withtype</literal> in a signature (and also
33605 <literal>withtype</literal> in a declaration):</simpara>
33606 <programlisting language="sml" linenumbering="unnumbered">signature STREAM =
33607 sig
33608 datatype 'a u = Nil | Cons of 'a * 'a t
33609 withtype 'a t = unit -&gt; 'a u
33610 end
33611 structure Stream : STREAM =
33612 struct
33613 datatype 'a u = Nil | Cons of 'a * 'a t
33614 withtype 'a t = unit -&gt; 'a u
33615 end</programlisting>
33616 <simpara>and is equivalent to:</simpara>
33617 <programlisting language="sml" linenumbering="unnumbered">signature STREAM =
33618 sig
33619 datatype 'a u = Nil | Cons of 'a * (unit -&gt; 'a u)
33620 type 'a t = unit -&gt; 'a u
33621 end
33622 structure Stream : STREAM =
33623 struct
33624 datatype 'a u = Nil | Cons of 'a * (unit -&gt; 'a u)
33625 type 'a t = unit -&gt; 'a u
33626 end</programlisting>
33627 </listitem>
33628 <listitem>
33629 <simpara>
33630 <anchor id="SuccessorML_VectorExpsAndPats" xreflabel="[SuccessorML_VectorExpsAndPats]"/>
33631 Vector Expressions and Patterns: <literal>allowVectorExpsAndPats {false|true}</literal>
33632 </simpara>
33633 <simpara>Allow or disallow vector expressions and vector patterns. This is a
33634 proxy for all of the following annotations.</simpara>
33635 <itemizedlist>
33636 <listitem>
33637 <simpara>
33638 <anchor id="SuccessorML_VectorExps" xreflabel="[SuccessorML_VectorExps]"/>
33639 Vector Expressions: <literal>allowVectorExps {false|true}</literal>
33640 </simpara>
33641 <simpara>Allow vector expressions of the form <literal>#[<emphasis>exp<subscript>0</subscript></emphasis>, <emphasis>exp<subscript>1</subscript></emphasis>, &#8230;, <emphasis>exp<subscript>n-1</subscript></emphasis>]</literal> (where <emphasis>n ≥ 0</emphasis>). The expression has type <literal><emphasis>τ</emphasis> vector</literal> when each expression <emphasis>exp<subscript>i</subscript></emphasis> has type <literal><emphasis>τ</emphasis></literal>.</simpara>
33642 </listitem>
33643 <listitem>
33644 <simpara>
33645 <anchor id="SuccessorML_VectorPats" xreflabel="[SuccessorML_VectorPats]"/>
33646 Vector Patterns: <literal>allowVectorPats {false|true}</literal>
33647 </simpara>
33648 <simpara>Allow vector patterns of the form <literal>#[<emphasis>pat<subscript>0</subscript></emphasis>, <emphasis>pat<subscript>1</subscript></emphasis>, &#8230;, <emphasis>pat<subscript>n-1</subscript></emphasis>]</literal> (where <emphasis>n ≥ 0</emphasis>). The pattern matches values of type <literal><emphasis>τ</emphasis> vector</literal> when each pattern <emphasis>pat<subscript>i</subscript></emphasis> matches values of type <literal><emphasis>τ</emphasis></literal>.</simpara>
33649 </listitem>
33650 </itemizedlist>
33651 </listitem>
33652 </itemizedlist>
33653 <simpara><?asciidoc-pagebreak?></simpara>
33654 </section>
33655 </section>
33656 <section id="SureshJagannathan">
33657 <title>SureshJagannathan</title>
33658 <simpara>I am an Associate Professor at the <ulink url="http://www.cs.purdue.edu/">Department of Computer Science</ulink> at Purdue University.
33659 My research focus is in programming language design and implementation, concurrency,
33660 and distributed systems. I am interested in various aspects of MLton, mostly related to (in no particular order): (1) control-flow analysis (2) representation
33661 strategies (e.g., flattening), (3) IR formats, and (4) extensions for distributed programming.</simpara>
33662 <simpara>Please see my <ulink url="http://www.cs.purdue.edu/homes/suresh/index.html">Home page</ulink> for more details.</simpara>
33663 <simpara><?asciidoc-pagebreak?></simpara>
33664 </section>
33665 <section id="Swerve">
33666 <title>Swerve</title>
33667 <simpara><ulink url="http://ftp.sun.ac.za/ftp/mirrorsites/ocaml/Systems_programming/book/c3253.html">Swerve</ulink>
33668 is an HTTP server written in SML, originally developed with SML/NJ.
33669 <link linkend="RayRacine">RayRacine</link> ported Swerve to MLton in January 2005.</simpara>
33670 <simpara><ulink url="guide/Swerve.attachments/swerve.tar.bz2">Download</ulink> the port.</simpara>
33671 <simpara>Excerpt from the included <literal>README</literal>:</simpara>
33672 <blockquote>
33673 <simpara>Total testing of this port consisted of a successful compile, startup,
33674 and serving one html page with one gif image. Given that the original
33675 code was throughly designed and implemented in a thoughtful manner and
33676 I expect it is quite usable modulo a few minor bugs introduced by my
33677 porting effort.</simpara>
33678 </blockquote>
33679 <simpara>Swerve is described in <link linkend="References_Shipman02">Shipman02</link>.</simpara>
33680 <simpara><?asciidoc-pagebreak?></simpara>
33681 </section>
33682 <section id="SXML">
33683 <title>SXML</title>
33684 <simpara><link linkend="SXML">SXML</link> is an <link linkend="IntermediateLanguage">IntermediateLanguage</link>, translated from <link linkend="XML">XML</link> by
33685 <link linkend="Monomorphise">Monomorphise</link>, optimized by <link linkend="SXMLSimplify">SXMLSimplify</link>, and translated by
33686 <link linkend="ClosureConvert">ClosureConvert</link> to <link linkend="SSA">SSA</link>.</simpara>
33687 <section id="_description_59">
33688 <title>Description</title>
33689 <simpara>SXML is a simply-typed version of <link linkend="XML">XML</link>.</simpara>
33690 </section>
33691 <section id="_implementation_64">
33692 <title>Implementation</title>
33693 <itemizedlist>
33694 <listitem>
33695 <simpara>
33696 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/sxml.sig"><literal>sxml.sig</literal></ulink>
33697 </simpara>
33698 </listitem>
33699 <listitem>
33700 <simpara>
33701 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/sxml.fun"><literal>sxml.fun</literal></ulink>
33702 </simpara>
33703 </listitem>
33704 <listitem>
33705 <simpara>
33706 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/sxml-tree.sig"><literal>sxml-tree.sig</literal></ulink>
33707 </simpara>
33708 </listitem>
33709 </itemizedlist>
33710 </section>
33711 <section id="_type_checking_7">
33712 <title>Type Checking</title>
33713 <simpara><link linkend="SXML">SXML</link> shares the type checker for <link linkend="XML">XML</link>.</simpara>
33714 </section>
33715 <section id="_details_and_notes_62">
33716 <title>Details and Notes</title>
33717 <simpara>There are only two differences between <link linkend="XML">XML</link> and <link linkend="SXML">SXML</link>. First,
33718 <link linkend="SXML">SXML</link> <literal>val</literal>, <literal>fun</literal>, and <literal>datatype</literal> declarations always have an
33719 empty list of type variables. Second, <link linkend="SXML">SXML</link> variable references
33720 always have an empty list of type arguments. Constructors uses can
33721 only have a nonempty list of type arguments if the constructor is a
33722 primitive.</simpara>
33723 <simpara>Although we could rely on the type system to enforce these constraints
33724 by parameterizing the <link linkend="XML">XML</link> signature, <link linkend="StephenWeeks">StephenWeeks</link> did so in a
33725 previous version of the compiler, and the software engineering gains
33726 were not worth the effort.</simpara>
33727 <simpara><?asciidoc-pagebreak?></simpara>
33728 </section>
33729 </section>
33730 <section id="SXMLShrink">
33731 <title>SXMLShrink</title>
33732 <simpara>SXMLShrink is an optimization pass for the <link linkend="SXML">SXML</link>
33733 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SXMLSimplify">SXMLSimplify</link>.</simpara>
33734 <section id="_description_60">
33735 <title>Description</title>
33736 <simpara>This pass performs optimizations based on a reduction system.</simpara>
33737 </section>
33738 <section id="_implementation_65">
33739 <title>Implementation</title>
33740 <itemizedlist>
33741 <listitem>
33742 <simpara>
33743 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/shrink.sig"><literal>shrink.sig</literal></ulink>
33744 </simpara>
33745 </listitem>
33746 <listitem>
33747 <simpara>
33748 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/shrink.fun"><literal>shrink.fun</literal></ulink>
33749 </simpara>
33750 </listitem>
33751 </itemizedlist>
33752 </section>
33753 <section id="_details_and_notes_63">
33754 <title>Details and Notes</title>
33755 <simpara><link linkend="SXML">SXML</link> shares the <link linkend="XMLShrink">XMLShrink</link> simplifier.</simpara>
33756 <simpara><?asciidoc-pagebreak?></simpara>
33757 </section>
33758 </section>
33759 <section id="SXMLSimplify">
33760 <title>SXMLSimplify</title>
33761 <simpara>The optimization passes for the <link linkend="SXML">SXML</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> are
33762 collected and controlled by the <literal>SxmlSimplify</literal> functor
33763 (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/sxml-simplify.sig"><literal>sxml-simplify.sig</literal></ulink>,
33764 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/sxml-simplify.fun"><literal>sxml-simplify.fun</literal></ulink>).</simpara>
33765 <simpara>The following optimization passes are implemented:</simpara>
33766 <itemizedlist>
33767 <listitem>
33768 <simpara>
33769 <link linkend="Polyvariance">Polyvariance</link>
33770 </simpara>
33771 </listitem>
33772 <listitem>
33773 <simpara>
33774 <link linkend="SXMLShrink">SXMLShrink</link>
33775 </simpara>
33776 </listitem>
33777 </itemizedlist>
33778 <simpara>The following implementation passes are implemented:</simpara>
33779 <itemizedlist>
33780 <listitem>
33781 <simpara>
33782 <link linkend="ImplementExceptions">ImplementExceptions</link>
33783 </simpara>
33784 </listitem>
33785 <listitem>
33786 <simpara>
33787 <link linkend="ImplementSuffix">ImplementSuffix</link>
33788 </simpara>
33789 </listitem>
33790 </itemizedlist>
33791 <simpara>The following optimization passes are not implemented, but might prove useful:</simpara>
33792 <itemizedlist>
33793 <listitem>
33794 <simpara>
33795 <link linkend="Uncurry">Uncurry</link>
33796 </simpara>
33797 </listitem>
33798 <listitem>
33799 <simpara>
33800 <link linkend="LambdaLift">LambdaLift</link>
33801 </simpara>
33802 </listitem>
33803 </itemizedlist>
33804 <simpara>The optimization passes can be controlled from the command-line by the options</simpara>
33805 <itemizedlist>
33806 <listitem>
33807 <simpara>
33808 <literal>-diag-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;keep diagnostic info for pass
33809 </simpara>
33810 </listitem>
33811 <listitem>
33812 <simpara>
33813 <literal>-disable-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;skip optimization pass (if normally performed)
33814 </simpara>
33815 </listitem>
33816 <listitem>
33817 <simpara>
33818 <literal>-enable-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;perform optimization pass (if normally skipped)
33819 </simpara>
33820 </listitem>
33821 <listitem>
33822 <simpara>
33823 <literal>-keep-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;keep the results of pass
33824 </simpara>
33825 </listitem>
33826 <listitem>
33827 <simpara>
33828 <literal>-sxml-passes &lt;passes&gt;</literal>&#8201;&#8212;&#8201;sxml optimization passes
33829 </simpara>
33830 </listitem>
33831 </itemizedlist>
33832 <simpara><?asciidoc-pagebreak?></simpara>
33833 </section>
33834 <section id="SyntacticConventions">
33835 <title>SyntacticConventions</title>
33836 <simpara>Here are a number of syntactic conventions useful for programming in
33837 SML.</simpara>
33838 <section id="_general">
33839 <title>General</title>
33840 <itemizedlist>
33841 <listitem>
33842 <simpara>
33843 A line of code never exceeds 80 columns.
33844 </simpara>
33845 </listitem>
33846 <listitem>
33847 <simpara>
33848 Only split a syntactic entity across multiple lines if it doesn&#8217;t fit on one line within 80 columns.
33849 </simpara>
33850 </listitem>
33851 <listitem>
33852 <simpara>
33853 Use alphabetical order wherever possible.
33854 </simpara>
33855 </listitem>
33856 <listitem>
33857 <simpara>
33858 Avoid redundant parentheses.
33859 </simpara>
33860 </listitem>
33861 <listitem>
33862 <simpara>
33863 When using <literal>:</literal>, there is no space before the colon, and a single space after it.
33864 </simpara>
33865 </listitem>
33866 </itemizedlist>
33867 </section>
33868 <section id="_identifiers">
33869 <title>Identifiers</title>
33870 <itemizedlist>
33871 <listitem>
33872 <simpara>
33873 Variables, record labels and type constructors begin with and use
33874 small letters, using capital letters to separate words.
33875 </simpara>
33876 <programlisting language="sml" linenumbering="unnumbered">cost
33877 maxValue</programlisting>
33878 </listitem>
33879 <listitem>
33880 <simpara>
33881 Variables that represent collections of objects (lists, arrays,
33882 vectors, &#8230;) are often suffixed with an <literal>s</literal>.
33883 </simpara>
33884 <programlisting language="sml" linenumbering="unnumbered">xs
33885 employees</programlisting>
33886 </listitem>
33887 <listitem>
33888 <simpara>
33889 Constructors, structure identifiers, and functor identifiers begin
33890 with a capital letter.
33891 </simpara>
33892 <programlisting language="sml" linenumbering="unnumbered">Queue
33893 LinkedList</programlisting>
33894 </listitem>
33895 <listitem>
33896 <simpara>
33897 Signature identifiers are in all capitals, using <literal>_</literal> to separate
33898 words.
33899 </simpara>
33900 <programlisting language="sml" linenumbering="unnumbered">LIST
33901 BINARY_HEAP</programlisting>
33902 </listitem>
33903 </itemizedlist>
33904 </section>
33905 <section id="_types_2">
33906 <title>Types</title>
33907 <itemizedlist>
33908 <listitem>
33909 <simpara>
33910 Alphabetize record labels. In a record type, there are spaces after
33911 colons and commas, but not before colons or commas, or at the
33912 delimiters <literal>{</literal> and <literal>}</literal>.
33913 </simpara>
33914 <programlisting language="sml" linenumbering="unnumbered">{bar: int, foo: int}</programlisting>
33915 </listitem>
33916 <listitem>
33917 <simpara>
33918 Only split a record type across multiple lines if it doesn&#8217;t fit on
33919 one line. If a record type must be split over multiple lines, put one
33920 field per line.
33921 </simpara>
33922 <programlisting language="sml" linenumbering="unnumbered">{bar: int,
33923 foo: real * real,
33924 zoo: bool}</programlisting>
33925 </listitem>
33926 <listitem>
33927 <simpara>
33928 In a tuple type, there are spaces before and after each <literal>*</literal>.
33929 </simpara>
33930 <programlisting language="sml" linenumbering="unnumbered">int * bool * real</programlisting>
33931 </listitem>
33932 <listitem>
33933 <simpara>
33934 Only split a tuple type across multiple lines if it doesn&#8217;t fit on
33935 one line. In a tuple type split over multiple lines, there is one
33936 type per line, and the <literal>*</literal>-s go at the beginning of the lines.
33937 </simpara>
33938 <programlisting language="sml" linenumbering="unnumbered">int
33939 * bool
33940 * real</programlisting>
33941 <simpara>It may also be useful to parenthesize to make the grouping more
33942 apparent.</simpara>
33943 <programlisting language="sml" linenumbering="unnumbered">(int
33944 * bool
33945 * real)</programlisting>
33946 </listitem>
33947 <listitem>
33948 <simpara>
33949 In an arrow type split over multiple lines, put the arrow at the
33950 beginning of its line.
33951 </simpara>
33952 <programlisting language="sml" linenumbering="unnumbered">int * real
33953 -&gt; bool</programlisting>
33954 <simpara>It may also be useful to parenthesize to make the grouping more
33955 apparent.</simpara>
33956 <programlisting language="sml" linenumbering="unnumbered">(int * real
33957 -&gt; bool)</programlisting>
33958 </listitem>
33959 <listitem>
33960 <simpara>
33961 Avoid redundant parentheses.
33962 </simpara>
33963 </listitem>
33964 <listitem>
33965 <simpara>
33966 Arrow types associate to the right, so write
33967 </simpara>
33968 <programlisting language="sml" linenumbering="unnumbered">a -&gt; b -&gt; c</programlisting>
33969 <simpara>not</simpara>
33970 <programlisting language="sml" linenumbering="unnumbered">a -&gt; (b -&gt; c)</programlisting>
33971 </listitem>
33972 <listitem>
33973 <simpara>
33974 Type constructor application associates to the left, so write
33975 </simpara>
33976 <programlisting language="sml" linenumbering="unnumbered">int ref list</programlisting>
33977 <simpara>not</simpara>
33978 <programlisting language="sml" linenumbering="unnumbered">(int ref) list</programlisting>
33979 </listitem>
33980 <listitem>
33981 <simpara>
33982 Type constructor application binds more tightly than a tuple type,
33983 so write
33984 </simpara>
33985 <programlisting language="sml" linenumbering="unnumbered">int list * bool list</programlisting>
33986 <simpara>not</simpara>
33987 <programlisting language="sml" linenumbering="unnumbered">(int list) * (bool list)</programlisting>
33988 </listitem>
33989 <listitem>
33990 <simpara>
33991 Tuple types bind more tightly than arrow types, so write
33992 </simpara>
33993 <programlisting language="sml" linenumbering="unnumbered">int * bool -&gt; real</programlisting>
33994 <simpara>not</simpara>
33995 <programlisting language="sml" linenumbering="unnumbered">(int * bool) -&gt; real</programlisting>
33996 </listitem>
33997 </itemizedlist>
33998 </section>
33999 <section id="_core">
34000 <title>Core</title>
34001 <itemizedlist>
34002 <listitem>
34003 <simpara>
34004 A core expression or declaration split over multiple lines does not
34005 contain any blank lines.
34006 </simpara>
34007 </listitem>
34008 <listitem>
34009 <simpara>
34010 A record field selector has no space between the <literal>#</literal> and the record
34011 label. So, write
34012 </simpara>
34013 <programlisting language="sml" linenumbering="unnumbered">#foo</programlisting>
34014 <simpara>not</simpara>
34015 <programlisting language="sml" linenumbering="unnumbered"># foo</programlisting>
34016 </listitem>
34017 <listitem>
34018 <simpara>
34019 A tuple has a space after each comma, but not before, and not at the
34020 delimiters <literal>(</literal> and <literal>)</literal>.
34021 </simpara>
34022 <programlisting language="sml" linenumbering="unnumbered">(e1, e2, e3)</programlisting>
34023 </listitem>
34024 <listitem>
34025 <simpara>
34026 A tuple split over multiple lines has one element per line, and the
34027 commas go at the end of the lines.
34028 </simpara>
34029 <programlisting language="sml" linenumbering="unnumbered">(e1,
34030 e2,
34031 e3)</programlisting>
34032 </listitem>
34033 <listitem>
34034 <simpara>
34035 A list has a space after each comma, but not before, and not at the
34036 delimiters <literal>[</literal> and <literal>]</literal>.
34037 </simpara>
34038 <programlisting language="sml" linenumbering="unnumbered">[e1, e2, e3]</programlisting>
34039 </listitem>
34040 <listitem>
34041 <simpara>
34042 A list split over multiple lines has one element per line, and the
34043 commas at the end of the lines.
34044 </simpara>
34045 <programlisting language="sml" linenumbering="unnumbered">[e1,
34046 e2,
34047 e3]</programlisting>
34048 </listitem>
34049 <listitem>
34050 <simpara>
34051 A record has spaces before and after <literal>=</literal>, a space after each comma,
34052 but not before, and not at the delimiters <literal>{</literal> and <literal>}</literal>. Field names
34053 appear in alphabetical order.
34054 </simpara>
34055 <programlisting language="sml" linenumbering="unnumbered">{bar = 13, foo = true}</programlisting>
34056 </listitem>
34057 <listitem>
34058 <simpara>
34059 A sequence expression has a space after each semicolon, but not before.
34060 </simpara>
34061 <programlisting language="sml" linenumbering="unnumbered">(e1; e2; e3)</programlisting>
34062 </listitem>
34063 <listitem>
34064 <simpara>
34065 A sequence expression split over multiple lines has one expression
34066 per line, and the semicolons at the beginning of lines. Lisp and
34067 Scheme programmers may find this hard to read at first.
34068 </simpara>
34069 <programlisting language="sml" linenumbering="unnumbered">(e1
34070 ; e2
34071 ; e3)</programlisting>
34072 <simpara><emphasis>Rationale</emphasis>: this makes it easy to visually spot the beginning of each
34073 expression, which becomes more valuable as the expressions themselves
34074 are split across multiple lines.</simpara>
34075 </listitem>
34076 <listitem>
34077 <simpara>
34078 An application expression has a space between the function and the
34079 argument. There are no parens unless the argument is a tuple (in
34080 which case the parens are really part of the tuple, not the
34081 application).
34082 </simpara>
34083 <programlisting language="sml" linenumbering="unnumbered">f a
34084 f (a1, a2, a3)</programlisting>
34085 </listitem>
34086 <listitem>
34087 <simpara>
34088 Avoid redundant parentheses. Application associates to left, so
34089 write
34090 </simpara>
34091 <programlisting language="sml" linenumbering="unnumbered">f a1 a2 a3</programlisting>
34092 <simpara>not</simpara>
34093 <programlisting language="sml" linenumbering="unnumbered">((f a1) a2) a3</programlisting>
34094 </listitem>
34095 <listitem>
34096 <simpara>
34097 Infix operators have a space before and after the operator.
34098 </simpara>
34099 <programlisting language="sml" linenumbering="unnumbered">x + y
34100 x * y - z</programlisting>
34101 </listitem>
34102 <listitem>
34103 <simpara>
34104 Avoid redundant parentheses. Use <link linkend="OperatorPrecedence">OperatorPrecedence</link>. So, write
34105 </simpara>
34106 <programlisting language="sml" linenumbering="unnumbered">x + y * z</programlisting>
34107 <simpara>not</simpara>
34108 <programlisting language="sml" linenumbering="unnumbered">x + (y * z)</programlisting>
34109 </listitem>
34110 <listitem>
34111 <simpara>
34112 An <literal>andalso</literal> expression split over multiple lines has the <literal>andalso</literal>
34113 at the beginning of subsequent lines.
34114 </simpara>
34115 <programlisting language="sml" linenumbering="unnumbered">e1
34116 andalso e2
34117 andalso e3</programlisting>
34118 </listitem>
34119 <listitem>
34120 <simpara>
34121 A <literal>case</literal> expression is indented as follows
34122 </simpara>
34123 <programlisting language="sml" linenumbering="unnumbered">case e1 of
34124 p1 =&gt; e1
34125 | p2 =&gt; e2
34126 | p3 =&gt; e3</programlisting>
34127 </listitem>
34128 <listitem>
34129 <simpara>
34130 A <literal>datatype</literal>'s constructors are alphabetized.
34131 </simpara>
34132 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B | C</programlisting>
34133 </listitem>
34134 <listitem>
34135 <simpara>
34136 A <literal>datatype</literal> declaration has a space before and after each <literal>|</literal>.
34137 </simpara>
34138 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B of int | C</programlisting>
34139 </listitem>
34140 <listitem>
34141 <simpara>
34142 A <literal>datatype</literal> split over multiple lines has one constructor per line,
34143 with the <literal>|</literal> at the beginning of lines and the constructors beginning
34144 3 columns to the right of the <literal>datatype</literal>.
34145 </simpara>
34146 <programlisting language="sml" linenumbering="unnumbered">datatype t =
34147 A
34148 | B
34149 | C</programlisting>
34150 </listitem>
34151 <listitem>
34152 <simpara>
34153 A <literal>fun</literal> declaration may start its body on the subsequent line,
34154 indented 3 spaces.
34155 </simpara>
34156 <programlisting language="sml" linenumbering="unnumbered">fun f x y =
34157 let
34158 val z = x + y + z
34159 in
34160 z
34161 end</programlisting>
34162 </listitem>
34163 <listitem>
34164 <simpara>
34165 An <literal>if</literal> expression is indented as follows.
34166 </simpara>
34167 <programlisting language="sml" linenumbering="unnumbered">if e1
34168 then e2
34169 else e3</programlisting>
34170 </listitem>
34171 <listitem>
34172 <simpara>
34173 A sequence of <literal>if</literal>-<literal>then</literal>-<literal>else</literal>-s is indented as follows.
34174 </simpara>
34175 <programlisting language="sml" linenumbering="unnumbered">if e1
34176 then e2
34177 else if e3
34178 then e4
34179 else if e5
34180 then e6
34181 else e7</programlisting>
34182 </listitem>
34183 <listitem>
34184 <simpara>
34185 A <literal>let</literal> expression has the <literal>let</literal>, <literal>in</literal>, and <literal>end</literal> on their own
34186 lines, starting in the same column. Declarations and the body are
34187 indented 3 spaces.
34188 </simpara>
34189 <programlisting language="sml" linenumbering="unnumbered">let
34190 val x = 13
34191 val y = 14
34192 in
34193 x + y
34194 end</programlisting>
34195 </listitem>
34196 <listitem>
34197 <simpara>
34198 A <literal>local</literal> declaration has the <literal>local</literal>, <literal>in</literal>, and <literal>end</literal> on their own
34199 lines, starting in the same column. Declarations are indented 3
34200 spaces.
34201 </simpara>
34202 <programlisting language="sml" linenumbering="unnumbered">local
34203 val x = 13
34204 in
34205 val y = x
34206 end</programlisting>
34207 </listitem>
34208 <listitem>
34209 <simpara>
34210 An <literal>orelse</literal> expression split over multiple lines has the <literal>orelse</literal> at
34211 the beginning of subsequent lines.
34212 </simpara>
34213 <programlisting language="sml" linenumbering="unnumbered">e1
34214 orelse e2
34215 orelse e3</programlisting>
34216 </listitem>
34217 <listitem>
34218 <simpara>
34219 A <literal>val</literal> declaration has a space before and after the <literal>=</literal>.
34220 </simpara>
34221 <programlisting language="sml" linenumbering="unnumbered">val p = e</programlisting>
34222 </listitem>
34223 <listitem>
34224 <simpara>
34225 A <literal>val</literal> declaration can start the expression on the subsequent line,
34226 indented 3 spaces.
34227 </simpara>
34228 <programlisting language="sml" linenumbering="unnumbered">val p =
34229 if e1 then e2 else e3</programlisting>
34230 </listitem>
34231 </itemizedlist>
34232 </section>
34233 <section id="_signatures">
34234 <title>Signatures</title>
34235 <itemizedlist>
34236 <listitem>
34237 <simpara>
34238 A <literal>signature</literal> declaration is indented as follows.
34239 </simpara>
34240 <programlisting language="sml" linenumbering="unnumbered">signature FOO =
34241 sig
34242 val x: int
34243 end</programlisting>
34244 <simpara><emphasis>Exception</emphasis>: a signature declaration in a file to itself can omit the
34245 indentation to save horizontal space.</simpara>
34246 <programlisting language="sml" linenumbering="unnumbered">signature FOO =
34247 sig
34248
34249 val x: int
34250
34251 end</programlisting>
34252 <simpara>In this case, there should be a blank line after the <literal>sig</literal> and before
34253 the <literal>end</literal>.</simpara>
34254 </listitem>
34255 <listitem>
34256 <simpara>
34257 A <literal>val</literal> specification has a space after the colon, but not before.
34258 </simpara>
34259 <programlisting language="sml" linenumbering="unnumbered">val x: int</programlisting>
34260 <simpara><emphasis>Exception</emphasis>: in the case of operators (like <literal>+</literal>), there is a space
34261 before the colon to avoid lexing the colon as part of the operator.</simpara>
34262 <programlisting language="sml" linenumbering="unnumbered">val + : t * t -&gt; t</programlisting>
34263 </listitem>
34264 <listitem>
34265 <simpara>
34266 Alphabetize specifications in signatures.
34267 </simpara>
34268 <programlisting language="sml" linenumbering="unnumbered">sig
34269 val x: int
34270 val y: bool
34271 end</programlisting>
34272 </listitem>
34273 </itemizedlist>
34274 </section>
34275 <section id="_structures">
34276 <title>Structures</title>
34277 <itemizedlist>
34278 <listitem>
34279 <simpara>
34280 A <literal>structure</literal> declaration has a space on both sides of the <literal>=</literal>.
34281 </simpara>
34282 <programlisting language="sml" linenumbering="unnumbered">structure Foo = Bar</programlisting>
34283 </listitem>
34284 <listitem>
34285 <simpara>
34286 A <literal>structure</literal> declaration split over multiple lines is indented as
34287 follows.
34288 </simpara>
34289 <programlisting language="sml" linenumbering="unnumbered">structure S =
34290 struct
34291 val x = 13
34292 end</programlisting>
34293 <simpara><emphasis>Exception</emphasis>: a structure declaration in a file to itself can omit the
34294 indentation to save horizontal space.</simpara>
34295 <programlisting language="sml" linenumbering="unnumbered">structure S =
34296 struct
34297
34298 val x = 13
34299
34300 end</programlisting>
34301 <simpara>In this case, there should be a blank line after the <literal>struct</literal> and
34302 before the <literal>end</literal>.</simpara>
34303 </listitem>
34304 <listitem>
34305 <simpara>
34306 Declarations in a <literal>struct</literal> are separated by blank lines.
34307 </simpara>
34308 <programlisting language="sml" linenumbering="unnumbered">struct
34309 val x =
34310 let
34311 y = 13
34312 in
34313 y + 1
34314 end
34315
34316 val z = 14
34317 end</programlisting>
34318 </listitem>
34319 </itemizedlist>
34320 </section>
34321 <section id="_functors">
34322 <title>Functors</title>
34323 <itemizedlist>
34324 <listitem>
34325 <simpara>
34326 A <literal>functor</literal> declaration has spaces after each <literal>:</literal> (or <literal>:&gt;</literal>) but not
34327 before, and a space before and after the <literal>=</literal>. It is indented as
34328 follows.
34329 </simpara>
34330 <programlisting language="sml" linenumbering="unnumbered">functor Foo (S: FOO_ARG): FOO =
34331 struct
34332 val x = S.x
34333 end</programlisting>
34334 <simpara><emphasis>Exception</emphasis>: a functor declaration in a file to itself can omit the
34335 indentation to save horizontal space.</simpara>
34336 <programlisting language="sml" linenumbering="unnumbered">functor Foo (S: FOO_ARG): FOO =
34337 struct
34338
34339 val x = S.x
34340
34341 end</programlisting>
34342 <simpara>In this case, there should be a blank line after the <literal>struct</literal>
34343 and before the <literal>end</literal>.</simpara>
34344 </listitem>
34345 </itemizedlist>
34346 <simpara><?asciidoc-pagebreak?></simpara>
34347 </section>
34348 </section>
34349 <section id="Talk">
34350 <title>Talk</title>
34351 <section id="_the_mlton_standard_ml_compiler">
34352 <title>The MLton Standard ML Compiler</title>
34353 <simpara><emphasis role="strong">Henry Cejtin, Matthew Fluet, Suresh Jagannathan, Stephen Weeks</emphasis></simpara>
34354 <simpara>&#160;<?asciidoc-br?>
34355 &#160;<?asciidoc-br?>
34356 &#160;<?asciidoc-br?></simpara>
34357 <simpara><?asciidoc-hr?></simpara>
34358 <informaltable
34359 frame="all"
34360 rowsep="1" colsep="1"
34361 >
34362 <tgroup cols="2">
34363 <colspec colname="col_1" colwidth="50*"/>
34364 <colspec colname="col_2" colwidth="50*"/>
34365 <tbody>
34366 <row>
34367 <entry align="left" valign="top"><simpara></simpara></entry>
34368 <entry align="right" valign="top"><simpara><link linkend="TalkStandardML">Next</link></simpara></entry>
34369 </row>
34370 </tbody>
34371 </tgroup>
34372 </informaltable>
34373 <simpara><?asciidoc-pagebreak?></simpara>
34374 </section>
34375 </section>
34376 <section id="TalkDiveIn">
34377 <title>TalkDiveIn</title>
34378 <section id="_dive_in">
34379 <title>Dive In</title>
34380 <itemizedlist>
34381 <listitem>
34382 <simpara>
34383 to <link linkend="Development">Development</link>
34384 </simpara>
34385 </listitem>
34386 <listitem>
34387 <simpara>
34388 to <link linkend="Documentation">Documentation</link>
34389 </simpara>
34390 </listitem>
34391 <listitem>
34392 <simpara>
34393 to <link linkend="Download">Download</link>
34394 </simpara>
34395 </listitem>
34396 </itemizedlist>
34397 <simpara>&#160;<?asciidoc-br?>
34398 &#160;<?asciidoc-br?>
34399 &#160;<?asciidoc-br?></simpara>
34400 <simpara><?asciidoc-hr?></simpara>
34401 <informaltable
34402 frame="all"
34403 rowsep="1" colsep="1"
34404 >
34405 <tgroup cols="2">
34406 <colspec colname="col_1" colwidth="50*"/>
34407 <colspec colname="col_2" colwidth="50*"/>
34408 <tbody>
34409 <row>
34410 <entry align="left" valign="top"><simpara><link linkend="TalkMLtonHistory">Prev</link></simpara></entry>
34411 <entry align="right" valign="top"><simpara></simpara></entry>
34412 </row>
34413 </tbody>
34414 </tgroup>
34415 </informaltable>
34416 <simpara><?asciidoc-pagebreak?></simpara>
34417 </section>
34418 </section>
34419 <section id="TalkFolkLore">
34420 <title>TalkFolkLore</title>
34421 <section id="_folk_lore">
34422 <title>Folk Lore</title>
34423 <itemizedlist>
34424 <listitem>
34425 <simpara>
34426 Defunctorization and monomorphisation are feasible
34427 </simpara>
34428 </listitem>
34429 <listitem>
34430 <simpara>
34431 Global control-flow analysis is feasible
34432 </simpara>
34433 </listitem>
34434 <listitem>
34435 <simpara>
34436 Early closure conversion is feasible
34437 </simpara>
34438 </listitem>
34439 </itemizedlist>
34440 <simpara>&#160;<?asciidoc-br?>
34441 &#160;<?asciidoc-br?>
34442 &#160;<?asciidoc-br?></simpara>
34443 <simpara><?asciidoc-hr?></simpara>
34444 <informaltable
34445 frame="all"
34446 rowsep="1" colsep="1"
34447 >
34448 <tgroup cols="2">
34449 <colspec colname="col_1" colwidth="50*"/>
34450 <colspec colname="col_2" colwidth="50*"/>
34451 <tbody>
34452 <row>
34453 <entry align="left" valign="top"><simpara><link linkend="TalkWholeProgram">Prev</link></simpara></entry>
34454 <entry align="right" valign="top"><simpara><link linkend="TalkMLtonFeatures">Next</link></simpara></entry>
34455 </row>
34456 </tbody>
34457 </tgroup>
34458 </informaltable>
34459 <simpara><?asciidoc-pagebreak?></simpara>
34460 </section>
34461 </section>
34462 <section id="TalkFromSMLTo">
34463 <title>TalkFromSMLTo</title>
34464 <section id="_from_standard_ml_to_s_t_f_o_il">
34465 <title>From Standard ML to S-T F-O IL</title>
34466 <itemizedlist>
34467 <listitem>
34468 <simpara>
34469 What issues arise when translating from Standard ML into an intermediate language?
34470 </simpara>
34471 </listitem>
34472 </itemizedlist>
34473 <simpara>&#160;<?asciidoc-br?>
34474 &#160;<?asciidoc-br?>
34475 &#160;<?asciidoc-br?></simpara>
34476 <simpara><?asciidoc-hr?></simpara>
34477 <informaltable
34478 frame="all"
34479 rowsep="1" colsep="1"
34480 >
34481 <tgroup cols="2">
34482 <colspec colname="col_1" colwidth="50*"/>
34483 <colspec colname="col_2" colwidth="50*"/>
34484 <tbody>
34485 <row>
34486 <entry align="left" valign="top"><simpara><link linkend="TalkMLtonApproach">Prev</link></simpara></entry>
34487 <entry align="right" valign="top"><simpara><link linkend="TalkHowModules">Next</link></simpara></entry>
34488 </row>
34489 </tbody>
34490 </tgroup>
34491 </informaltable>
34492 <simpara><?asciidoc-pagebreak?></simpara>
34493 </section>
34494 </section>
34495 <section id="TalkHowHigherOrder">
34496 <title>TalkHowHigherOrder</title>
34497 <section id="_higher_order_functions">
34498 <title>Higher-order Functions</title>
34499 <itemizedlist>
34500 <listitem>
34501 <simpara>
34502 How does one represent SML&#8217;s higher-order functions?
34503 </simpara>
34504 </listitem>
34505 <listitem>
34506 <simpara>
34507 MLton&#8217;s answer: defunctionalize
34508 </simpara>
34509 </listitem>
34510 </itemizedlist>
34511 <simpara>&#160;<?asciidoc-br?>
34512 &#160;<?asciidoc-br?></simpara>
34513 <simpara>See <link linkend="ClosureConvert">ClosureConvert</link>.</simpara>
34514 <simpara>&#160;<?asciidoc-br?>
34515 &#160;<?asciidoc-br?>
34516 &#160;<?asciidoc-br?></simpara>
34517 <simpara><?asciidoc-hr?></simpara>
34518 <informaltable
34519 frame="all"
34520 rowsep="1" colsep="1"
34521 >
34522 <tgroup cols="2">
34523 <colspec colname="col_1" colwidth="50*"/>
34524 <colspec colname="col_2" colwidth="50*"/>
34525 <tbody>
34526 <row>
34527 <entry align="left" valign="top"><simpara><link linkend="TalkMLtonApproach">Prev</link></simpara></entry>
34528 <entry align="right" valign="top"><simpara><link linkend="TalkWholeProgram">Next</link></simpara></entry>
34529 </row>
34530 </tbody>
34531 </tgroup>
34532 </informaltable>
34533 <simpara><?asciidoc-pagebreak?></simpara>
34534 </section>
34535 </section>
34536 <section id="TalkHowModules">
34537 <title>TalkHowModules</title>
34538 <section id="_modules">
34539 <title>Modules</title>
34540 <itemizedlist>
34541 <listitem>
34542 <simpara>
34543 How does one represent SML&#8217;s modules?
34544 </simpara>
34545 </listitem>
34546 <listitem>
34547 <simpara>
34548 MLton&#8217;s answer: defunctorize
34549 </simpara>
34550 </listitem>
34551 </itemizedlist>
34552 <simpara>&#160;<?asciidoc-br?>
34553 &#160;<?asciidoc-br?></simpara>
34554 <simpara>See <link linkend="Elaborate">Elaborate</link>.</simpara>
34555 <simpara>&#160;<?asciidoc-br?>
34556 &#160;<?asciidoc-br?>
34557 &#160;<?asciidoc-br?></simpara>
34558 <simpara><?asciidoc-hr?></simpara>
34559 <informaltable
34560 frame="all"
34561 rowsep="1" colsep="1"
34562 >
34563 <tgroup cols="2">
34564 <colspec colname="col_1" colwidth="50*"/>
34565 <colspec colname="col_2" colwidth="50*"/>
34566 <tbody>
34567 <row>
34568 <entry align="left" valign="top"><simpara><link linkend="TalkFromSMLTo">Prev</link></simpara></entry>
34569 <entry align="right" valign="top"><simpara><link linkend="TalkHowPolymorphism">Next</link></simpara></entry>
34570 </row>
34571 </tbody>
34572 </tgroup>
34573 </informaltable>
34574 <simpara><?asciidoc-pagebreak?></simpara>
34575 </section>
34576 </section>
34577 <section id="TalkHowPolymorphism">
34578 <title>TalkHowPolymorphism</title>
34579 <section id="_polymorphism">
34580 <title>Polymorphism</title>
34581 <itemizedlist>
34582 <listitem>
34583 <simpara>
34584 How does one represent SML&#8217;s polymorphism?
34585 </simpara>
34586 </listitem>
34587 <listitem>
34588 <simpara>
34589 MLton&#8217;s answer: monomorphise
34590 </simpara>
34591 </listitem>
34592 </itemizedlist>
34593 <simpara>&#160;<?asciidoc-br?>
34594 &#160;<?asciidoc-br?></simpara>
34595 <simpara>See <link linkend="Monomorphise">Monomorphise</link>.</simpara>
34596 <simpara>&#160;<?asciidoc-br?>
34597 &#160;<?asciidoc-br?>
34598 &#160;<?asciidoc-br?></simpara>
34599 <simpara><?asciidoc-hr?></simpara>
34600 <informaltable
34601 frame="all"
34602 rowsep="1" colsep="1"
34603 >
34604 <tgroup cols="2">
34605 <colspec colname="col_1" colwidth="50*"/>
34606 <colspec colname="col_2" colwidth="50*"/>
34607 <tbody>
34608 <row>
34609 <entry align="left" valign="top"><simpara><link linkend="TalkHowModules">Prev</link></simpara></entry>
34610 <entry align="right" valign="top"><simpara><link linkend="TalkHowHigherOrder">Next</link></simpara></entry>
34611 </row>
34612 </tbody>
34613 </tgroup>
34614 </informaltable>
34615 <simpara><?asciidoc-pagebreak?></simpara>
34616 </section>
34617 </section>
34618 <section id="TalkMLtonApproach">
34619 <title>TalkMLtonApproach</title>
34620 <section id="_mlton_8217_s_approach">
34621 <title>MLton&#8217;s Approach</title>
34622 <itemizedlist>
34623 <listitem>
34624 <simpara>
34625 whole-program optimization using a simply-typed, first-order intermediate language
34626 </simpara>
34627 </listitem>
34628 <listitem>
34629 <simpara>
34630 ensures programs are not penalized for exploiting abstraction and modularity
34631 </simpara>
34632 </listitem>
34633 </itemizedlist>
34634 <simpara>&#160;<?asciidoc-br?>
34635 &#160;<?asciidoc-br?>
34636 &#160;<?asciidoc-br?></simpara>
34637 <simpara><?asciidoc-hr?></simpara>
34638 <informaltable
34639 frame="all"
34640 rowsep="1" colsep="1"
34641 >
34642 <tgroup cols="2">
34643 <colspec colname="col_1" colwidth="50*"/>
34644 <colspec colname="col_2" colwidth="50*"/>
34645 <tbody>
34646 <row>
34647 <entry align="left" valign="top"><simpara><link linkend="TalkStandardML">Prev</link></simpara></entry>
34648 <entry align="right" valign="top"><simpara><link linkend="TalkFromSMLTo">Next</link></simpara></entry>
34649 </row>
34650 </tbody>
34651 </tgroup>
34652 </informaltable>
34653 <simpara><?asciidoc-pagebreak?></simpara>
34654 </section>
34655 </section>
34656 <section id="TalkMLtonFeatures">
34657 <title>TalkMLtonFeatures</title>
34658 <section id="_mlton_features">
34659 <title>MLton Features</title>
34660 <itemizedlist>
34661 <listitem>
34662 <simpara>
34663 Supports full Standard ML language and Basis Library
34664 </simpara>
34665 </listitem>
34666 <listitem>
34667 <simpara>
34668 Generates standalone executables
34669 </simpara>
34670 </listitem>
34671 <listitem>
34672 <simpara>
34673 Extensions
34674 </simpara>
34675 <itemizedlist>
34676 <listitem>
34677 <simpara>
34678 Foreign function interface (SML to C, C to SML)
34679 </simpara>
34680 </listitem>
34681 <listitem>
34682 <simpara>
34683 ML Basis system for programming in the very large
34684 </simpara>
34685 </listitem>
34686 <listitem>
34687 <simpara>
34688 Extension libraries
34689 </simpara>
34690 </listitem>
34691 </itemizedlist>
34692 </listitem>
34693 </itemizedlist>
34694 <simpara>&#160;<?asciidoc-br?>
34695 &#160;<?asciidoc-br?></simpara>
34696 <simpara>See <link linkend="Features">Features</link>.</simpara>
34697 <simpara>&#160;<?asciidoc-br?>
34698 &#160;<?asciidoc-br?>
34699 &#160;<?asciidoc-br?></simpara>
34700 <simpara><?asciidoc-hr?></simpara>
34701 <informaltable
34702 frame="all"
34703 rowsep="1" colsep="1"
34704 >
34705 <tgroup cols="2">
34706 <colspec colname="col_1" colwidth="50*"/>
34707 <colspec colname="col_2" colwidth="50*"/>
34708 <tbody>
34709 <row>
34710 <entry align="left" valign="top"><simpara><link linkend="TalkFolkLore">Prev</link></simpara></entry>
34711 <entry align="right" valign="top"><simpara><link linkend="TalkMLtonHistory">Next</link></simpara></entry>
34712 </row>
34713 </tbody>
34714 </tgroup>
34715 </informaltable>
34716 <simpara><?asciidoc-pagebreak?></simpara>
34717 </section>
34718 </section>
34719 <section id="TalkMLtonHistory">
34720 <title>TalkMLtonHistory</title>
34721 <section id="_mlton_history">
34722 <title>MLton History</title>
34723 <informaltable
34724 frame="all"
34725 rowsep="1" colsep="1"
34726 >
34727 <tgroup cols="2">
34728 <colspec colname="col_1" colwidth="25*"/>
34729 <colspec colname="col_2" colwidth="75*"/>
34730 <tbody>
34731 <row>
34732 <entry align="left" valign="top"><simpara>April 1997</simpara></entry>
34733 <entry align="left" valign="top"><simpara>Stephen Weeks wrote a defunctorizer for SML/NJ</simpara></entry>
34734 </row>
34735 <row>
34736 <entry align="left" valign="top"><simpara>Aug. 1997</simpara></entry>
34737 <entry align="left" valign="top"><simpara>Begin independent compiler (<literal>smlc</literal>)</simpara></entry>
34738 </row>
34739 <row>
34740 <entry align="left" valign="top"><simpara>Oct. 1997</simpara></entry>
34741 <entry align="left" valign="top"><simpara>Monomorphiser</simpara></entry>
34742 </row>
34743 <row>
34744 <entry align="left" valign="top"><simpara>Nov. 1997</simpara></entry>
34745 <entry align="left" valign="top"><simpara>Polyvariant higher-order control-flow analysis (10,000 lines)</simpara></entry>
34746 </row>
34747 <row>
34748 <entry align="left" valign="top"><simpara>March 1999</simpara></entry>
34749 <entry align="left" valign="top"><simpara>First release of MLton (48,006 lines)</simpara></entry>
34750 </row>
34751 <row>
34752 <entry align="left" valign="top"><simpara>Jan. 2002</simpara></entry>
34753 <entry align="left" valign="top"><simpara>MLton at 102,541 lines</simpara></entry>
34754 </row>
34755 <row>
34756 <entry align="left" valign="top"><simpara>Jan. 2003</simpara></entry>
34757 <entry align="left" valign="top"><simpara>MLton at 112,204 lines</simpara></entry>
34758 </row>
34759 <row>
34760 <entry align="left" valign="top"><simpara>Jan. 2004</simpara></entry>
34761 <entry align="left" valign="top"><simpara>MLton at 122,299 lines</simpara></entry>
34762 </row>
34763 <row>
34764 <entry align="left" valign="top"><simpara>Nov. 2004</simpara></entry>
34765 <entry align="left" valign="top"><simpara>MLton at 141,311 lines</simpara></entry>
34766 </row>
34767 </tbody>
34768 </tgroup>
34769 </informaltable>
34770 <simpara>&#160;<?asciidoc-br?>
34771 &#160;<?asciidoc-br?></simpara>
34772 <simpara>See <link linkend="History">History</link>.</simpara>
34773 <simpara>&#160;<?asciidoc-br?>
34774 &#160;<?asciidoc-br?>
34775 &#160;<?asciidoc-br?></simpara>
34776 <simpara><?asciidoc-hr?></simpara>
34777 <informaltable
34778 frame="all"
34779 rowsep="1" colsep="1"
34780 >
34781 <tgroup cols="2">
34782 <colspec colname="col_1" colwidth="50*"/>
34783 <colspec colname="col_2" colwidth="50*"/>
34784 <tbody>
34785 <row>
34786 <entry align="left" valign="top"><simpara><link linkend="TalkMLtonFeatures">Prev</link></simpara></entry>
34787 <entry align="right" valign="top"><simpara><link linkend="TalkDiveIn">Next</link></simpara></entry>
34788 </row>
34789 </tbody>
34790 </tgroup>
34791 </informaltable>
34792 <simpara><?asciidoc-pagebreak?></simpara>
34793 </section>
34794 </section>
34795 <section id="TalkStandardML">
34796 <title>TalkStandardML</title>
34797 <section id="_standard_ml">
34798 <title>Standard ML</title>
34799 <itemizedlist>
34800 <listitem>
34801 <simpara>
34802 a high-level language makes
34803 </simpara>
34804 <itemizedlist>
34805 <listitem>
34806 <simpara>
34807 a programmer&#8217;s life easier
34808 </simpara>
34809 </listitem>
34810 <listitem>
34811 <simpara>
34812 a compiler writer&#8217;s life harder
34813 </simpara>
34814 </listitem>
34815 </itemizedlist>
34816 </listitem>
34817 <listitem>
34818 <simpara>
34819 perceived overheads of features discourage their use
34820 </simpara>
34821 <itemizedlist>
34822 <listitem>
34823 <simpara>
34824 higher-order functions
34825 </simpara>
34826 </listitem>
34827 <listitem>
34828 <simpara>
34829 polymorphic datatypes
34830 </simpara>
34831 </listitem>
34832 <listitem>
34833 <simpara>
34834 separate modules
34835 </simpara>
34836 </listitem>
34837 </itemizedlist>
34838 </listitem>
34839 </itemizedlist>
34840 <simpara>&#160;<?asciidoc-br?>
34841 &#160;<?asciidoc-br?></simpara>
34842 <simpara>Also see <link linkend="StandardML">Standard ML</link>.</simpara>
34843 <simpara>&#160;<?asciidoc-br?>
34844 &#160;<?asciidoc-br?>
34845 &#160;<?asciidoc-br?></simpara>
34846 <simpara><?asciidoc-hr?></simpara>
34847 <informaltable
34848 frame="all"
34849 rowsep="1" colsep="1"
34850 >
34851 <tgroup cols="2">
34852 <colspec colname="col_1" colwidth="50*"/>
34853 <colspec colname="col_2" colwidth="50*"/>
34854 <tbody>
34855 <row>
34856 <entry align="left" valign="top"><simpara><link linkend="Talk">Prev</link></simpara></entry>
34857 <entry align="right" valign="top"><simpara><link linkend="TalkMLtonApproach">Next</link></simpara></entry>
34858 </row>
34859 </tbody>
34860 </tgroup>
34861 </informaltable>
34862 <simpara><?asciidoc-pagebreak?></simpara>
34863 </section>
34864 </section>
34865 <section id="TalkTemplate">
34866 <title>TalkTemplate</title>
34867 <section id="_title">
34868 <title>Title</title>
34869 <itemizedlist>
34870 <listitem>
34871 <simpara>
34872 Bullet
34873 </simpara>
34874 </listitem>
34875 <listitem>
34876 <simpara>
34877 Bullet
34878 </simpara>
34879 </listitem>
34880 </itemizedlist>
34881 <simpara>&#160;<?asciidoc-br?>
34882 &#160;<?asciidoc-br?>
34883 &#160;<?asciidoc-br?></simpara>
34884 <simpara><?asciidoc-hr?></simpara>
34885 <informaltable
34886 frame="all"
34887 rowsep="1" colsep="1"
34888 >
34889 <tgroup cols="2">
34890 <colspec colname="col_1" colwidth="50*"/>
34891 <colspec colname="col_2" colwidth="50*"/>
34892 <tbody>
34893 <row>
34894 <entry align="left" valign="top"><simpara><link linkend="ZZZPrev">Prev</link></simpara></entry>
34895 <entry align="right" valign="top"><simpara><link linkend="ZZZNext">Next</link></simpara></entry>
34896 </row>
34897 </tbody>
34898 </tgroup>
34899 </informaltable>
34900 <simpara><?asciidoc-pagebreak?></simpara>
34901 </section>
34902 </section>
34903 <section id="TalkWholeProgram">
34904 <title>TalkWholeProgram</title>
34905 <section id="_whole_program_compiler">
34906 <title>Whole Program Compiler</title>
34907 <itemizedlist>
34908 <listitem>
34909 <simpara>
34910 Each of these techniques requires whole-program analysis
34911 </simpara>
34912 </listitem>
34913 <listitem>
34914 <simpara>
34915 But, additional benefits:
34916 </simpara>
34917 <itemizedlist>
34918 <listitem>
34919 <simpara>
34920 eliminate (some) variability in programming styles
34921 </simpara>
34922 </listitem>
34923 <listitem>
34924 <simpara>
34925 specialize representations
34926 </simpara>
34927 </listitem>
34928 <listitem>
34929 <simpara>
34930 simplifies and improves runtime system
34931 </simpara>
34932 </listitem>
34933 </itemizedlist>
34934 </listitem>
34935 </itemizedlist>
34936 <simpara>&#160;<?asciidoc-br?>
34937 &#160;<?asciidoc-br?>
34938 &#160;<?asciidoc-br?></simpara>
34939 <simpara><?asciidoc-hr?></simpara>
34940 <informaltable
34941 frame="all"
34942 rowsep="1" colsep="1"
34943 >
34944 <tgroup cols="2">
34945 <colspec colname="col_1" colwidth="50*"/>
34946 <colspec colname="col_2" colwidth="50*"/>
34947 <tbody>
34948 <row>
34949 <entry align="left" valign="top"><simpara><link linkend="TalkHowHigherOrder">Prev</link></simpara></entry>
34950 <entry align="right" valign="top"><simpara><link linkend="TalkFolkLore">Next</link></simpara></entry>
34951 </row>
34952 </tbody>
34953 </tgroup>
34954 </informaltable>
34955 <simpara><?asciidoc-pagebreak?></simpara>
34956 </section>
34957 </section>
34958 <section id="TILT">
34959 <title>TILT</title>
34960 <simpara><ulink url="http://www.cs.cornell.edu/home/jgm/tilt.html">TILT</ulink> is a
34961 <link linkend="StandardMLImplementations">Standard ML implementation</link>.</simpara>
34962 <simpara><?asciidoc-pagebreak?></simpara>
34963 </section>
34964 <section id="TipsForWritingConciseSML">
34965 <title>TipsForWritingConciseSML</title>
34966 <simpara>SML is a rich enough language that there are often several ways to
34967 express things. This page contains miscellaneous tips (ideas not
34968 rules) for writing concise SML. The metric that we are interested in
34969 here is the number of tokens or words (rather than the number of
34970 lines, for example).</simpara>
34971 <section id="_datatypes_in_signatures">
34972 <title>Datatypes in Signatures</title>
34973 <simpara>A seemingly frequent source of repetition in SML is that of datatype
34974 definitions in signatures and structures. Actually, it isn&#8217;t
34975 repetition at all. A datatype specification in a signature, such as,</simpara>
34976 <programlisting language="sml" linenumbering="unnumbered">signature EXP = sig
34977 datatype exp = Fn of id * exp | App of exp * exp | Var of id
34978 end</programlisting>
34979 <simpara>is just a specification of a datatype that may be matched by multiple
34980 (albeit identical) datatype declarations. For example, in</simpara>
34981 <programlisting language="sml" linenumbering="unnumbered">structure AnExp : EXP = struct
34982 datatype exp = Fn of id * exp | App of exp * exp | Var of id
34983 end
34984
34985 structure AnotherExp : EXP = struct
34986 datatype exp = Fn of id * exp | App of exp * exp | Var of id
34987 end</programlisting>
34988 <simpara>the types <literal>AnExp.exp</literal> and <literal>AnotherExp.exp</literal> are two distinct types. If
34989 such <link linkend="GenerativeDatatype">generativity</link> isn&#8217;t desired or needed, you
34990 can avoid the repetition:</simpara>
34991 <programlisting language="sml" linenumbering="unnumbered">structure Exp = struct
34992 datatype exp = Fn of id * exp | App of exp * exp | Var of id
34993 end
34994
34995 signature EXP = sig
34996 datatype exp = datatype Exp.exp
34997 end
34998
34999 structure Exp : EXP = struct
35000 open Exp
35001 end</programlisting>
35002 <simpara>Keep in mind that this isn&#8217;t semantically equivalent to the original.</simpara>
35003 </section>
35004 <section id="_clausal_function_definitions">
35005 <title>Clausal Function Definitions</title>
35006 <simpara>The syntax of clausal function definitions is rather repetitive. For
35007 example,</simpara>
35008 <programlisting language="sml" linenumbering="unnumbered">fun isSome NONE = false
35009 | isSome (SOME _) = true</programlisting>
35010 <simpara>is more verbose than</simpara>
35011 <programlisting language="sml" linenumbering="unnumbered">val isSome =
35012 fn NONE =&gt; false
35013 | SOME _ =&gt; true</programlisting>
35014 <simpara>For recursive functions the break-even point is one clause higher. For example,</simpara>
35015 <programlisting language="sml" linenumbering="unnumbered">fun fib 0 = 0
35016 | fib 1 = 1
35017 | fib n = fib (n-1) + fib (n-2)</programlisting>
35018 <simpara>isn&#8217;t less verbose than</simpara>
35019 <programlisting language="sml" linenumbering="unnumbered">val rec fib =
35020 fn 0 =&gt; 0
35021 | 1 =&gt; 1
35022 | n =&gt; fib (n-1) + fib (n-2)</programlisting>
35023 <simpara>It is quite often the case that a curried function primarily examines
35024 just one of its arguments. Such functions can be written particularly
35025 concisely by making the examined argument last. For example, instead
35026 of</simpara>
35027 <programlisting language="sml" linenumbering="unnumbered">fun eval (Fn (v, b)) env =&gt; ...
35028 | eval (App (f, a) env =&gt; ...
35029 | eval (Var v) env =&gt; ...</programlisting>
35030 <simpara>consider writing</simpara>
35031 <programlisting language="sml" linenumbering="unnumbered">fun eval env =
35032 fn Fn (v, b) =&gt; ...
35033 | App (f, a) =&gt; ...
35034 | Var v =&gt; ...</programlisting>
35035 </section>
35036 <section id="_parentheses">
35037 <title>Parentheses</title>
35038 <simpara>It is a good idea to avoid using lots of irritating superfluous
35039 parentheses. An important rule to know is that prefix function
35040 application in SML has higher precedence than any infix operator. For
35041 example, the outer parentheses in</simpara>
35042 <programlisting language="sml" linenumbering="unnumbered">(square (5 + 1)) + (square (5 * 2))</programlisting>
35043 <simpara>are superfluous.</simpara>
35044 <simpara>People trained in other languages often use superfluous parentheses in
35045 a number of places. In particular, the parentheses in the following
35046 examples are practically always superfluous and are best avoided:</simpara>
35047 <programlisting language="sml" linenumbering="unnumbered">if (condition) then ... else ...
35048 while (condition) do ...</programlisting>
35049 <simpara>The same basically applies to case expressions:</simpara>
35050 <programlisting language="sml" linenumbering="unnumbered">case (expression) of ...</programlisting>
35051 <simpara>It is not uncommon to match a tuple of two or more values:</simpara>
35052 <programlisting language="sml" linenumbering="unnumbered">case (a, b) of
35053 (A1, B1) =&gt; ...
35054 | (A2, B2) =&gt; ...</programlisting>
35055 <simpara>Such case expressions can be written more concisely with an
35056 <link linkend="ProductType">infix product constructor</link>:</simpara>
35057 <programlisting language="sml" linenumbering="unnumbered">case a &amp; b of
35058 A1 &amp; B1 =&gt; ...
35059 | A2 &amp; B2 =&gt; ...</programlisting>
35060 </section>
35061 <section id="_conditionals">
35062 <title>Conditionals</title>
35063 <simpara>Repeated sequences of conditionals such as</simpara>
35064 <programlisting language="sml" linenumbering="unnumbered">if x &lt; y then ...
35065 else if x = y then ...
35066 else ...</programlisting>
35067 <simpara>can often be written more concisely as case expressions such as</simpara>
35068 <programlisting language="sml" linenumbering="unnumbered">case Int.compare (x, y) of
35069 LESS =&gt; ...
35070 | EQUAL =&gt; ...
35071 | GREATER =&gt; ...</programlisting>
35072 <simpara>For a custom comparison, you would then define an appropriate datatype
35073 and a reification function. An alternative to using datatypes is to
35074 use dispatch functions</simpara>
35075 <programlisting language="sml" linenumbering="unnumbered">comparing (x, y)
35076 {lt = fn () =&gt; ...,
35077 eq = fn () =&gt; ...,
35078 gt = fn () =&gt; ...}</programlisting>
35079 <simpara>where</simpara>
35080 <programlisting language="sml" linenumbering="unnumbered">fun comparing (x, y) {lt, eq, gt} =
35081 (case Int.compare (x, y) of
35082 LESS =&gt; lt
35083 | EQUAL =&gt; eq
35084 | GREATER =&gt; gt) ()</programlisting>
35085 <simpara>An advantage is that no datatype definition is needed. A disadvantage
35086 is that you can&#8217;t combine multiple dispatch results easily.</simpara>
35087 </section>
35088 <section id="_command_query_fusion">
35089 <title>Command-Query Fusion</title>
35090 <simpara>Many are familiar with the
35091 <ulink url="http://en.wikipedia.org/wiki/Command-Query_Separation">Command-Query
35092 Separation Principle</ulink>. Adhering to the principle, a signature for an
35093 imperative stack might contain specifications</simpara>
35094 <programlisting language="sml" linenumbering="unnumbered">val isEmpty : 'a t -&gt; bool
35095 val pop : 'a t -&gt; 'a</programlisting>
35096 <simpara>and use of a stack would look like</simpara>
35097 <programlisting language="sml" linenumbering="unnumbered">if isEmpty stack
35098 then ... pop stack ...
35099 else ...</programlisting>
35100 <simpara>or, when the element needs to be named,</simpara>
35101 <programlisting language="sml" linenumbering="unnumbered">if isEmpty stack
35102 then let val elem = pop stack in ... end
35103 else ...</programlisting>
35104 <simpara>For efficiency, correctness, and conciseness, it is often better to
35105 combine the query and command and return the result as an option:</simpara>
35106 <programlisting language="sml" linenumbering="unnumbered">val pop : 'a t -&gt; 'a option</programlisting>
35107 <simpara>A use of a stack would then look like this:</simpara>
35108 <programlisting language="sml" linenumbering="unnumbered">case pop stack of
35109 NONE =&gt; ...
35110 | SOME elem =&gt; ...</programlisting>
35111 <simpara><?asciidoc-pagebreak?></simpara>
35112 </section>
35113 </section>
35114 <section id="ToMachine">
35115 <title>ToMachine</title>
35116 <simpara><link linkend="ToMachine">ToMachine</link> is a translation pass from the <link linkend="RSSA">RSSA</link>
35117 <link linkend="IntermediateLanguage">IntermediateLanguage</link> to the <link linkend="Machine">Machine</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>.</simpara>
35118 <section id="_description_61">
35119 <title>Description</title>
35120 <simpara>This pass converts from a <link linkend="RSSA">RSSA</link> program into a <link linkend="Machine">Machine</link> program.</simpara>
35121 <simpara>It uses <link linkend="AllocateRegisters">AllocateRegisters</link>, <link linkend="Chunkify">Chunkify</link>, and <link linkend="ParallelMove">ParallelMove</link>.</simpara>
35122 </section>
35123 <section id="_implementation_66">
35124 <title>Implementation</title>
35125 <itemizedlist>
35126 <listitem>
35127 <simpara>
35128 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/backend.sig"><literal>backend.sig</literal></ulink>
35129 </simpara>
35130 </listitem>
35131 <listitem>
35132 <simpara>
35133 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/backend.fun"><literal>backend.fun</literal></ulink>
35134 </simpara>
35135 </listitem>
35136 </itemizedlist>
35137 </section>
35138 <section id="_details_and_notes_64">
35139 <title>Details and Notes</title>
35140 <simpara>Because the MLton runtime system is shared by all <link linkend="Codegen">codegens</link>, it is most
35141 convenient to decide on stack layout <emphasis>before</emphasis> any <link linkend="Codegen">codegen</link> takes over.
35142 In particular, we compute all the stack frame info for each <link linkend="RSSA">RSSA</link>
35143 function, including stack size, <link linkend="GarbageCollection">garbage collector</link>
35144 masks for each frame, etc. To do so, the <link linkend="Machine">Machine</link>
35145 <link linkend="IntermediateLanguage">IntermediateLanguage</link> imagines an abstract machine with an infinite
35146 number of (pseudo-)registers of every size. A liveness analysis
35147 determines, for each variable, whether or not it is live across a
35148 point where the runtime system might take over (for example, any
35149 garbage collection point) or a non-tail call to another <link linkend="RSSA">RSSA</link>
35150 function. Those that are live go on the stack, while those that
35151 aren&#8217;t live go into psuedo-registers. From this information, we know
35152 all we need to about each stack frame. On the downside, nothing
35153 further on is allowed to change this stack info; it is set in stone.</simpara>
35154 <simpara><?asciidoc-pagebreak?></simpara>
35155 </section>
35156 </section>
35157 <section id="TomMurphy">
35158 <title>TomMurphy</title>
35159 <simpara>Tom Murphy VII is a long time MLton user and occasional contributor. He works on programming languages for his PhD work at Carnegie Mellon in Pittsburgh, USA. <link linkend="AdamGoode">AdamGoode</link> lives on the same floor of Wean Hall.</simpara>
35160 <simpara><ulink url="http://tom7.org">Home page</ulink></simpara>
35161 <simpara><?asciidoc-pagebreak?></simpara>
35162 </section>
35163 <section id="ToRSSA">
35164 <title>ToRSSA</title>
35165 <simpara><link linkend="ToRSSA">ToRSSA</link> is a translation pass from the <link linkend="SSA2">SSA2</link>
35166 <link linkend="IntermediateLanguage">IntermediateLanguage</link> to the <link linkend="RSSA">RSSA</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>.</simpara>
35167 <section id="_description_62">
35168 <title>Description</title>
35169 <simpara>This pass converts a <link linkend="SSA2">SSA2</link> program into a <link linkend="RSSA">RSSA</link> program.</simpara>
35170 <simpara>It uses <link linkend="PackedRepresentation">PackedRepresentation</link>.</simpara>
35171 </section>
35172 <section id="_implementation_67">
35173 <title>Implementation</title>
35174 <itemizedlist>
35175 <listitem>
35176 <simpara>
35177 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/ssa-to-rssa.sig"><literal>ssa-to-rssa.sig</literal></ulink>
35178 </simpara>
35179 </listitem>
35180 <listitem>
35181 <simpara>
35182 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/backend/ssa-to-rssa.fun"><literal>ssa-to-rssa.fun</literal></ulink>
35183 </simpara>
35184 </listitem>
35185 </itemizedlist>
35186 </section>
35187 <section id="_details_and_notes_65">
35188 <title>Details and Notes</title>
35189 <simpara></simpara>
35190 <simpara><?asciidoc-pagebreak?></simpara>
35191 </section>
35192 </section>
35193 <section id="ToSSA2">
35194 <title>ToSSA2</title>
35195 <simpara><link linkend="ToSSA2">ToSSA2</link> is a translation pass from the <link linkend="SSA">SSA</link>
35196 <link linkend="IntermediateLanguage">IntermediateLanguage</link> to the <link linkend="SSA2">SSA2</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link>.</simpara>
35197 <section id="_description_63">
35198 <title>Description</title>
35199 <simpara>This pass is a simple conversion from a <link linkend="SSA">SSA</link> program into a
35200 <link linkend="SSA2">SSA2</link> program.</simpara>
35201 <simpara>The only interesting portions of the translation are:</simpara>
35202 <itemizedlist>
35203 <listitem>
35204 <simpara>
35205 an <link linkend="SSA">SSA</link> <literal>ref</literal> type becomes an object with a single mutable field
35206 </simpara>
35207 </listitem>
35208 <listitem>
35209 <simpara>
35210 <literal>array</literal>, <literal>vector</literal>, and <literal>ref</literal> are eliminated in favor of select and updates
35211 </simpara>
35212 </listitem>
35213 <listitem>
35214 <simpara>
35215 <literal>Case</literal> transfers separate discrimination and constructor argument selects
35216 </simpara>
35217 </listitem>
35218 </itemizedlist>
35219 </section>
35220 <section id="_implementation_68">
35221 <title>Implementation</title>
35222 <itemizedlist>
35223 <listitem>
35224 <simpara>
35225 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ssa-to-ssa2.sig"><literal>ssa-to-ssa2.sig</literal></ulink>
35226 </simpara>
35227 </listitem>
35228 <listitem>
35229 <simpara>
35230 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/ssa-to-ssa2.fun"><literal>ssa-to-ssa2.fun</literal></ulink>
35231 </simpara>
35232 </listitem>
35233 </itemizedlist>
35234 </section>
35235 <section id="_details_and_notes_66">
35236 <title>Details and Notes</title>
35237 <simpara></simpara>
35238 <simpara><?asciidoc-pagebreak?></simpara>
35239 </section>
35240 </section>
35241 <section id="TypeChecking">
35242 <title>TypeChecking</title>
35243 <simpara>MLton&#8217;s type checker follows the <link linkend="DefinitionOfStandardML">Definition</link>
35244 closely, so you may find differences between MLton and other SML
35245 compilers that do not follow the Definition so closely. In
35246 particular, SML/NJ has many deviations from the Definition&#8201;&#8212;&#8201;please
35247 see <link linkend="SMLNJDeviations">SMLNJDeviations</link> for those that we are aware of.</simpara>
35248 <simpara>In some respects MLton&#8217;s type checker is more powerful than other SML
35249 compilers, so there are programs that MLton accepts that are rejected
35250 by some other SML compilers. These kinds of programs fall into a few
35251 simple categories.</simpara>
35252 <itemizedlist>
35253 <listitem>
35254 <simpara>
35255 MLton resolves flexible record patterns using a larger context than
35256 many other SML compilers. For example, MLton accepts the
35257 following.
35258 </simpara>
35259 <programlisting language="sml" linenumbering="unnumbered">fun f {x, ...} = x
35260 val _ = f {x = 13, y = "foo"}</programlisting>
35261 </listitem>
35262 <listitem>
35263 <simpara>
35264 MLton uses as large a context as possible to resolve the type of
35265 variables constrained by the value restriction to be monotypes. For
35266 example, MLton accepts the following.
35267 </simpara>
35268 <programlisting language="sml" linenumbering="unnumbered">structure S:
35269 sig
35270 val f: int -&gt; int
35271 end =
35272 struct
35273 val f = (fn x =&gt; x) (fn y =&gt; y)
35274 end</programlisting>
35275 </listitem>
35276 </itemizedlist>
35277 <section id="_type_error_messages">
35278 <title>Type error messages</title>
35279 <simpara>To aid in the understanding of type errors, MLton&#8217;s type checker
35280 displays type errors differently than other SML compilers. In
35281 particular, when two types are different, it is important for the
35282 programmer to easily understand why they are different. So, MLton
35283 displays only the differences between two types that don&#8217;t match,
35284 using underscores for the parts that match. For example, if a
35285 function expects <literal>real * int</literal> but gets <literal>real * real</literal>, the type error
35286 message would look like</simpara>
35287 <screen>expects: _ * [int]
35288 but got: _ * [real]</screen>
35289 <simpara>As another aid to spotting differences, MLton places brackets <literal>[]</literal>
35290 around the parts of the types that don&#8217;t match. A common situation is
35291 when a function receives a different number of arguments than it
35292 expects, in which case you might see an error like</simpara>
35293 <screen>expects: [int * real]
35294 but got: [int * real * string]</screen>
35295 <simpara>The brackets make it easy to see that the problem is that the tuples
35296 have different numbers of components&#8201;&#8212;&#8201;not that the components don&#8217;t
35297 match. Contrast that with a case where a function receives the right
35298 number of arguments, but in the wrong order, in which case you might
35299 see an error like</simpara>
35300 <screen>expects: [int] * [real]
35301 but got: [real] * [int]</screen>
35302 <simpara>Here the brackets make it easy to see that the components do not match.</simpara>
35303 <simpara>We appreciate feedback on any type error messages that you find
35304 confusing, or suggestions you may have for improvements to error
35305 messages.</simpara>
35306 </section>
35307 <section id="_the_shortest_most_recent_rule_for_type_names">
35308 <title>The shortest/most-recent rule for type names</title>
35309 <simpara>In a type error message, MLton often has a number of choices in
35310 deciding what name to use for a type. For example, in the following
35311 type-incorrect program</simpara>
35312 <programlisting language="sml" linenumbering="unnumbered">type t = int
35313 fun f (x: t) = x
35314 val _ = f "foo"</programlisting>
35315 <simpara>MLton reports the error message</simpara>
35316 <screen>Error: z.sml 3.9-3.15.
35317 Function applied to incorrect argument.
35318 expects: [t]
35319 but got: [string]
35320 in: f "foo"</screen>
35321 <simpara>MLton could have reported <literal>expects: [int]</literal> instead of <literal>expects: [t]</literal>.
35322 However, MLton uses the shortest/most-recent rule in order to decide
35323 what type name to display. This rule means that, at the point of the
35324 error, MLton first looks for the shortest name for a type in terms of
35325 number of structure identifiers (e.g. <literal>foobar</literal> is shorter than <literal>A.t</literal>).
35326 Next, if there are multiple names of the same length, then MLton uses
35327 the most recently defined name. It is this tiebreaker that causes
35328 MLton to prefer <literal>t</literal> to <literal>int</literal> in the above example.</simpara>
35329 <simpara>In signature matching, most recently defined is not taken to include
35330 all of the definitions introduced by the structure (since the matching
35331 takes place outside the structure and before it is defined). For
35332 example, in the following type-incorrect program</simpara>
35333 <programlisting language="sml" linenumbering="unnumbered">structure S:
35334 sig
35335 val x: int
35336 end =
35337 struct
35338 type t = int
35339 val x = "foo"
35340 end</programlisting>
35341 <simpara>MLton reports the error message</simpara>
35342 <screen>Error: z.sml 2.4-4.6.
35343 Variable in structure disagrees with signature (type): x.
35344 structure: val x: [string]
35345 defn at: z.sml 7.11-7.11
35346 signature: val x: [int]
35347 spec at: z.sml 3.11-3.11</screen>
35348 <simpara>If there is a type that only exists inside the structure being
35349 matched, then the prefix <literal>_str.</literal> is used. For example, in the
35350 following type-incorrect program</simpara>
35351 <programlisting language="sml" linenumbering="unnumbered">structure S:
35352 sig
35353 val x: int
35354 end =
35355 struct
35356 datatype t = T
35357 val x = T
35358 end</programlisting>
35359 <simpara>MLton reports the error message</simpara>
35360 <screen>Error: z.sml 2.4-4.6.
35361 Variable in structure disagrees with signature (type): x.
35362 structure: val x: [_str.t]
35363 defn at: z.sml 7.11-7.11
35364 signature: val x: [int]
35365 spec at: z.sml 3.11-3.11</screen>
35366 <simpara>in which the <literal>[_str.t]</literal> refers to the type defined in the structure.</simpara>
35367 <simpara><?asciidoc-pagebreak?></simpara>
35368 </section>
35369 </section>
35370 <section id="TypeConstructor">
35371 <title>TypeConstructor</title>
35372 <simpara>In <link linkend="StandardML">Standard ML</link>, a type constructor is a function from
35373 types to types. Type constructors can be <emphasis>nullary</emphasis>, meaning that
35374 they take no arguments, as in <literal>char</literal>, <literal>int</literal>, and <literal>real</literal>.
35375 Type constructors can be <emphasis>unary</emphasis>, meaning that they take one
35376 argument, as in <literal>array</literal>, <literal>list</literal>, and <literal>vector</literal>. A program
35377 can define a new type constructor in two ways: a <literal>type</literal> definition
35378 or a <literal>datatype</literal> declaration. User-defined type constructors can
35379 can take any number of arguments.</simpara>
35380 <programlisting language="sml" linenumbering="unnumbered">datatype t = T of int * real (* 0 arguments *)
35381 type 'a t = 'a * int (* 1 argument *)
35382 datatype ('a, 'b) t = A | B of 'a * 'b (* 2 arguments *)
35383 type ('a, 'b, 'c) t = 'a * ('b -&gt; 'c) (* 3 arguments *)</programlisting>
35384 <simpara>Here are the syntax rules for type constructor application.</simpara>
35385 <itemizedlist>
35386 <listitem>
35387 <simpara>
35388 Type constructor application is written in postfix. So, one writes
35389 <literal>int list</literal>, not <literal>list int</literal>.
35390 </simpara>
35391 </listitem>
35392 <listitem>
35393 <simpara>
35394 Unary type constructors drop the parens, so one writes
35395 <literal>int list</literal>, not <literal>(int) list</literal>.
35396 </simpara>
35397 </listitem>
35398 <listitem>
35399 <simpara>
35400 Nullary type constructors drop the argument entirely, so one writes
35401 <literal>int</literal>, not <literal>() int</literal>.
35402 </simpara>
35403 </listitem>
35404 <listitem>
35405 <simpara>
35406 N-ary type constructors use tuple notation; for example,
35407 <literal>(int, real) t</literal>.
35408 </simpara>
35409 </listitem>
35410 <listitem>
35411 <simpara>
35412 Type constructor application associates to the left. So,
35413 <literal>int ref list</literal> is the same as <literal>(int ref) list</literal>.
35414 </simpara>
35415 </listitem>
35416 </itemizedlist>
35417 <simpara><?asciidoc-pagebreak?></simpara>
35418 </section>
35419 <section id="TypeIndexedValues">
35420 <title>TypeIndexedValues</title>
35421 <simpara><link linkend="StandardML">Standard ML</link> does not support ad hoc polymorphism. This
35422 presents a challenge to programmers. The problem is that at first
35423 glance there seems to be no practical way to implement something like
35424 a function for converting a value of any type to a string or a
35425 function for computing a hash value for a value of any type.
35426 Fortunately there are ways to implement type-indexed values in SML as
35427 discussed in <link linkend="References_Yang98">Yang98</link>. Various articles such as
35428 <link linkend="References_Danvy98">Danvy98</link>, <link linkend="References_Ramsey11">Ramsey11</link>, <link linkend="References_Elsman04">Elsman04</link>,
35429 <link linkend="References_Kennedy04">Kennedy04</link>, and <link linkend="References_Benton05">Benton05</link> also contain examples of
35430 type-indexed values.</simpara>
35431 <simpara><emphasis role="strong">NOTE:</emphasis> The technique used in the following example uses an early (and
35432 somewhat broken) variation of the basic technique used in an
35433 experimental generic programming library (see
35434 <ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/generic/unstable/README"><literal>README</literal></ulink>) that can
35435 be found from the MLton repository. The generic programming library
35436 also includes a more advanced generic pretty printing function (see
35437 <ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/generic/unstable/public/value/pretty.sig"><literal>pretty.sig</literal></ulink>).</simpara>
35438 <section id="_example_converting_any_sml_value_to_roughly_sml_syntax">
35439 <title>Example: Converting any SML value to (roughly) SML syntax</title>
35440 <simpara>Consider the problem of converting any SML value to a textual
35441 presentation that matches the syntax of SML as closely as possible.
35442 One solution is a type-indexed function that maps a given type to a
35443 function that maps any value (of the type) to its textual
35444 presentation. A type-indexed function like this can be useful for a
35445 variety of purposes. For example, one could use it to show debugging
35446 information. We&#8217;ll call this function "<literal>show</literal>".</simpara>
35447 <simpara>We&#8217;ll do a fairly complete implementation of <literal>show</literal>. We do not
35448 distinguish infix and nonfix constructors, but that is not an
35449 intrinsic property of SML datatypes. We also don&#8217;t reconstruct a type
35450 name for the value, although it would be particularly useful for
35451 functional values. To reconstruct type names, some changes would be
35452 needed and the reader is encouraged to consider how to do that. A
35453 more realistic implementation would use some pretty printing
35454 combinators to compute a layout for the result. This should be a
35455 relatively easy change (given a suitable pretty printing library).
35456 Cyclic values (through references and arrays) do not have a standard
35457 textual presentation and it is impossible to convert arbitrary
35458 functional values (within SML) to a meaningful textual presentation.
35459 Finally, it would also make sense to show sharing of references and
35460 arrays. We&#8217;ll leave these improvements to an actual library
35461 implementation.</simpara>
35462 <simpara>The following code uses the <link linkend="Fixpoints">fixpoint framework</link> and other
35463 utilities from an Extended Basis library (see
35464 <ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/extended-basis/unstable/README"><literal>README</literal></ulink>).</simpara>
35465 <section id="_signature">
35466 <title>Signature</title>
35467 <simpara>Let&#8217;s consider the design of the <literal>SHOW</literal> signature:</simpara>
35468 <programlisting language="sml" linenumbering="unnumbered">infixr --&gt;
35469
35470 signature SHOW = sig
35471 type 'a t (* complete type-index *)
35472 type 'a s (* incomplete sum *)
35473 type ('a, 'k) p (* incomplete product *)
35474 type u (* tuple or unlabelled product *)
35475 type l (* record or labelled product *)
35476
35477 val show : 'a t -&gt; 'a -&gt; string
35478
35479 (* user-defined types *)
35480 val inj : ('a -&gt; 'b) -&gt; 'b t -&gt; 'a t
35481
35482 (* tuples and records *)
35483 val * : ('a, 'k) p * ('b, 'k) p -&gt; (('a, 'b) product, 'k) p
35484
35485 val U : 'a t -&gt; ('a, u) p
35486 val L : string -&gt; 'a t -&gt; ('a, l) p
35487
35488 val tuple : ('a, u) p -&gt; 'a t
35489 val record : ('a, l) p -&gt; 'a t
35490
35491 (* datatypes *)
35492 val + : 'a s * 'b s -&gt; (('a, 'b) sum) s
35493
35494 val C0 : string -&gt; unit s
35495 val C1 : string -&gt; 'a t -&gt; 'a s
35496
35497 val data : 'a s -&gt; 'a t
35498
35499 val Y : 'a t Tie.t
35500
35501 (* exceptions *)
35502 val exn : exn t
35503 val regExn : (exn -&gt; ('a * 'a s) option) -&gt; unit
35504
35505 (* some built-in type constructors *)
35506 val refc : 'a t -&gt; 'a ref t
35507 val array : 'a t -&gt; 'a array t
35508 val list : 'a t -&gt; 'a list t
35509 val vector : 'a t -&gt; 'a vector t
35510 val --&gt; : 'a t * 'b t -&gt; ('a -&gt; 'b) t
35511
35512 (* some built-in base types *)
35513 val string : string t
35514 val unit : unit t
35515 val bool : bool t
35516 val char : char t
35517 val int : int t
35518 val word : word t
35519 val real : real t
35520 end</programlisting>
35521 <simpara>While some details are shaped by the specific requirements of <literal>show</literal>,
35522 there are a number of (design) patterns that translate to other
35523 type-indexed values. The former kind of details are mostly shaped by
35524 the syntax of SML values that <literal>show</literal> is designed to produce. To this
35525 end, abstract types and phantom types are used to distinguish
35526 incomplete record, tuple, and datatype type-indices from each other
35527 and from complete type-indices. Also, names of record labels and
35528 datatype constructors need to be provided by the user.</simpara>
35529 <section id="_arbitrary_user_defined_datatypes">
35530 <title>Arbitrary user-defined datatypes</title>
35531 <simpara>Perhaps the most important pattern is how the design supports
35532 arbitrary user-defined datatypes. A number of combinators together
35533 conspire to provide the functionality. First of all, to support new
35534 user-defined types, a combinator taking a conversion function to a
35535 previously supported type is provided:</simpara>
35536 <programlisting language="sml" linenumbering="unnumbered">val inj : ('a -&gt; 'b) -&gt; 'b t -&gt; 'a t</programlisting>
35537 <simpara>An injection function is sufficient in this case, but in the general
35538 case, an embedding with injection and projection functions may be
35539 needed.</simpara>
35540 <simpara>To support products (tuples and records) a product combinator is
35541 provided:</simpara>
35542 <programlisting language="sml" linenumbering="unnumbered">val * : ('a, 'k) p * ('b, 'k) p -&gt; (('a, 'b) product, 'k) p</programlisting>
35543 <simpara>The second (phantom) type variable <literal>'k</literal> is there to distinguish
35544 between labelled and unlabelled products and the type <literal>p</literal>
35545 distinguishes incomplete products from complete type-indices of type
35546 <literal>t</literal>. Most type-indexed values do not need to make such distinctions.</simpara>
35547 <simpara>To support sums (datatypes) a sum combinator is provided:</simpara>
35548 <programlisting language="sml" linenumbering="unnumbered">val + : 'a s * 'b s -&gt; (('a, 'b) sum) s</programlisting>
35549 <simpara>Again, the purpose of the type <literal>s</literal> is to distinguish incomplete sums
35550 from complete type-indices of type <literal>t</literal>, which usually isn&#8217;t necessary.</simpara>
35551 <simpara>Finally, to support recursive datatypes, including sets of mutually
35552 recursive datatypes, a <link linkend="Fixpoints">fixpoint tier</link> is provided:</simpara>
35553 <programlisting language="sml" linenumbering="unnumbered">val Y : 'a t Tie.t</programlisting>
35554 <simpara>Together these combinators (with the more domain specific combinators
35555 <literal>U</literal>, <literal>L</literal>, <literal>tuple</literal>, <literal>record</literal>, <literal>C0</literal>, <literal>C1</literal>, and <literal>data</literal>) enable one to
35556 encode a type-index for any user-defined datatype.</simpara>
35557 </section>
35558 <section id="_exceptions">
35559 <title>Exceptions</title>
35560 <simpara>The <literal>exn</literal> type in SML is a <link linkend="UniversalType">universal type</link> into which
35561 all types can be embedded. SML also allows a program to generate new
35562 exception variants at run-time. Thus a mechanism is required to register
35563 handlers for particular variants:</simpara>
35564 <programlisting language="sml" linenumbering="unnumbered">val exn : exn t
35565 val regExn : (exn -&gt; ('a * 'a s) option) -&gt; unit</programlisting>
35566 <simpara>The universal <literal>exn</literal> type-index then makes use of the registered
35567 handlers. The above particular form of handler, which converts an
35568 exception value to a value of some type and a type-index for that type
35569 (essentially an existential type) is designed to make it convenient to
35570 write handlers. To write a handler, one can conveniently reuse
35571 existing type-indices:</simpara>
35572 <programlisting language="sml" linenumbering="unnumbered">exception Int of int
35573
35574 local
35575 open Show
35576 in
35577 val () = regExn (fn Int v =&gt; SOME (v, C1"Int" int)
35578 | _ =&gt; NONE)
35579 end</programlisting>
35580 <simpara>Note that a single handler may actually handle an arbitrary number of
35581 different exceptions.</simpara>
35582 </section>
35583 <section id="_other_types">
35584 <title>Other types</title>
35585 <simpara>Some built-in and standard types typically require special treatment
35586 due to their special nature. The most important of these are arrays
35587 and references, because cyclic data (ignoring closures) and observable
35588 sharing can only be constructed through them.</simpara>
35589 <simpara>When arrow types are really supported, unlike in this case, they
35590 usually need special treatment due to the contravariance of arguments.</simpara>
35591 <simpara>Lists and vectors require special treatment in the case of <literal>show</literal>,
35592 because of their special syntax. This isn&#8217;t usually the case.</simpara>
35593 <simpara>The set of base types to support also needs to be considered unless
35594 one exports an interface for constructing type-indices for entirely
35595 new base types.</simpara>
35596 </section>
35597 </section>
35598 </section>
35599 <section id="_usage_9">
35600 <title>Usage</title>
35601 <simpara>Before going to the implementation, let&#8217;s look at some examples. For
35602 the following examples, we&#8217;ll assume a structure binding
35603 <literal>Show :&gt; SHOW</literal>. If you want to try the examples immediately, just
35604 skip forward to the implementation.</simpara>
35605 <simpara>To use <literal>show</literal>, one first needs a type-index, which is then given to
35606 <literal>show</literal>. To show a list of integers, one would use the type-index
35607 <literal>list int</literal>, which has the type <literal>int list Show.t</literal>:</simpara>
35608 <programlisting language="sml" linenumbering="unnumbered">val "[3, 1, 4]" =
35609 let open Show in show (list int) end
35610 [3, 1, 4]</programlisting>
35611 <simpara>Likewise, to show a list of lists of characters, one would use the
35612 type-index <literal>list (list char)</literal>, which has the type <literal>char list list
35613 Show.t</literal>:</simpara>
35614 <programlisting language="sml" linenumbering="unnumbered">val "[[#\"a\", #\"b\", #\"c\"], []]" =
35615 let open Show in show (list (list char)) end
35616 [[#"a", #"b", #"c"], []]</programlisting>
35617 <simpara>Handling standard types is not particularly interesting. It is more
35618 interesting to see how user-defined types can be handled. Although
35619 the <literal>option</literal> datatype is a standard type, it requires no special
35620 support, so we can treat it as a user-defined type. Options can be
35621 encoded easily using a sum:</simpara>
35622 <programlisting language="sml" linenumbering="unnumbered">fun option t = let
35623 open Show
35624 in
35625 inj (fn NONE =&gt; INL ()
35626 | SOME v =&gt; INR v)
35627 (data (C0"NONE" + C1"SOME" t))
35628 end
35629
35630 val "SOME 5" =
35631 let open Show in show (option int) end
35632 (SOME 5)</programlisting>
35633 <simpara>Readers new to type-indexed values might want to type annotate each
35634 subexpression of the above example as an exercise. (Use a compiler to
35635 check your annotations.)</simpara>
35636 <simpara>Using a product, user specified records can be also be encoded easily:</simpara>
35637 <programlisting language="sml" linenumbering="unnumbered">val abc = let
35638 open Show
35639 in
35640 inj (fn {a, b, c} =&gt; a &amp; b &amp; c)
35641 (record (L"a" (option int) *
35642 L"b" real *
35643 L"c" bool))
35644 end
35645
35646 val "{a = SOME 1, b = 3.0, c = false}" =
35647 let open Show in show abc end
35648 {a = SOME 1, b = 3.0, c = false}</programlisting>
35649 <simpara>As you can see, both of the above use <literal>inj</literal> to inject user-defined
35650 types to the general purpose sum and product types.</simpara>
35651 <simpara>Of particular interest is whether recursive datatypes and cyclic data
35652 can be handled. For example, how does one write a type-index for a
35653 recursive datatype such as a cyclic graph?</simpara>
35654 <programlisting language="sml" linenumbering="unnumbered">datatype 'a graph = VTX of 'a * 'a graph list ref
35655 fun arcs (VTX (_, r)) = r</programlisting>
35656 <simpara>Using the <literal>Show</literal> combinators, we could first write a new type-index
35657 combinator for <literal>graph</literal>:</simpara>
35658 <programlisting language="sml" linenumbering="unnumbered">fun graph a = let
35659 open Tie Show
35660 in
35661 fix Y (fn graph_a =&gt;
35662 inj (fn VTX (x, y) =&gt; x &amp; y)
35663 (data (C1"VTX"
35664 (tuple (U a *
35665 U (refc (list graph_a)))))))
35666 end</programlisting>
35667 <simpara>To show a graph with integer labels</simpara>
35668 <programlisting language="sml" linenumbering="unnumbered">val a_graph = let
35669 val a = VTX (1, ref [])
35670 val b = VTX (2, ref [])
35671 val c = VTX (3, ref [])
35672 val d = VTX (4, ref [])
35673 val e = VTX (5, ref [])
35674 val f = VTX (6, ref [])
35675 in
35676 arcs a := [b, d]
35677 ; arcs b := [c, e]
35678 ; arcs c := [a, f]
35679 ; arcs d := [f]
35680 ; arcs e := [d]
35681 ; arcs f := [e]
35682 ; a
35683 end</programlisting>
35684 <simpara>we could then simply write</simpara>
35685 <programlisting language="sml" linenumbering="unnumbered">val "VTX (1, ref [VTX (2, ref [VTX (3, ref [VTX (1, %0), \
35686 \VTX (6, ref [VTX (5, ref [VTX (4, ref [VTX (6, %3)])])] as %3)]), \
35687 \VTX (5, ref [VTX (4, ref [VTX (6, ref [VTX (5, %2)])])] as %2)]), \
35688 \VTX (4, ref [VTX (6, ref [VTX (5, ref [VTX (4, %1)])])] as %1)] as %0)" =
35689 let open Show in show (graph int) end
35690 a_graph</programlisting>
35691 <simpara>There is a subtle gotcha with cyclic data. Consider the following code:</simpara>
35692 <programlisting language="sml" linenumbering="unnumbered">exception ExnArray of exn array
35693
35694 val () = let
35695 open Show
35696 in
35697 regExn (fn ExnArray a =&gt;
35698 SOME (a, C1"ExnArray" (array exn))
35699 | _ =&gt; NONE)
35700 end
35701
35702 val a_cycle = let
35703 val a = Array.fromList [Empty]
35704 in
35705 Array.update (a, 0, ExnArray a) ; a
35706 end</programlisting>
35707 <simpara>Although the above looks innocent enough, the evaluation of</simpara>
35708 <programlisting language="sml" linenumbering="unnumbered">val "[|ExnArray %0|] as %0" =
35709 let open Show in show (array exn) end
35710 a_cycle</programlisting>
35711 <simpara>goes into an infinite loop. To avoid this problem, the type-index
35712 <literal>array exn</literal> must be evaluated only once, as in the following:</simpara>
35713 <programlisting language="sml" linenumbering="unnumbered">val array_exn = let open Show in array exn end
35714
35715 exception ExnArray of exn array
35716
35717 val () = let
35718 open Show
35719 in
35720 regExn (fn ExnArray a =&gt;
35721 SOME (a, C1"ExnArray" array_exn)
35722 | _ =&gt; NONE)
35723 end
35724
35725 val a_cycle = let
35726 val a = Array.fromList [Empty]
35727 in
35728 Array.update (a, 0, ExnArray a) ; a
35729 end
35730
35731 val "[|ExnArray %0|] as %0" =
35732 let open Show in show array_exn end
35733 a_cycle</programlisting>
35734 <simpara>Cyclic data (excluding closures) in Standard ML can only be
35735 constructed imperatively through arrays and references (combined with
35736 exceptions or recursive datatypes). Before recursing to a reference
35737 or an array, one needs to check whether that reference or array has
35738 already been seen before. When <literal>ref</literal> or <literal>array</literal> is called with a
35739 type-index, a new cyclicity checker is instantiated.</simpara>
35740 </section>
35741 <section id="_implementation_69">
35742 <title>Implementation</title>
35743 <programlisting language="sml" linenumbering="unnumbered">structure SmlSyntax = struct
35744 local
35745 structure CV = CharVector and C = Char
35746 in
35747 val isSym = Char.contains "!%&amp;$#+-/:&lt;=&gt;?@\\~`^|*"
35748
35749 fun isSymId s = 0 &lt; size s andalso CV.all isSym s
35750
35751 fun isAlphaNumId s =
35752 0 &lt; size s
35753 andalso C.isAlpha (CV.sub (s, 0))
35754 andalso CV.all (fn c =&gt; C.isAlphaNum c
35755 orelse #"'" = c
35756 orelse #"_" = c) s
35757
35758 fun isNumLabel s =
35759 0 &lt; size s
35760 andalso #"0" &lt;&gt; CV.sub (s, 0)
35761 andalso CV.all C.isDigit s
35762
35763 fun isId s = isAlphaNumId s orelse isSymId s
35764
35765 fun isLongId s = List.all isId (String.fields (#"." &lt;\ op =) s)
35766
35767 fun isLabel s = isId s orelse isNumLabel s
35768 end
35769 end
35770
35771 structure Show :&gt; SHOW = struct
35772 datatype 'a t = IN of exn list * 'a -&gt; bool * string
35773 type 'a s = 'a t
35774 type ('a, 'k) p = 'a t
35775 type u = unit
35776 type l = unit
35777
35778 fun show (IN t) x = #2 (t ([], x))
35779
35780 (* user-defined types *)
35781 fun inj inj (IN b) = IN (b o Pair.map (id, inj))
35782
35783 local
35784 fun surround pre suf (_, s) = (false, concat [pre, s, suf])
35785 fun parenthesize x = if #1 x then surround "(" ")" x else x
35786 fun construct tag =
35787 (fn (_, s) =&gt; (true, concat [tag, " ", s])) o parenthesize
35788 fun check p m s = if p s then () else raise Fail (m^s)
35789 in
35790 (* tuples and records *)
35791 fun (IN l) * (IN r) =
35792 IN (fn (rs, a &amp; b) =&gt;
35793 (false, concat [#2 (l (rs, a)),
35794 ", ",
35795 #2 (r (rs, b))]))
35796
35797 val U = id
35798 fun L l = (check SmlSyntax.isLabel "Invalid label: " l
35799 ; fn IN t =&gt; IN (surround (l^" = ") "" o t))
35800
35801 fun tuple (IN t) = IN (surround "(" ")" o t)
35802 fun record (IN t) = IN (surround "{" "}" o t)
35803
35804 (* datatypes *)
35805 fun (IN l) + (IN r) = IN (fn (rs, INL a) =&gt; l (rs, a)
35806 | (rs, INR b) =&gt; r (rs, b))
35807
35808 fun C0 c = (check SmlSyntax.isId "Invalid constructor: " c
35809 ; IN (const (false, c)))
35810 fun C1 c (IN t) = (check SmlSyntax.isId "Invalid constructor: " c
35811 ; IN (construct c o t))
35812
35813 val data = id
35814
35815 fun Y ? = Tie.iso Tie.function (fn IN x =&gt; x, IN) ?
35816
35817 (* exceptions *)
35818 local
35819 val handlers = ref ([] : (exn -&gt; unit t option) list)
35820 in
35821 val exn = IN (fn (rs, e) =&gt; let
35822 fun lp [] =
35823 C0(concat ["&lt;exn:",
35824 General.exnName e,
35825 "&gt;"])
35826 | lp (f::fs) =
35827 case f e
35828 of NONE =&gt; lp fs
35829 | SOME t =&gt; t
35830 val IN f = lp (!handlers)
35831 in
35832 f (rs, ())
35833 end)
35834 fun regExn f =
35835 handlers := (Option.map
35836 (fn (x, IN f) =&gt;
35837 IN (fn (rs, ()) =&gt;
35838 f (rs, x))) o f)
35839 :: !handlers
35840 end
35841
35842 (* some built-in type constructors *)
35843 local
35844 fun cyclic (IN t) = let
35845 exception E of ''a * bool ref
35846 in
35847 IN (fn (rs, v : ''a) =&gt; let
35848 val idx = Int.toString o length
35849 fun lp (E (v', c)::rs) =
35850 if v' &lt;&gt; v then lp rs
35851 else (c := false ; (false, "%"^idx rs))
35852 | lp (_::rs) = lp rs
35853 | lp [] = let
35854 val c = ref true
35855 val r = t (E (v, c)::rs, v)
35856 in
35857 if !c then r
35858 else surround "" (" as %"^idx rs) r
35859 end
35860 in
35861 lp rs
35862 end)
35863 end
35864
35865 fun aggregate pre suf toList (IN t) =
35866 IN (surround pre suf o
35867 (fn (rs, a) =&gt;
35868 (false,
35869 String.concatWith
35870 ", "
35871 (map (#2 o curry t rs)
35872 (toList a)))))
35873 in
35874 fun refc ? = (cyclic o inj ! o C1"ref") ?
35875 fun array ? = (cyclic o aggregate "[|" "|]" (Array.foldr op:: [])) ?
35876 fun list ? = aggregate "[" "]" id ?
35877 fun vector ? = aggregate "#[" "]" (Vector.foldr op:: []) ?
35878 end
35879
35880 fun (IN _) --&gt; (IN _) = IN (const (false, "&lt;fn&gt;"))
35881
35882 (* some built-in base types *)
35883 local
35884 fun mk toS = (fn x =&gt; (false, x)) o toS o (fn (_, x) =&gt; x)
35885 in
35886 val string =
35887 IN (surround "\"" "\"" o mk (String.translate Char.toString))
35888 val unit = IN (mk (fn () =&gt; "()"))
35889 val bool = IN (mk Bool.toString)
35890 val char = IN (surround "#\"" "\"" o mk Char.toString)
35891 val int = IN (mk Int.toString)
35892 val word = IN (surround "0wx" "" o mk Word.toString)
35893 val real = IN (mk Real.toString)
35894 end
35895 end
35896 end
35897
35898 (* Handlers for standard top-level exceptions *)
35899 val () = let
35900 open Show
35901 fun E0 name = SOME ((), C0 name)
35902 in
35903 regExn (fn Bind =&gt; E0"Bind"
35904 | Chr =&gt; E0"Chr"
35905 | Div =&gt; E0"Div"
35906 | Domain =&gt; E0"Domain"
35907 | Empty =&gt; E0"Empty"
35908 | Match =&gt; E0"Match"
35909 | Option =&gt; E0"Option"
35910 | Overflow =&gt; E0"Overflow"
35911 | Size =&gt; E0"Size"
35912 | Span =&gt; E0"Span"
35913 | Subscript =&gt; E0"Subscript"
35914 | _ =&gt; NONE)
35915 ; regExn (fn Fail s =&gt; SOME (s, C1"Fail" string)
35916 | _ =&gt; NONE)
35917 end</programlisting>
35918 </section>
35919 <section id="_also_see_47">
35920 <title>Also see</title>
35921 <simpara>There are a number of related techniques. Here are some of them.</simpara>
35922 <itemizedlist>
35923 <listitem>
35924 <simpara>
35925 <link linkend="Fold">Fold</link>
35926 </simpara>
35927 </listitem>
35928 <listitem>
35929 <simpara>
35930 <link linkend="StaticSum">StaticSum</link>
35931 </simpara>
35932 </listitem>
35933 </itemizedlist>
35934 <simpara><?asciidoc-pagebreak?></simpara>
35935 </section>
35936 </section>
35937 <section id="TypeVariableScope">
35938 <title>TypeVariableScope</title>
35939 <simpara>In <link linkend="StandardML">Standard ML</link>, every type variable is <emphasis>scoped</emphasis> (or
35940 bound) at a particular point in the program. A type variable can be
35941 either implicitly scoped or explicitly scoped. For example, <literal>'a</literal> is
35942 implicitly scoped in</simpara>
35943 <programlisting language="sml" linenumbering="unnumbered">val id: 'a -&gt; 'a = fn x =&gt; x</programlisting>
35944 <simpara>and is implicitly scoped in</simpara>
35945 <programlisting language="sml" linenumbering="unnumbered">val id = fn x: 'a =&gt; x</programlisting>
35946 <simpara>On the other hand, <literal>'a</literal> is explicitly scoped in</simpara>
35947 <programlisting language="sml" linenumbering="unnumbered">val 'a id: 'a -&gt; 'a = fn x =&gt; x</programlisting>
35948 <simpara>and is explicitly scoped in</simpara>
35949 <programlisting language="sml" linenumbering="unnumbered">val 'a id = fn x: 'a =&gt; x</programlisting>
35950 <simpara>A type variable can be scoped at a <literal>val</literal> or <literal>fun</literal> declaration. An SML
35951 type checker performs scope inference on each top-level declaration to
35952 determine the scope of each implicitly scoped type variable. After
35953 scope inference, every type variable is scoped at exactly one
35954 enclosing <literal>val</literal> or <literal>fun</literal> declaration. Scope inference shows that the
35955 first and second example above are equivalent to the third and fourth
35956 example, respectively.</simpara>
35957 <simpara>Section 4.6 of the <link linkend="DefinitionOfStandardML">Definition</link> specifies
35958 precisely the scope of an implicitly scoped type variable. A free
35959 occurrence of a type variable <literal>'a</literal> in a declaration <literal>d</literal> is said to be
35960 <emphasis>unguarded</emphasis> in <literal>d</literal> if <literal>'a</literal> is not part of a smaller declaration. A
35961 type variable <literal>'a</literal> is implicitly scoped at <literal>d</literal> if <literal>'a</literal> is unguarded in
35962 <literal>d</literal> and <literal>'a</literal> does not occur unguarded in any declaration containing
35963 <literal>d</literal>.</simpara>
35964 <section id="_scope_inference_examples">
35965 <title>Scope inference examples</title>
35966 <itemizedlist>
35967 <listitem>
35968 <simpara>
35969 In this example,
35970 </simpara>
35971 <programlisting language="sml" linenumbering="unnumbered">val id: 'a -&gt; 'a = fn x =&gt; x</programlisting>
35972 <simpara><literal>'a</literal> is unguarded in <literal>val id</literal> and does not occur unguarded in any
35973 containing declaration. Hence, <literal>'a</literal> is scoped at <literal>val id</literal> and the
35974 declaration is equivalent to the following.</simpara>
35975 <programlisting language="sml" linenumbering="unnumbered">val 'a id: 'a -&gt; 'a = fn x =&gt; x</programlisting>
35976 </listitem>
35977 <listitem>
35978 <simpara>
35979 In this example,
35980 </simpara>
35981 <programlisting language="sml" linenumbering="unnumbered"> val f = fn x =&gt; let exception E of 'a in E x end</programlisting>
35982 <simpara><literal>'a</literal> is unguarded in <literal>val f</literal> and does not occur unguarded in any
35983 containing declaration. Hence, <literal>'a</literal> is scoped at <literal>val f</literal> and the
35984 declaration is equivalent to the following.</simpara>
35985 <programlisting language="sml" linenumbering="unnumbered">val 'a f = fn x =&gt; let exception E of 'a in E x end</programlisting>
35986 </listitem>
35987 <listitem>
35988 <simpara>
35989 In this example (taken from the <link linkend="DefinitionOfStandardML">Definition</link>),
35990 </simpara>
35991 <programlisting language="sml" linenumbering="unnumbered">val x: int -&gt; int = let val id: 'a -&gt; 'a = fn z =&gt; z in id id end</programlisting>
35992 <simpara><literal>'a</literal> occurs unguarded in <literal>val id</literal>, but not in <literal>val x</literal>. Hence, <literal>'a</literal> is
35993 implicitly scoped at <literal>val id</literal>, and the declaration is equivalent to
35994 the following.</simpara>
35995 <programlisting language="sml" linenumbering="unnumbered">val x: int -&gt; int = let val 'a id: 'a -&gt; 'a = fn z =&gt; z in id id end</programlisting>
35996 </listitem>
35997 <listitem>
35998 <simpara>
35999 In this example,
36000 </simpara>
36001 <programlisting language="sml" linenumbering="unnumbered">val f = (fn x: 'a =&gt; x) (fn y =&gt; y)</programlisting>
36002 <simpara><literal>'a</literal> occurs unguarded in <literal>val f</literal> and does not occur unguarded in any
36003 containing declaration. Hence, <literal>'a</literal> is implicitly scoped at <literal>val f</literal>,
36004 and the declaration is equivalent to the following.</simpara>
36005 <programlisting language="sml" linenumbering="unnumbered">val 'a f = (fn x: 'a =&gt; x) (fn y =&gt; y)</programlisting>
36006 <simpara>This does not type check due to the <link linkend="ValueRestriction">ValueRestriction</link>.</simpara>
36007 </listitem>
36008 <listitem>
36009 <simpara>
36010 In this example,
36011 </simpara>
36012 <programlisting language="sml" linenumbering="unnumbered">fun f x =
36013 let
36014 fun g (y: 'a) = if true then x else y
36015 in
36016 g x
36017 end</programlisting>
36018 <simpara><literal>'a</literal> occurs unguarded in <literal>fun g</literal>, not in <literal>fun f</literal>. Hence, <literal>'a</literal> is
36019 implicitly scoped at <literal>fun g</literal>, and the declaration is equivalent to</simpara>
36020 <programlisting language="sml" linenumbering="unnumbered">fun f x =
36021 let
36022 fun 'a g (y: 'a) = if true then x else y
36023 in
36024 g x
36025 end</programlisting>
36026 <simpara>This fails to type check because <literal>x</literal> and <literal>y</literal> must have the same type,
36027 but the <literal>x</literal> occurs outside the scope of the type variable <literal>'a</literal>. MLton
36028 reports the following error.</simpara>
36029 <screen>Error: z.sml 3.21-3.41.
36030 Then and else branches disagree.
36031 then: [???]
36032 else: ['a]
36033 in: if true then x else y
36034 note: type would escape its scope: 'a
36035 escape to: z.sml 1.1-6.5</screen>
36036 <simpara>This problem could be fixed either by adding an explicit type
36037 constraint, as in <literal>fun f (x: 'a)</literal>, or by explicitly scoping <literal>'a</literal>, as
36038 in <literal>fun 'a f x = ...</literal>.</simpara>
36039 </listitem>
36040 </itemizedlist>
36041 </section>
36042 <section id="_restrictions_on_type_variable_scope">
36043 <title>Restrictions on type variable scope</title>
36044 <simpara>It is not allowed to scope a type variable within a declaration in
36045 which it is already in scope (see the last restriction listed on page
36046 9 of the <link linkend="DefinitionOfStandardML">Definition</link>). For example, the
36047 following program is invalid.</simpara>
36048 <programlisting language="sml" linenumbering="unnumbered">fun 'a f (x: 'a) =
36049 let
36050 fun 'a g (y: 'a) = y
36051 in
36052 ()
36053 end</programlisting>
36054 <simpara>MLton reports the following error.</simpara>
36055 <screen>Error: z.sml 3.11-3.12.
36056 Type variable scoped at an outer declaration: 'a.
36057 scoped at: z.sml 1.1-6.6</screen>
36058 <simpara>This is an error even if the scoping is implicit. That is, the
36059 following program is invalid as well.</simpara>
36060 <programlisting language="sml" linenumbering="unnumbered">fun f (x: 'a) =
36061 let
36062 fun 'a g (y: 'a) = y
36063 in
36064 ()
36065 end</programlisting>
36066 <simpara><?asciidoc-pagebreak?></simpara>
36067 </section>
36068 </section>
36069 <section id="Unicode">
36070 <title>Unicode</title>
36071 <section id="_support_in_the_definition_of_standard_ml">
36072 <title>Support in The Definition of Standard ML</title>
36073 <simpara>There is no real support for Unicode in the
36074 <link linkend="DefinitionOfStandardML">Definition</link>; there are only a few throw-away
36075 sentences along the lines of "the characters with numbers 0 to 127
36076 coincide with the ASCII character set."</simpara>
36077 </section>
36078 <section id="_support_in_the_standard_ml_basis_library">
36079 <title>Support in The Standard ML Basis Library</title>
36080 <simpara>Neither is there real support for Unicode in the <link linkend="BasisLibrary">Basis Library</link>. The general consensus (which includes the opinions of the
36081 editors of the Basis Library) is that the <literal>WideChar</literal> and <literal>WideString</literal>
36082 structures are insufficient for the purposes of Unicode. There is no
36083 <literal>LargeChar</literal> structure, which in itself is a deficiency, since a
36084 programmer can not program against the largest supported character
36085 size.</simpara>
36086 </section>
36087 <section id="_current_support_in_mlton">
36088 <title>Current Support in MLton</title>
36089 <simpara>MLton, as a minor extension over the Definition, supports UTF-8 byte
36090 sequences in text constants. This feature enables "UTF-8 convenience"
36091 (but not comprehensive Unicode support); in particular, it allows one
36092 to copy text from a browser and paste it into a string constant in an
36093 editor and, furthermore, if the string is printed to a terminal, then
36094 will (typically) appear as the original text. See the
36095 <link linkend="SuccessorML_ExtendedTextConsts">extended text constants feature of Successor ML</link> for more details.</simpara>
36096 <simpara>MLton, also as a minor extension over the Definition, supports
36097 <literal>\Uxxxxxxxx</literal> numeric escapes in text constants and has preliminary
36098 internal support for 16- and 32-bit characters and strings.</simpara>
36099 <simpara>MLton provides <literal>WideChar</literal> and <literal>WideString</literal> structures, corresponding
36100 to 32-bit characters and strings, respectively.</simpara>
36101 </section>
36102 <section id="_questions_and_discussions">
36103 <title>Questions and Discussions</title>
36104 <simpara>There are periodic flurries of questions and discussion about Unicode
36105 in MLton/SML. In December 2004, there was a discussion that led to
36106 some seemingly sound design decisions. The discussion started at:</simpara>
36107 <itemizedlist>
36108 <listitem>
36109 <simpara>
36110 <ulink url="http://www.mlton.org/pipermail/mlton/2004-December/026396.html">http://www.mlton.org/pipermail/mlton/2004-December/026396.html</ulink>
36111 </simpara>
36112 </listitem>
36113 </itemizedlist>
36114 <simpara>There is a good summary of points at:</simpara>
36115 <itemizedlist>
36116 <listitem>
36117 <simpara>
36118 <ulink url="http://www.mlton.org/pipermail/mlton/2004-December/026440.html">http://www.mlton.org/pipermail/mlton/2004-December/026440.html</ulink>
36119 </simpara>
36120 </listitem>
36121 </itemizedlist>
36122 <simpara>In November 2005, there was a followup discussion and the beginning of
36123 some coding.</simpara>
36124 <itemizedlist>
36125 <listitem>
36126 <simpara>
36127 <ulink url="http://www.mlton.org/pipermail/mlton/2005-November/028300.html">http://www.mlton.org/pipermail/mlton/2005-November/028300.html</ulink>
36128 </simpara>
36129 </listitem>
36130 </itemizedlist>
36131 </section>
36132 <section id="_also_see_48">
36133 <title>Also see</title>
36134 <simpara>The <link linkend="fxp">fxp</link> XML parser has some support for dealing with Unicode
36135 documents.</simpara>
36136 <simpara><?asciidoc-pagebreak?></simpara>
36137 </section>
36138 </section>
36139 <section id="UniversalType">
36140 <title>UniversalType</title>
36141 <simpara>A universal type is a type into which all other types can be embedded.
36142 Here&#8217;s a <link linkend="StandardML">Standard ML</link> signature for a universal type.</simpara>
36143 <programlisting language="sml" linenumbering="unnumbered">signature UNIVERSAL_TYPE =
36144 sig
36145 type t
36146
36147 val embed: unit -&gt; ('a -&gt; t) * (t -&gt; 'a option)
36148 end</programlisting>
36149 <simpara>The idea is that <literal>type t</literal> is the universal type and that each call to
36150 <literal>embed</literal> returns a new pair of functions <literal>(inject, project)</literal>, where
36151 <literal>inject</literal> embeds a value into the universal type and <literal>project</literal> extracts
36152 the value from the universal type. A pair <literal>(inject, project)</literal>
36153 returned by <literal>embed</literal> works together in that <literal>project u</literal> will return
36154 <literal>SOME v</literal> if and only if <literal>u</literal> was created by <literal>inject v</literal>. If <literal>u</literal> was
36155 created by a different function <literal>inject'</literal>, then <literal>project</literal> returns
36156 <literal>NONE</literal>.</simpara>
36157 <simpara>Here&#8217;s an example embedding integers and reals into a universal type.</simpara>
36158 <programlisting language="sml" linenumbering="unnumbered">functor Test (U: UNIVERSAL_TYPE): sig end =
36159 struct
36160 val (intIn: int -&gt; U.t, intOut) = U.embed ()
36161 val r: U.t ref = ref (intIn 13)
36162 val s1 =
36163 case intOut (!r) of
36164 NONE =&gt; "NONE"
36165 | SOME i =&gt; Int.toString i
36166 val (realIn: real -&gt; U.t, realOut) = U.embed ()
36167 val () = r := realIn 13.0
36168 val s2 =
36169 case intOut (!r) of
36170 NONE =&gt; "NONE"
36171 | SOME i =&gt; Int.toString i
36172 val s3 =
36173 case realOut (!r) of
36174 NONE =&gt; "NONE"
36175 | SOME x =&gt; Real.toString x
36176 val () = print (concat [s1, " ", s2, " ", s3, "\n"])
36177 end</programlisting>
36178 <simpara>Applying <literal>Test</literal> to an appropriate implementation will print</simpara>
36179 <screen>13 NONE 13.0</screen>
36180 <simpara>Note that two different calls to embed on the same type return
36181 different embeddings.</simpara>
36182 <simpara>Standard ML does not have explicit support for universal types;
36183 however, there are at least two ways to implement them.</simpara>
36184 <section id="_implementation_using_exceptions">
36185 <title>Implementation Using Exceptions</title>
36186 <simpara>While the intended use of SML exceptions is for exception handling, an
36187 accidental feature of their design is that the <literal>exn</literal> type is a
36188 universal type. The implementation relies on being able to declare
36189 exceptions locally to a function and on the fact that exceptions are
36190 <link linkend="GenerativeException">generative</link>.</simpara>
36191 <programlisting language="sml" linenumbering="unnumbered">structure U:&gt; UNIVERSAL_TYPE =
36192 struct
36193 type t = exn
36194
36195 fun 'a embed () =
36196 let
36197 exception E of 'a
36198 fun project (e: t): 'a option =
36199 case e of
36200 E a =&gt; SOME a
36201 | _ =&gt; NONE
36202 in
36203 (E, project)
36204 end
36205 end</programlisting>
36206 </section>
36207 <section id="_implementation_using_functions_and_references">
36208 <title>Implementation Using Functions and References</title>
36209 <programlisting language="sml" linenumbering="unnumbered">structure U:&gt; UNIVERSAL_TYPE =
36210 struct
36211 datatype t = T of {clear: unit -&gt; unit,
36212 store: unit -&gt; unit}
36213
36214 fun 'a embed () =
36215 let
36216 val r: 'a option ref = ref NONE
36217 fun inject (a: 'a): t =
36218 T {clear = fn () =&gt; r := NONE,
36219 store = fn () =&gt; r := SOME a}
36220 fun project (T {clear, store}): 'a option =
36221 let
36222 val () = store ()
36223 val res = !r
36224 val () = clear ()
36225 in
36226 res
36227 end
36228 in
36229 (inject, project)
36230 end
36231 end</programlisting>
36232 <simpara>Note that due to the use of a shared ref cell, the above
36233 implementation is not thread safe.</simpara>
36234 <simpara>One could try to simplify the above implementation by eliminating the
36235 <literal>clear</literal> function, making <literal>type t = unit -&gt; unit</literal>.</simpara>
36236 <programlisting language="sml" linenumbering="unnumbered">structure U:&gt; UNIVERSAL_TYPE =
36237 struct
36238 type t = unit -&gt; unit
36239
36240 fun 'a embed () =
36241 let
36242 val r: 'a option ref = ref NONE
36243 fun inject (a: 'a): t = fn () =&gt; r := SOME a
36244 fun project (f: t): 'a option = (r := NONE; f (); !r)
36245 in
36246 (inject, project)
36247 end
36248 end</programlisting>
36249 <simpara>While correct, this approach keeps the contents of the ref cell alive
36250 longer than necessary, which could cause a space leak. The problem is
36251 in <literal>project</literal>, where the call to <literal>f</literal> stores some value in some ref cell
36252 <literal>r'</literal>. Perhaps <literal>r'</literal> is the same ref cell as <literal>r</literal>, but perhaps not. If
36253 we do not clear <literal>r'</literal> before returning from <literal>project</literal>, then <literal>r'</literal> will
36254 keep the value alive, even though it is useless.</simpara>
36255 </section>
36256 <section id="_also_see_49">
36257 <title>Also see</title>
36258 <itemizedlist>
36259 <listitem>
36260 <simpara>
36261 <link linkend="PropertyList">PropertyList</link>: Lisp-style property lists implemented with a universal type
36262 </simpara>
36263 </listitem>
36264 </itemizedlist>
36265 <simpara><?asciidoc-pagebreak?></simpara>
36266 </section>
36267 </section>
36268 <section id="UnresolvedBugs">
36269 <title>UnresolvedBugs</title>
36270 <simpara>Here are the places where MLton deviates from
36271 <link linkend="DefinitionOfStandardML">The Definition of Standard ML (Revised)</link> and
36272 the <link linkend="BasisLibrary">Basis Library</link>. In general, MLton complies with
36273 the <link linkend="DefinitionOfStandardML">Definition</link> quite closely, typically much
36274 more closely than other SML compilers (see, e.g., our list of
36275 <link linkend="SMLNJDeviations">SML/NJ&#8217;s deviations</link>). In fact, the four deviations
36276 listed here are the only known deviations, and we have no immediate
36277 plans to fix them. If you find a deviation not listed here, please
36278 report a <link linkend="Bug">Bug</link>.</simpara>
36279 <simpara>We don&#8217;t plan to fix these bugs because the first (parsing nested
36280 cases) has historically never been accepted by any SML compiler, the
36281 second clearly indicates a problem in the
36282 <link linkend="DefinitionOfStandardML">Definition</link>, and the remaining are difficult
36283 to resolve in the context of MLton&#8217;s implementaton of Standard ML (and
36284 unlikely to be problematic in practice).</simpara>
36285 <itemizedlist>
36286 <listitem>
36287 <simpara>
36288 MLton does not correctly parse case expressions nested within other
36289 matches. For example, the following fails.
36290 </simpara>
36291 <programlisting language="sml" linenumbering="unnumbered">fun f 0 y =
36292 case x of
36293 1 =&gt; 2
36294 | _ =&gt; 3
36295 | f _ y = 4</programlisting>
36296 <simpara>To do this in a program, simply parenthesize the case expression.</simpara>
36297 <simpara>Allowing such expressions, although compliant with the Definition,
36298 would be a mistake, since using parentheses is clearer and no SML
36299 compiler has ever allowed them. Furthermore, implementing this would
36300 require serious yacc grammar rewriting followed by postprocessing.</simpara>
36301 </listitem>
36302 <listitem>
36303 <simpara>
36304 MLton does not raise the <literal>Bind</literal> exception at run time when
36305 evaluating <literal>val rec</literal> (and <literal>fun</literal>) declarations that redefine
36306 identifiers that previously had constructor status. (By default,
36307 MLton does warn at compile time about <literal>val rec</literal> (and <literal>fun</literal>)
36308 declarations that redefine identifiers that previously had
36309 constructors status; see the <literal>valrecConstr</literal> <link linkend="MLBasisAnnotations">ML Basis annotation</link>.) For example, the Definition requires the
36310 following program to type check, but also (bizarelly) requires it to
36311 raise the <literal>Bind</literal> exception
36312 </simpara>
36313 <programlisting language="sml" linenumbering="unnumbered">val rec NONE = fn () =&gt; ()</programlisting>
36314 <simpara>The Definition&#8217;s behavior is obviously an error, a mismatch between
36315 the static semantics (rule 26) and the dynamic semantics (rule 126).
36316 Given the comments on rule 26 in the Definition, it seems clear that
36317 the authors meant for <literal>val rec</literal> to allow an identifier&#8217;s constructor
36318 status to be overridden both statically and dynamically. Hence, MLton
36319 and most SML compilers follow rule 26, but do not follow rule 126.</simpara>
36320 </listitem>
36321 <listitem>
36322 <simpara>
36323 MLton does not hide the equality aspect of types declared in
36324 <literal>abstype</literal> declarations. So, MLton accepts programs like the following,
36325 while the Definition rejects them.
36326 </simpara>
36327 <programlisting language="sml" linenumbering="unnumbered">abstype t = T with end
36328 val _ = fn (t1, t2 : t) =&gt; t1 = t2
36329
36330 abstype t = T with val a = T end
36331 val _ = a = a</programlisting>
36332 <simpara>One consequence of this choice is that MLton accepts the following
36333 program, in accordance with the Definition.</simpara>
36334 <programlisting language="sml" linenumbering="unnumbered">abstype t = T with val eq = op = end
36335 val _ = fn (t1, t2 : t) =&gt; eq (t1, t2)</programlisting>
36336 <simpara>Other implementations will typically reject this program, because they
36337 make an early choice for the type of <literal>eq</literal> to be <literal>''a * ''a -&gt; bool</literal>
36338 instead of <literal>t * t -&gt; bool</literal>. The choice is understandable, since the
36339 Definition accepts the following program.</simpara>
36340 <programlisting language="sml" linenumbering="unnumbered">abstype t = T with val eq = op = end
36341 val _ = eq (1, 2)</programlisting>
36342 </listitem>
36343 <listitem>
36344 <simpara>
36345 MLton (re-)type checks each functor definition at every
36346 corresponding functor application (the compilation technique of
36347 defunctorization). One consequence of this implementation is that
36348 MLton accepts the following program, while the Definition rejects
36349 it.
36350 </simpara>
36351 <programlisting language="sml" linenumbering="unnumbered">functor F (X: sig type t end) = struct
36352 val f = id id
36353 end
36354 structure A = F (struct type t = int end)
36355 structure B = F (struct type t = bool end)
36356 val _ = A.f 10
36357 val _ = B.f "dude"</programlisting>
36358 <simpara>On the other hand, other implementations will typically reject the
36359 following program, while MLton and the Definition accept it.</simpara>
36360 <programlisting language="sml" linenumbering="unnumbered">functor F (X: sig type t end) = struct
36361 val f = id id
36362 end
36363 structure A = F (struct type t = int end)
36364 structure B = F (struct type t = bool end)
36365 val _ = A.f 10
36366 val _ = B.f false</programlisting>
36367 <simpara>See <link linkend="References_DreyerBlume07">DreyerBlume07</link> for more details.</simpara>
36368 </listitem>
36369 </itemizedlist>
36370 <simpara><?asciidoc-pagebreak?></simpara>
36371 </section>
36372 <section id="UnsafeStructure">
36373 <title>UnsafeStructure</title>
36374 <simpara>This module is a subset of the <literal>Unsafe</literal> module provided by SML/NJ,
36375 with a few extract operations for <literal>PackWord</literal> and <literal>PackReal</literal>.</simpara>
36376 <programlisting language="sml" linenumbering="unnumbered">signature UNSAFE_MONO_ARRAY =
36377 sig
36378 type array
36379 type elem
36380
36381 val create: int -&gt; array
36382 val sub: array * int -&gt; elem
36383 val update: array * int * elem -&gt; unit
36384 end
36385
36386 signature UNSAFE_MONO_VECTOR =
36387 sig
36388 type elem
36389 type vector
36390
36391 val sub: vector * int -&gt; elem
36392 end
36393
36394 signature UNSAFE =
36395 sig
36396 structure Array:
36397 sig
36398 val create: int * 'a -&gt; 'a array
36399 val sub: 'a array * int -&gt; 'a
36400 val update: 'a array * int * 'a -&gt; unit
36401 end
36402 structure CharArray: UNSAFE_MONO_ARRAY
36403 structure CharVector: UNSAFE_MONO_VECTOR
36404 structure IntArray: UNSAFE_MONO_ARRAY
36405 structure IntVector: UNSAFE_MONO_VECTOR
36406 structure Int8Array: UNSAFE_MONO_ARRAY
36407 structure Int8Vector: UNSAFE_MONO_VECTOR
36408 structure Int16Array: UNSAFE_MONO_ARRAY
36409 structure Int16Vector: UNSAFE_MONO_VECTOR
36410 structure Int32Array: UNSAFE_MONO_ARRAY
36411 structure Int32Vector: UNSAFE_MONO_VECTOR
36412 structure Int64Array: UNSAFE_MONO_ARRAY
36413 structure Int64Vector: UNSAFE_MONO_VECTOR
36414 structure IntInfArray: UNSAFE_MONO_ARRAY
36415 structure IntInfVector: UNSAFE_MONO_VECTOR
36416 structure LargeIntArray: UNSAFE_MONO_ARRAY
36417 structure LargeIntVector: UNSAFE_MONO_VECTOR
36418 structure LargeRealArray: UNSAFE_MONO_ARRAY
36419 structure LargeRealVector: UNSAFE_MONO_VECTOR
36420 structure LargeWordArray: UNSAFE_MONO_ARRAY
36421 structure LargeWordVector: UNSAFE_MONO_VECTOR
36422 structure RealArray: UNSAFE_MONO_ARRAY
36423 structure RealVector: UNSAFE_MONO_VECTOR
36424 structure Real32Array: UNSAFE_MONO_ARRAY
36425 structure Real32Vector: UNSAFE_MONO_VECTOR
36426 structure Real64Array: UNSAFE_MONO_ARRAY
36427 structure Vector:
36428 sig
36429 val sub: 'a vector * int -&gt; 'a
36430 end
36431 structure Word8Array: UNSAFE_MONO_ARRAY
36432 structure Word8Vector: UNSAFE_MONO_VECTOR
36433 structure Word16Array: UNSAFE_MONO_ARRAY
36434 structure Word16Vector: UNSAFE_MONO_VECTOR
36435 structure Word32Array: UNSAFE_MONO_ARRAY
36436 structure Word32Vector: UNSAFE_MONO_VECTOR
36437 structure Word64Array: UNSAFE_MONO_ARRAY
36438 structure Word64Vector: UNSAFE_MONO_VECTOR
36439
36440 structure PackReal32Big : PACK_REAL
36441 structure PackReal32Little : PACK_REAL
36442 structure PackReal64Big : PACK_REAL
36443 structure PackReal64Little : PACK_REAL
36444 structure PackRealBig : PACK_REAL
36445 structure PackRealLittle : PACK_REAL
36446 structure PackWord16Big : PACK_WORD
36447 structure PackWord16Little : PACK_WORD
36448 structure PackWord32Big : PACK_WORD
36449 structure PackWord32Little : PACK_WORD
36450 structure PackWord64Big : PACK_WORD
36451 structure PackWord64Little : PACK_WORD
36452 end</programlisting>
36453 <simpara><?asciidoc-pagebreak?></simpara>
36454 </section>
36455 <section id="Useless">
36456 <title>Useless</title>
36457 <simpara><link linkend="Useless">Useless</link> is an optimization pass for the <link linkend="SSA">SSA</link>
36458 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSASimplify">SSASimplify</link>.</simpara>
36459 <section id="_description_64">
36460 <title>Description</title>
36461 <simpara>This pass:</simpara>
36462 <itemizedlist>
36463 <listitem>
36464 <simpara>
36465 removes components of tuples that are constants (use unification)
36466 </simpara>
36467 </listitem>
36468 <listitem>
36469 <simpara>
36470 removes function arguments that are constants
36471 </simpara>
36472 </listitem>
36473 <listitem>
36474 <simpara>
36475 builds some kind of dependence graph where
36476 </simpara>
36477 <itemizedlist>
36478 <listitem>
36479 <simpara>
36480 a value of ground type is useful if it is an arg to a primitive
36481 </simpara>
36482 </listitem>
36483 <listitem>
36484 <simpara>
36485 a tuple is useful if it contains a useful component
36486 </simpara>
36487 </listitem>
36488 <listitem>
36489 <simpara>
36490 a constructor is useful if it contains a useful component or is used in a <literal>Case</literal> transfer
36491 </simpara>
36492 </listitem>
36493 </itemizedlist>
36494 </listitem>
36495 </itemizedlist>
36496 <simpara>If a useful tuple is coerced to another useful tuple, then all of
36497 their components must agree (exactly). It is trivial to convert a
36498 useful value to a useless one.</simpara>
36499 </section>
36500 <section id="_implementation_70">
36501 <title>Implementation</title>
36502 <itemizedlist>
36503 <listitem>
36504 <simpara>
36505 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/useless.fun"><literal>useless.fun</literal></ulink>
36506 </simpara>
36507 </listitem>
36508 </itemizedlist>
36509 </section>
36510 <section id="_details_and_notes_67">
36511 <title>Details and Notes</title>
36512 <simpara>It is also trivial to convert a useful tuple to one of its useful
36513 components&#8201;&#8212;&#8201;but this seems hard.</simpara>
36514 <simpara>Suppose that you have a <literal>ref</literal>/<literal>array</literal>/<literal>vector</literal> that is useful, but the
36515 components aren&#8217;t&#8201;&#8212;&#8201;then the components are converted to type <literal>unit</literal>,
36516 and any primitive args must be as well.</simpara>
36517 <simpara>Unify all handler arguments so that <literal>raise</literal>/<literal>handle</literal> has a consistent
36518 calling convention.</simpara>
36519 <simpara><?asciidoc-pagebreak?></simpara>
36520 </section>
36521 </section>
36522 <section id="Users">
36523 <title>Users</title>
36524 <simpara>Here is a list of companies, projects, and courses that use or have
36525 used MLton. If you use MLton and are not here, please add your
36526 project with a brief description and a link. Thanks.</simpara>
36527 <section id="_companies">
36528 <title>Companies</title>
36529 <itemizedlist>
36530 <listitem>
36531 <simpara>
36532 <ulink url="http://www.hardcoreprocessing.com/">Hardcore Processing</ulink> uses MLton as a <ulink url="http://www.hardcoreprocessing.com/Freeware/MLTonWin32.html">crosscompiler from Linux to Windows</ulink> for graphics and game software.
36533 </simpara>
36534 <itemizedlist>
36535 <listitem>
36536 <simpara>
36537 <ulink url="http://www.cex3d.net/">CEX3D Converter</ulink>, a conversion program for 3D objects.
36538 </simpara>
36539 </listitem>
36540 <listitem>
36541 <simpara>
36542 <ulink url="http://www.hardcoreprocessing.com/company/showreel/index.html">Interactive Showreel</ulink>, which contains a crossplatform GUI-toolkit and a realtime renderer for a subset of RenderMan written in Standard ML.
36543 </simpara>
36544 </listitem>
36545 <listitem>
36546 <simpara>
36547 various <ulink url="http://www.hardcoreprocessing.com/entertainment/index.html">games</ulink>
36548 </simpara>
36549 </listitem>
36550 </itemizedlist>
36551 </listitem>
36552 <listitem>
36553 <simpara>
36554 <ulink url="http://www.mathworks.com/products/polyspace/">MathWorks/PolySpace Technologies</ulink> builds their product that detects runtime errors in embedded systems based on abstract interpretation.
36555 </simpara>
36556 </listitem>
36557 <listitem>
36558 <simpara>
36559 <ulink url="http://www.reactive-systems.com/">Reactive Systems</ulink> uses MLton to build Reactis, a model-based testing and validation package used in the automotive and aerospace industries.
36560 </simpara>
36561 </listitem>
36562 </itemizedlist>
36563 </section>
36564 <section id="_projects">
36565 <title>Projects</title>
36566 <itemizedlist>
36567 <listitem>
36568 <simpara>
36569 <ulink url="http://www-ia.hiof.no/%7Erolando/adate_intro.html">ADATE</ulink>, Automatic Design of Algorithms Through Evolution, a system for automatic programming i.e., inductive inference of algorithms. ADATE can automatically generate non-trivial and novel algorithms written in Standard ML.
36570 </simpara>
36571 </listitem>
36572 <listitem>
36573 <simpara>
36574 <ulink url="http://types.bu.edu/reports/Dim+Wes+Mul+Tur+Wel+Con:TIC-2000-LNCS.html">CIL</ulink>, a compiler for SML based on intersection and union types.
36575 </simpara>
36576 </listitem>
36577 <listitem>
36578 <simpara>
36579 <ulink url="http://www.cs.cmu.edu/%7Econcert/">ConCert</ulink>, a project investigating certified code for grid computing.
36580 </simpara>
36581 </listitem>
36582 <listitem>
36583 <simpara>
36584 <ulink url="http://hcoop.sourceforge.net/">Cooperative Internet hosting tools</ulink>
36585 </simpara>
36586 </listitem>
36587 <listitem>
36588 <simpara>
36589 <ulink url="http://www.fantasy-coders.de/projects/gh/">Guugelhupf</ulink>, a simple search engine.
36590 </simpara>
36591 </listitem>
36592 <listitem>
36593 <simpara>
36594 <ulink url="http://www.mpi-sws.org/%7Erossberg/hamlet/">HaMLet</ulink>, a model implementation of Standard ML.
36595 </simpara>
36596 </listitem>
36597 <listitem>
36598 <simpara>
36599 <ulink url="http://code.google.com/p/kepler-code/">KeplerCode</ulink>, independent verification of the computational aspects of proofs of the Kepler conjecture and the Dodecahedral conjecture.
36600 </simpara>
36601 </listitem>
36602 <listitem>
36603 <simpara>
36604 <ulink url="http://www.gilith.com/research/metis/">Metis</ulink>, a first-order prover (used in the <ulink url="http://hol.sourceforge.net/">HOL4 theorem prover</ulink> and the <ulink url="http://isabelle.in.tum.de/">Isabelle theorem prover</ulink>).
36605 </simpara>
36606 </listitem>
36607 <listitem>
36608 <simpara>
36609 <ulink url="http://tom7misc.cvs.sourceforge.net/viewvc/tom7misc/net/mlftpd/">mlftpd</ulink>, an ftp daemon written in SML. <link linkend="TomMurphy">TomMurphy</link> is also working on <ulink url="http://tom7misc.cvs.sourceforge.net/viewvc/tom7misc/net/">replacements for standard network services</ulink> in SML. He also uses MLton to build his entries (<ulink url="http://www.cs.cmu.edu/%7Etom7/icfp2001/">2001</ulink>, <ulink url="http://www.cs.cmu.edu/%7Etom7/icfp2002/">2002</ulink>, <ulink url="http://www.cs.cmu.edu/%7Etom7/icfp2004/">2004</ulink>, <ulink url="http://www.cs.cmu.edu/%7Etom7/icfp2005/">2005</ulink>) in the annual ICFP programming contest.
36610 </simpara>
36611 </listitem>
36612 <listitem>
36613 <simpara>
36614 <ulink url="http://www.informatik.uni-freiburg.de/proglang/research/software/mlope/">MLOPE</ulink>, an offline partial evaluator for Standard ML.
36615 </simpara>
36616 </listitem>
36617 <listitem>
36618 <simpara>
36619 <ulink url="http://www.ida.liu.se/%7Epelab/rml/">RML</ulink>, a system for developing, compiling and debugging and teaching structural operational semantics (SOS) and natural semantics specifications.
36620 </simpara>
36621 </listitem>
36622 <listitem>
36623 <simpara>
36624 <ulink url="http://www.macs.hw.ac.uk/ultra/skalpel/index.html">Skalpel</ulink>, a type-error slicer for SML
36625 </simpara>
36626 </listitem>
36627 <listitem>
36628 <simpara>
36629 <ulink url="http://www.cs.cmu.edu/%7Etom7/ssapre/">SSA PRE</ulink>, an implementation of Partial Redundancy Elimination for MLton.
36630 </simpara>
36631 </listitem>
36632 <listitem>
36633 <simpara>
36634 <link linkend="Stabilizers">Stabilizers</link>, a modular checkpointing abstraction for concurrent functional programs.
36635 </simpara>
36636 </listitem>
36637 <listitem>
36638 <simpara>
36639 <ulink url="http://ttic.uchicago.edu/%7Epl/sa-sml/">Self-Adjusting SML</ulink>, self-adjusting computation, a model of computing where programs can automatically adjust to changes to their data.
36640 </simpara>
36641 </listitem>
36642 <listitem>
36643 <simpara>
36644 <ulink url="http://faculty.ist.unomaha.edu/winter/ShiftLab/TL_web/TL_index.html">TL System</ulink>, providing general-purpose support for rewrite-based transformation over elements belonging to a (user-defined) domain language.
36645 </simpara>
36646 </listitem>
36647 <listitem>
36648 <simpara>
36649 <ulink url="http://projects.laas.fr/tina/">Tina</ulink> (Time Petri net Analyzer)
36650 </simpara>
36651 </listitem>
36652 <listitem>
36653 <simpara>
36654 <ulink url="http://www.twelf.org/">Twelf</ulink> an implementation of the LF logical framework.
36655 </simpara>
36656 </listitem>
36657 <listitem>
36658 <simpara>
36659 <ulink url="http://www.cs.indiana.edu/%7Errnewton/wavescope/">WaveScript/WaveScript</ulink>, a sensor network project; the WaveScript compiler can generate SML (MLton) code.
36660 </simpara>
36661 </listitem>
36662 </itemizedlist>
36663 </section>
36664 <section id="_courses">
36665 <title>Courses</title>
36666 <itemizedlist>
36667 <listitem>
36668 <simpara>
36669 <ulink url="http://www.eecs.harvard.edu/%7Enr/cs152/">Harvard CS-152</ulink>, undergraduate programming languages.
36670 </simpara>
36671 </listitem>
36672 <listitem>
36673 <simpara>
36674 <ulink url="http://www.ia-stud.hiof.no/%7Erolando/PL/">Høgskolen i Østfold IAI30202</ulink>, programming languages.
36675 </simpara>
36676 </listitem>
36677 </itemizedlist>
36678 <simpara><?asciidoc-pagebreak?></simpara>
36679 </section>
36680 </section>
36681 <section id="Utilities">
36682 <title>Utilities</title>
36683 <simpara>This page is a collection of basic utilities used in the examples on
36684 various pages. See</simpara>
36685 <itemizedlist>
36686 <listitem>
36687 <simpara>
36688 <link linkend="InfixingOperators">InfixingOperators</link>, and
36689 </simpara>
36690 </listitem>
36691 <listitem>
36692 <simpara>
36693 <link linkend="ProductType">ProductType</link>
36694 </simpara>
36695 </listitem>
36696 </itemizedlist>
36697 <simpara>for longer discussions on some of these utilities.</simpara>
36698 <programlisting language="sml" linenumbering="unnumbered">(* Operator precedence table *)
36699 infix 8 * / div mod (* +1 from Basis Library *)
36700 infix 7 + - ^ (* +1 from Basis Library *)
36701 infixr 6 :: @ (* +1 from Basis Library *)
36702 infix 5 = &lt;&gt; &gt; &gt;= &lt; &lt;= (* +1 from Basis Library *)
36703 infix 4 &lt;\ \&gt;
36704 infixr 4 &lt;/ /&gt;
36705 infix 3 o
36706 infix 2 &gt;|
36707 infixr 2 |&lt;
36708 infix 1 := (* -2 from Basis Library *)
36709 infix 0 before &amp;
36710
36711 (* Some basic combinators *)
36712 fun const x _ = x
36713 fun cross (f, g) (x, y) = (f x, g y)
36714 fun curry f x y = f (x, y)
36715 fun fail e _ = raise e
36716 fun id x = x
36717
36718 (* Product type *)
36719 datatype ('a, 'b) product = &amp; of 'a * 'b
36720
36721 (* Sum type *)
36722 datatype ('a, 'b) sum = INL of 'a | INR of 'b
36723
36724 (* Some type shorthands *)
36725 type 'a uop = 'a -&gt; 'a
36726 type 'a fix = 'a uop -&gt; 'a
36727 type 'a thunk = unit -&gt; 'a
36728 type 'a effect = 'a -&gt; unit
36729 type ('a, 'b) emb = ('a -&gt; 'b) * ('b -&gt; 'a)
36730
36731 (* Infixing, sectioning, and application operators *)
36732 fun x &lt;\ f = fn y =&gt; f (x, y)
36733 fun f \&gt; y = f y
36734 fun f /&gt; y = fn x =&gt; f (x, y)
36735 fun x &lt;/ f = f x
36736
36737 (* Piping operators *)
36738 val op&gt;| = op&lt;/
36739 val op|&lt; = op\&gt;</programlisting>
36740 <simpara><?asciidoc-pagebreak?></simpara>
36741 </section>
36742 <section id="ValueRestriction">
36743 <title>ValueRestriction</title>
36744 <simpara>The value restriction is a rule that governs when type inference is
36745 allowed to polymorphically generalize a value declaration. In short,
36746 the value restriction says that generalization can only occur if the
36747 right-hand side of an expression is syntactically a value. For
36748 example, in</simpara>
36749 <programlisting language="sml" linenumbering="unnumbered">val f = fn x =&gt; x
36750 val _ = (f "foo"; f 13)</programlisting>
36751 <simpara>the expression <literal>fn x =&gt; x</literal> is syntactically a value, so <literal>f</literal> has
36752 polymorphic type <literal>'a -&gt; 'a</literal> and both calls to <literal>f</literal> type check. On the
36753 other hand, in</simpara>
36754 <programlisting language="sml" linenumbering="unnumbered">val f = let in fn x =&gt; x end
36755 val _ = (f "foo"; f 13)</programlisting>
36756 <simpara>the expression <literal>let in fn x =&gt; end end</literal> is not syntactically a value
36757 and so <literal>f</literal> can either have type <literal>int -&gt; int</literal> or <literal>string -&gt; string</literal>,
36758 but not <literal>'a -&gt; 'a</literal>. Hence, the program does not type check.</simpara>
36759 <simpara><link linkend="DefinitionOfStandardML">The Definition of Standard ML</link> spells out
36760 precisely which expressions are syntactic values (it refers to such
36761 expressions as <emphasis>non-expansive</emphasis>). An expression is a value if it is of
36762 one of the following forms.</simpara>
36763 <itemizedlist>
36764 <listitem>
36765 <simpara>
36766 a constant (<literal>13</literal>, <literal>"foo"</literal>, <literal>13.0</literal>, &#8230;)
36767 </simpara>
36768 </listitem>
36769 <listitem>
36770 <simpara>
36771 a variable (<literal>x</literal>, <literal>y</literal>, &#8230;)
36772 </simpara>
36773 </listitem>
36774 <listitem>
36775 <simpara>
36776 a function (<literal>fn x =&gt; e</literal>)
36777 </simpara>
36778 </listitem>
36779 <listitem>
36780 <simpara>
36781 the application of a constructor other than <literal>ref</literal> to a value (<literal>Foo v</literal>)
36782 </simpara>
36783 </listitem>
36784 <listitem>
36785 <simpara>
36786 a type constrained value (<literal>v: t</literal>)
36787 </simpara>
36788 </listitem>
36789 <listitem>
36790 <simpara>
36791 a tuple in which each field is a value <literal>(v1, v2, ...)</literal>
36792 </simpara>
36793 </listitem>
36794 <listitem>
36795 <simpara>
36796 a record in which each field is a value <literal>{l1 = v1, l2 = v2, ...}</literal>
36797 </simpara>
36798 </listitem>
36799 <listitem>
36800 <simpara>
36801 a list in which each element is a value <literal>[v1, v2, ...]</literal>
36802 </simpara>
36803 </listitem>
36804 </itemizedlist>
36805 <section id="_why_the_value_restriction_exists">
36806 <title>Why the value restriction exists</title>
36807 <simpara>The value restriction prevents a ref cell (or an array) from holding
36808 values of different types, which would allow a value of one type to be
36809 cast to another and hence would break type safety. If the restriction
36810 were not in place, the following program would type check.</simpara>
36811 <programlisting language="sml" linenumbering="unnumbered">val r: 'a option ref = ref NONE
36812 val r1: string option ref = r
36813 val r2: int option ref = r
36814 val () = r1 := SOME "foo"
36815 val v: int = valOf (!r2)</programlisting>
36816 <simpara>The first line violates the value restriction because <literal>ref NONE</literal> is
36817 not a value. All other lines are type correct. By its last line, the
36818 program has cast the string <literal>"foo"</literal> to an integer. This breaks type
36819 safety, because now we can add a string to an integer with an
36820 expression like <literal>v + 13</literal>. We could even be more devious, by adding
36821 the following two lines, which allow us to threat the string <literal>"foo"</literal>
36822 as a function.</simpara>
36823 <programlisting language="sml" linenumbering="unnumbered">val r3: (int -&gt; int) option ref = r
36824 val v: int -&gt; int = valOf (!r3)</programlisting>
36825 <simpara>Eliminating the explicit <literal>ref</literal> does nothing to fix the problem. For
36826 example, we could replace the declaration of <literal>r</literal> with the following.</simpara>
36827 <programlisting language="sml" linenumbering="unnumbered">val f: unit -&gt; 'a option ref = fn () =&gt; ref NONE
36828 val r: 'a option ref = f ()</programlisting>
36829 <simpara>The declaration of <literal>f</literal> is well typed, while the declaration of <literal>r</literal>
36830 violates the value restriction because <literal>f ()</literal> is not a value.</simpara>
36831 </section>
36832 <section id="_unnecessarily_rejected_programs">
36833 <title>Unnecessarily rejected programs</title>
36834 <simpara>Unfortunately, the value restriction rejects some programs that could
36835 be accepted.</simpara>
36836 <programlisting language="sml" linenumbering="unnumbered">val id: 'a -&gt; 'a = fn x =&gt; x
36837 val f: 'a -&gt; 'a = id id</programlisting>
36838 <simpara>The type constraint on <literal>f</literal> requires <literal>f</literal> to be polymorphic, which is
36839 disallowed because <literal>id id</literal> is not a value. MLton reports the
36840 following type error.</simpara>
36841 <screen>Error: z.sml 2.5-2.5.
36842 Type of variable cannot be generalized in expansive declaration: f.
36843 type: ['a] -&gt; ['a]
36844 in: val 'a f: ('a -&gt; 'a) = id id</screen>
36845 <simpara>MLton indicates the inability to make <literal>f</literal> polymorphic by saying that
36846 the type of <literal>f</literal> cannot be generalized (made polymorphic) its
36847 declaration is expansive (not a value). MLton doesn&#8217;t explicitly
36848 mention the value restriction, but that is the reason. If we leave
36849 the type constraint off of <literal>f</literal></simpara>
36850 <programlisting language="sml" linenumbering="unnumbered">val id: 'a -&gt; 'a = fn x =&gt; x
36851 val f = id id</programlisting>
36852 <simpara>then the program succeeds; however, MLton gives us the following
36853 warning.</simpara>
36854 <screen>Warning: z.sml 2.5-2.5.
36855 Type of variable was not inferred and could not be generalized: f.
36856 type: ??? -&gt; ???
36857 in: val f = id id</screen>
36858 <simpara>This warning indicates that MLton couldn&#8217;t polymorphically generalize
36859 <literal>f</literal>, nor was there enough context using <literal>f</literal> to determine its type.
36860 This in itself is not a type error, but it it is a hint that something
36861 is wrong with our program. Using <literal>f</literal> provides enough context to
36862 eliminate the warning.</simpara>
36863 <programlisting language="sml" linenumbering="unnumbered">val id: 'a -&gt; 'a = fn x =&gt; x
36864 val f = id id
36865 val _ = f 13</programlisting>
36866 <simpara>But attempting to use <literal>f</literal> as a polymorphic function will fail.</simpara>
36867 <programlisting language="sml" linenumbering="unnumbered">val id: 'a -&gt; 'a = fn x =&gt; x
36868 val f = id id
36869 val _ = f 13
36870 val _ = f "foo"</programlisting>
36871 <screen>Error: z.sml 4.9-4.15.
36872 Function applied to incorrect argument.
36873 expects: [int]
36874 but got: [string]
36875 in: f "foo"</screen>
36876 </section>
36877 <section id="_alternatives_to_the_value_restriction">
36878 <title>Alternatives to the value restriction</title>
36879 <simpara>There would be nothing wrong with treating <literal>f</literal> as polymorphic in</simpara>
36880 <programlisting language="sml" linenumbering="unnumbered">val id: 'a -&gt; 'a = fn x =&gt; x
36881 val f = id id</programlisting>
36882 <simpara>One might think that the value restriction could be relaxed, and that
36883 only types involving <literal>ref</literal> should be disallowed. Unfortunately, the
36884 following example shows that even the type <literal>'a -&gt; 'a</literal> can cause
36885 problems. If this program were allowed, then we could cast an integer
36886 to a string (or any other type).</simpara>
36887 <programlisting language="sml" linenumbering="unnumbered">val f: 'a -&gt; 'a =
36888 let
36889 val r: 'a option ref = ref NONE
36890 in
36891 fn x =&gt;
36892 let
36893 val y = !r
36894 val () = r := SOME x
36895 in
36896 case y of
36897 NONE =&gt; x
36898 | SOME y =&gt; y
36899 end
36900 end
36901 val _ = f 13
36902 val _ = f "foo"</programlisting>
36903 <simpara>The previous version of Standard ML took a different approach
36904 (<link linkend="References_MilnerEtAl90">MilnerEtAl90</link>, <link linkend="References_Tofte90">Tofte90</link>, <link linkend="ImperativeTypeVariable">ImperativeTypeVariable</link>)
36905 than the value restriction. It encoded information in the type system
36906 about when ref cells would be created, and used this to prevent a ref
36907 cell from holding multiple types. Although it allowed more programs
36908 to be type checked, this approach had significant drawbacks. First,
36909 it was significantly more complex, both for implementers and for
36910 programmers. Second, it had an unfortunate interaction with the
36911 modularity, because information about ref usage was exposed in module
36912 signatures. This either prevented the use of references for
36913 implementing a signature, or required information that one would like
36914 to keep hidden to propagate across modules.</simpara>
36915 <simpara>In the early nineties, Andrew Wright studied about 250,000 lines of
36916 existing SML code and discovered that it did not make significant use
36917 of the extended typing ability, and proposed the value restriction as
36918 a simpler alternative (<link linkend="References_Wright95">Wright95</link>). This was adopted in the
36919 revised <link linkend="DefinitionOfStandardML">Definition</link>.</simpara>
36920 </section>
36921 <section id="_working_with_the_value_restriction">
36922 <title>Working with the value restriction</title>
36923 <simpara>One technique that works with the value restriction is
36924 <link linkend="EtaExpansion">EtaExpansion</link>. We can use eta expansion to make our <literal>id id</literal>
36925 example type check follows.</simpara>
36926 <programlisting language="sml" linenumbering="unnumbered">val id: 'a -&gt; 'a = fn x =&gt; x
36927 val f: 'a -&gt; 'a = fn z =&gt; (id id) z</programlisting>
36928 <simpara>This solution means that the computation (in this case <literal>id id</literal>) will
36929 be performed each time <literal>f</literal> is applied, instead of just once when <literal>f</literal>
36930 is declared. In this case, that is not a problem, but it could be if
36931 the declaration of <literal>f</literal> performs substantial computation or creates a
36932 shared data structure.</simpara>
36933 <simpara>Another technique that sometimes works is to move a monomorphic
36934 computation prior to a (would-be) polymorphic declaration so that the
36935 expression is a value. Consider the following program, which fails
36936 due to the value restriction.</simpara>
36937 <programlisting language="sml" linenumbering="unnumbered">datatype 'a t = A of string | B of 'a
36938 val x: 'a t = A (if true then "yes" else "no")</programlisting>
36939 <simpara>It is easy to rewrite this program as</simpara>
36940 <programlisting language="sml" linenumbering="unnumbered">datatype 'a t = A of string | B of 'a
36941 local
36942 val s = if true then "yes" else "no"
36943 in
36944 val x: 'a t = A s
36945 end</programlisting>
36946 <simpara>The following example (taken from <link linkend="References_Wright95">Wright95</link>) creates a ref
36947 cell to count the number of times a function is called.</simpara>
36948 <programlisting language="sml" linenumbering="unnumbered">val count: ('a -&gt; 'a) -&gt; ('a -&gt; 'a) * (unit -&gt; int) =
36949 fn f =&gt;
36950 let
36951 val r = ref 0
36952 in
36953 (fn x =&gt; (r := 1 + !r; f x), fn () =&gt; !r)
36954 end
36955 val id: 'a -&gt; 'a = fn x =&gt; x
36956 val (countId: 'a -&gt; 'a, numCalls) = count id</programlisting>
36957 <simpara>The example does not type check, due to the value restriction.
36958 However, it is easy to rewrite the program, staging the ref cell
36959 creation before the polymorphic code.</simpara>
36960 <programlisting language="sml" linenumbering="unnumbered">datatype t = T of int ref
36961 val count1: unit -&gt; t = fn () =&gt; T (ref 0)
36962 val count2: t * ('a -&gt; 'a) -&gt; (unit -&gt; int) * ('a -&gt; 'a) =
36963 fn (T r, f) =&gt; (fn () =&gt; !r, fn x =&gt; (r := 1 + !r; f x))
36964 val id: 'a -&gt; 'a = fn x =&gt; x
36965 val t = count1 ()
36966 val countId: 'a -&gt; 'a = fn z =&gt; #2 (count2 (t, id)) z
36967 val numCalls = #1 (count2 (t, id))</programlisting>
36968 <simpara>Of course, one can hide the constructor <literal>T</literal> inside a <literal>local</literal> or behind
36969 a signature.</simpara>
36970 </section>
36971 <section id="_also_see_50">
36972 <title>Also see</title>
36973 <itemizedlist>
36974 <listitem>
36975 <simpara>
36976 <link linkend="ImperativeTypeVariable">ImperativeTypeVariable</link>
36977 </simpara>
36978 </listitem>
36979 </itemizedlist>
36980 <simpara><?asciidoc-pagebreak?></simpara>
36981 </section>
36982 </section>
36983 <section id="VariableArityPolymorphism">
36984 <title>VariableArityPolymorphism</title>
36985 <simpara><link linkend="StandardML">Standard ML</link> programmers often face the problem of how to
36986 provide a variable-arity polymorphic function. For example, suppose
36987 one is defining a combinator library, e.g. for parsing or pickling.
36988 The signature for such a library might look something like the
36989 following.</simpara>
36990 <programlisting language="sml" linenumbering="unnumbered">signature COMBINATOR =
36991 sig
36992 type 'a t
36993
36994 val int: int t
36995 val real: real t
36996 val string: string t
36997 val unit: unit t
36998 val tuple2: 'a1 t * 'a2 t -&gt; ('a1 * 'a2) t
36999 val tuple3: 'a1 t * 'a2 t * 'a3 t -&gt; ('a1 * 'a2 * 'a3) t
37000 val tuple4: 'a1 t * 'a2 t * 'a3 t * 'a4 t
37001 -&gt; ('a1 * 'a2 * 'a3 * 'a4) t
37002 ...
37003 end</programlisting>
37004 <simpara>The question is how to define a variable-arity tuple combinator.
37005 Traditionally, the only way to take a variable number of arguments in
37006 SML is to put the arguments in a list (or vector) and pass that. So,
37007 one might define a tuple combinator with the following signature.</simpara>
37008 <programlisting language="sml" linenumbering="unnumbered">val tupleN: 'a list -&gt; 'a list t</programlisting>
37009 <simpara>The problem with this approach is that as soon as one places values in
37010 a list, they must all have the same type. So, programmers often take
37011 an alternative approach, and define a family of <literal>tuple&lt;N&gt;</literal> functions,
37012 as we see in the <literal>COMBINATOR</literal> signature above.</simpara>
37013 <simpara>The family-of-functions approach is ugly for many reasons. First, it
37014 clutters the signature with a number of functions when there should
37015 really only be one. Second, it is <emphasis>closed</emphasis>, in that there are a fixed
37016 number of tuple combinators in the interface, and should a client need
37017 a combinator for a large tuple, he is out of luck. Third, this
37018 approach often requires a lot of duplicate code in the implementation
37019 of the combinators.</simpara>
37020 <simpara>Fortunately, using <link linkend="Fold01N">Fold01N</link> and <link linkend="ProductType">products</link>, one can
37021 provide an interface and implementation that solves all these
37022 problems. Here is a simple pickling module that converts values to
37023 strings.</simpara>
37024 <programlisting language="sml" linenumbering="unnumbered">structure Pickler =
37025 struct
37026 type 'a t = 'a -&gt; string
37027
37028 val unit = fn () =&gt; ""
37029
37030 val int = Int.toString
37031
37032 val real = Real.toString
37033
37034 val string = id
37035
37036 type 'a accum = 'a * string list -&gt; string list
37037
37038 val tuple =
37039 fn z =&gt;
37040 Fold01N.fold
37041 {finish = fn ps =&gt; fn x =&gt; concat (rev (ps (x, []))),
37042 start = fn p =&gt; fn (x, l) =&gt; p x :: l,
37043 zero = unit}
37044 z
37045
37046 val ` =
37047 fn z =&gt;
37048 Fold01N.step1
37049 {combine = (fn (p, p') =&gt; fn (x &amp; x', l) =&gt; p' x' :: "," :: p (x, l))}
37050 z
37051 end</programlisting>
37052 <simpara>If one has <literal>n</literal> picklers of types</simpara>
37053 <programlisting language="sml" linenumbering="unnumbered">val p1: a1 Pickler.t
37054 val p2: a2 Pickler.t
37055 ...
37056 val pn: an Pickler.t</programlisting>
37057 <simpara>then one can construct a pickler for n-ary products as follows.</simpara>
37058 <programlisting language="sml" linenumbering="unnumbered">tuple `p1 `p2 ... `pn $ : (a1 &amp; a2 &amp; ... &amp; an) Pickler.t</programlisting>
37059 <simpara>For example, with <literal>Pickler</literal> in scope, one can prove the following
37060 equations.</simpara>
37061 <programlisting language="sml" linenumbering="unnumbered">"" = tuple $ ()
37062 "1" = tuple `int $ 1
37063 "1,2.0" = tuple `int `real $ (1 &amp; 2.0)
37064 "1,2.0,three" = tuple `int `real `string $ (1 &amp; 2.0 &amp; "three")</programlisting>
37065 <simpara>Here is the signature for <literal>Pickler</literal>. It shows why the <literal>accum</literal> type is
37066 useful.</simpara>
37067 <programlisting language="sml" linenumbering="unnumbered">signature PICKLER =
37068 sig
37069 type 'a t
37070
37071 val int: int t
37072 val real: real t
37073 val string: string t
37074 val unit: unit t
37075
37076 type 'a accum
37077 val ` : ('a accum, 'b t, ('a, 'b) prod accum,
37078 'z1, 'z2, 'z3, 'z4, 'z5, 'z6, 'z7) Fold01N.step1
37079 val tuple: ('a t, 'a accum, 'b accum, 'b t, unit t,
37080 'z1, 'z2, 'z3, 'z4, 'z5) Fold01N.t
37081 end
37082
37083 structure Pickler: PICKLER = Pickler</programlisting>
37084 <simpara><?asciidoc-pagebreak?></simpara>
37085 </section>
37086 <section id="Variant">
37087 <title>Variant</title>
37088 <simpara>A <emphasis>variant</emphasis> is an arm of a datatype declaration. For example, the
37089 datatype</simpara>
37090 <programlisting language="sml" linenumbering="unnumbered">datatype t = A | B of int | C of real</programlisting>
37091 <simpara>has three variants: <literal>A</literal>, <literal>B</literal>, and <literal>C</literal>.</simpara>
37092 <simpara><?asciidoc-pagebreak?></simpara>
37093 </section>
37094 <section id="VesaKarvonen">
37095 <title>VesaKarvonen</title>
37096 <simpara>Vesa Karvonen is a student at the <ulink url="http://www.cs.helsinki.fi/index.en.html">University of Helsinki</ulink>.
37097 His interests lie in programming techniques that allow complex programs to be expressed
37098 clearly and concisely and the design and implementation of programming languages.</simpara>
37099 <informalfigure>
37100 <mediaobject>
37101 <imageobject>
37102 <imagedata fileref="VesaKarvonen.attachments/vesa-in-mlton-t-shirt.jpg" align="center"/>
37103 </imageobject>
37104 <textobject><phrase>VesaKarvonen.attachments/vesa-in-mlton-t-shirt.jpg</phrase></textobject>
37105 </mediaobject>
37106 </informalfigure>
37107 <simpara>Things he&#8217;d like to see for SML and hopes to be able to contribute towards:</simpara>
37108 <itemizedlist>
37109 <listitem>
37110 <simpara>
37111 A practical tool for documenting libraries. Preferably one that is
37112 based on extracting the documentation from source code comments.
37113 </simpara>
37114 </listitem>
37115 <listitem>
37116 <simpara>
37117 A good IDE. Possibly an enhanced SML mode (<literal>esml-mode</literal>) for Emacs.
37118 Google for <ulink url="http://www.google.com/search?&amp;q=SLIME+video">SLIME video</ulink> to
37119 get an idea of what he&#8217;d like to see. Some specific notes:
37120 </simpara>
37121 <itemizedlist>
37122 <listitem>
37123 <simpara>
37124 show type at point
37125 </simpara>
37126 </listitem>
37127 <listitem>
37128 <simpara>
37129 robust, consistent indentation
37130 </simpara>
37131 </listitem>
37132 <listitem>
37133 <simpara>
37134 show documentation
37135 </simpara>
37136 </listitem>
37137 <listitem>
37138 <simpara>
37139 jump to definition (see <link linkend="EmacsDefUseMode">EmacsDefUseMode</link>)
37140 </simpara>
37141 </listitem>
37142 </itemizedlist>
37143 <simpara><link linkend="EmacsBgBuildMode">EmacsBgBuildMode</link> has also been written for working with MLton.</simpara>
37144 </listitem>
37145 <listitem>
37146 <simpara>
37147 Documented and cataloged libraries. Perhaps something like
37148 <ulink url="http://www.boost.org">Boost</ulink>, but for SML libraries. Here is a partial
37149 list of libraries, tools, and frameworks Vesa is or has been working
37150 on:
37151 </simpara>
37152 <itemizedlist>
37153 <listitem>
37154 <simpara>
37155 Asynchronous Programming Library (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/async/unstable/README"><literal>README</literal></ulink>)
37156 </simpara>
37157 </listitem>
37158 <listitem>
37159 <simpara>
37160 Extended Basis Library (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/extended-basis/unstable/README"><literal>README</literal></ulink>)
37161 </simpara>
37162 </listitem>
37163 <listitem>
37164 <simpara>
37165 Generic Programming Library (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/generic/unstable/README"><literal>README</literal></ulink>)
37166 </simpara>
37167 </listitem>
37168 <listitem>
37169 <simpara>
37170 Pretty Printing Library (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/prettier/unstable/README"><literal>README</literal></ulink>)
37171 </simpara>
37172 </listitem>
37173 <listitem>
37174 <simpara>
37175 Random Generator Library (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/random/unstable/README"><literal>README</literal></ulink>)
37176 </simpara>
37177 </listitem>
37178 <listitem>
37179 <simpara>
37180 RPC (Remote Procedure Call) Library (<ulink url="https://github.com/MLton/mltonlib/blob/master/org/mlton/vesak/rpc-lib/unstable/README"><literal>README</literal></ulink>)
37181 </simpara>
37182 </listitem>
37183 <listitem>
37184 <simpara>
37185 <ulink url="http://www.libsdl.org/">SDL</ulink> Binding (<ulink url="https://github.com/MLton/mltonlib/blob/master/org/mlton/vesak/sdl/unstable/README"><literal>README</literal></ulink>)
37186 </simpara>
37187 </listitem>
37188 <listitem>
37189 <simpara>
37190 Unit Testing Library (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/unit-test/unstable/README"><literal>README</literal></ulink>)
37191 </simpara>
37192 </listitem>
37193 <listitem>
37194 <simpara>
37195 Use Library (<ulink url="https://github.com/MLton/mltonlib/blob/master/org/mlton/vesak/use-lib/unstable/README"><literal>README</literal></ulink>)
37196 </simpara>
37197 </listitem>
37198 <listitem>
37199 <simpara>
37200 Windows Library (<ulink url="https://github.com/MLton/mltonlib/blob/master/com/ssh/windows/unstable/README"><literal>README</literal></ulink>)
37201 </simpara>
37202 </listitem>
37203 </itemizedlist>
37204 </listitem>
37205 </itemizedlist>
37206 <simpara>Note that most of these libraries have been ported to several <link linkend="StandardMLImplementations">SML implementations</link>.</simpara>
37207 <simpara><?asciidoc-pagebreak?></simpara>
37208 </section>
37209 <section id="WarnUnusedAnomalies">
37210 <title>WarnUnusedAnomalies</title>
37211 <simpara>The <literal>warnUnused</literal> <link linkend="MLBasisAnnotations">MLBasis annotation</link> can be used
37212 to report unused identifiers. This can be useful for catching bugs
37213 and for code maintenance (e.g., eliminating dead code). However, the
37214 <literal>warnUnused</literal> annotation can sometimes behave in counter-intuitive
37215 ways. This page gives some of the anomalies that have been reported.</simpara>
37216 <itemizedlist>
37217 <listitem>
37218 <simpara>
37219 Functions whose only uses are recursive uses within their bodies are
37220 not warned as unused:
37221 </simpara>
37222 <programlisting language="sml" linenumbering="unnumbered">local
37223 fun foo () = foo () : unit
37224 val bar = let fun baz () = baz () : unit in baz end
37225 in
37226 end</programlisting>
37227 <screen>Warning: z.sml 3.5.
37228 Unused variable: bar.</screen>
37229 </listitem>
37230 <listitem>
37231 <simpara>
37232 Components of actual functor argument that are necessary to match
37233 the functor argument signature but are unused in the body of the
37234 functor are warned as unused:
37235 </simpara>
37236 <programlisting language="sml" linenumbering="unnumbered">functor Warning (type t val x : t) = struct
37237 val y = x
37238 end
37239 structure X = Warning (type t = int val x = 1)</programlisting>
37240 <screen>Warning: z.sml 4.29.
37241 Unused type: t.</screen>
37242 </listitem>
37243 <listitem>
37244 <simpara>
37245 No component of a functor result is warned as unused. In the
37246 following, the only uses of <literal>f2</literal> are to match the functor argument
37247 signatures of <literal>functor G</literal> and <literal>functor H</literal> and there are no uses of
37248 <literal>z</literal>:
37249 </simpara>
37250 <programlisting language="sml" linenumbering="unnumbered">functor F(structure X : sig type t end) = struct
37251 type t = X.t
37252 fun f1 (_ : X.t) = ()
37253 fun f2 (_ : X.t) = ()
37254 val z = ()
37255 end
37256 functor G(structure Y : sig
37257 type t
37258 val f1 : t -&gt; unit
37259 val f2 : t -&gt; unit
37260 val z : unit
37261 end) = struct
37262 fun g (x : Y.t) = Y.f1 x
37263 end
37264 functor H(structure Y : sig
37265 type t
37266 val f1 : t -&gt; unit
37267 val f2 : t -&gt; unit
37268 val z : unit
37269 end) = struct
37270 fun h (x : Y.t) = Y.f1 x
37271 end
37272 functor Z() = struct
37273 structure S = F(structure X = struct type t = unit end)
37274 structure SG = G(structure Y = S)
37275 structure SH = H(structure Y = S)
37276 end
37277 structure U = Z()
37278 val _ = U.SG.g ()
37279 val _ = U.SH.h ()</programlisting>
37280 <screen></screen>
37281 </listitem>
37282 </itemizedlist>
37283 <simpara><?asciidoc-pagebreak?></simpara>
37284 </section>
37285 <section id="WesleyTerpstra">
37286 <title>WesleyTerpstra</title>
37287 <simpara>Wesley W. Terpstra is a PhD student at the Technische Universitat Darmstadt (Germany).</simpara>
37288 <simpara>Research interests</simpara>
37289 <itemizedlist>
37290 <listitem>
37291 <simpara>
37292 Distributed systems (P2P)
37293 </simpara>
37294 </listitem>
37295 <listitem>
37296 <simpara>
37297 Number theory (Error-correcting codes)
37298 </simpara>
37299 </listitem>
37300 </itemizedlist>
37301 <simpara>My interest in SML is centered on the fact the the language is able to directly express ideas from number theory which are important for my work. Modules and Functors seem to be a very natural basis for implementing many algebraic structures. MLton provides an ideal platform for actual implementation as it is fast and has unboxed words.</simpara>
37302 <simpara>Things I would like from MLton in the future:</simpara>
37303 <itemizedlist>
37304 <listitem>
37305 <simpara>
37306 Some better optimization of mathematical expressions
37307 </simpara>
37308 </listitem>
37309 <listitem>
37310 <simpara>
37311 IPv6 and multicast support
37312 </simpara>
37313 </listitem>
37314 <listitem>
37315 <simpara>
37316 A complete GUI toolkit like mGTK
37317 </simpara>
37318 </listitem>
37319 <listitem>
37320 <simpara>
37321 More supported platforms so that applications written under MLton have a wider audience
37322 </simpara>
37323 </listitem>
37324 </itemizedlist>
37325 <simpara><?asciidoc-pagebreak?></simpara>
37326 </section>
37327 <section id="WholeProgramOptimization">
37328 <title>WholeProgramOptimization</title>
37329 <simpara>Whole-program optimization is a compilation technique in which
37330 optimizations operate over the entire program. This allows the
37331 compiler many optimization opportunities that are not available when
37332 analyzing modules separately (as with separate compilation).</simpara>
37333 <simpara>Most of MLton&#8217;s optimizations are whole-program optimizations.
37334 Because MLton compiles the whole program at once, it can perform
37335 optimization across module boundaries. As a consequence, MLton often
37336 reduces or eliminates the run-time penalty that arises with separate
37337 compilation of SML features such as functors, modules, polymorphism,
37338 and higher-order functions. MLton takes advantage of having the
37339 entire program to perform transformations such as: defunctorization,
37340 monomorphisation, higher-order control-flow analysis, inlining,
37341 unboxing, argument flattening, redundant-argument removal, constant
37342 folding, and representation selection. Whole-program compilation is
37343 an integral part of the design of MLton and is not likely to change.</simpara>
37344 <simpara><?asciidoc-pagebreak?></simpara>
37345 </section>
37346 <section id="WishList">
37347 <title>WishList</title>
37348 <simpara>This page is mainly for recording recurring feature requests. If you
37349 have a new feature request, you probably want to query interest on one
37350 of the <link linkend="Contact">mailing lists</link> first.</simpara>
37351 <simpara>Please be aware of MLton&#8217;s policy on
37352 <link linkend="LanguageChanges">language changes</link>. Nonetheless, we hope to provide
37353 support for some of the "immediate" <link linkend="SuccessorML">SuccessorML</link> proposals in a
37354 future release.</simpara>
37355 <section id="_support_for_link_options_in_ml_basis_files">
37356 <title>Support for link options in ML Basis files</title>
37357 <simpara>Introduce a mechanism to specify link options in <link linkend="MLBasis">ML Basis</link>
37358 files. For example, generalizing a bit, a ML Basis declaration of the
37359 form</simpara>
37360 <screen>option "option"</screen>
37361 <simpara>could be introduced whose semantics would be the same (as closely as
37362 possible) as if the option string were specified on the compiler
37363 command line.</simpara>
37364 <simpara>The main motivation for this is that a MLton library that would
37365 introduce bindings (through <link linkend="ForeignFunctionInterface">FFI</link>) to an
37366 external library could be packaged conveniently as a single MLB file.
37367 For example, to link with library <literal>foo</literal> the MLB file would simply
37368 contain:</simpara>
37369 <screen>option "-link-opt -lfoo"</screen>
37370 <simpara>Similar feature requests have been discussed previously on the mailing lists:</simpara>
37371 <itemizedlist>
37372 <listitem>
37373 <simpara>
37374 <ulink url="http://www.mlton.org/pipermail/mlton/2004-July/025553.html">http://www.mlton.org/pipermail/mlton/2004-July/025553.html</ulink>
37375 </simpara>
37376 </listitem>
37377 <listitem>
37378 <simpara>
37379 <ulink url="http://www.mlton.org/pipermail/mlton/2005-January/026648.html">http://www.mlton.org/pipermail/mlton/2005-January/026648.html</ulink>
37380 </simpara>
37381 </listitem>
37382 </itemizedlist>
37383 <simpara><?asciidoc-pagebreak?></simpara>
37384 </section>
37385 </section>
37386 <section id="XML">
37387 <title>XML</title>
37388 <simpara><link linkend="XML">XML</link> is an <link linkend="IntermediateLanguage">IntermediateLanguage</link>, translated from <link linkend="CoreML">CoreML</link> by
37389 <link linkend="Defunctorize">Defunctorize</link>, optimized by <link linkend="XMLSimplify">XMLSimplify</link>, and translated by
37390 <link linkend="Monomorphise">Monomorphise</link> to <link linkend="SXML">SXML</link>.</simpara>
37391 <section id="_description_65">
37392 <title>Description</title>
37393 <simpara><link linkend="XML">XML</link> is polymorphic, higher-order, with flat patterns. Every
37394 <link linkend="XML">XML</link> expression is annotated with its type. Polymorphic
37395 generalization is made explicit through type variables annotating
37396 <literal>val</literal> and <literal>fun</literal> declarations. Polymorphic instantiation is made
37397 explicit by specifying type arguments at variable references. <link linkend="XML">XML</link>
37398 patterns can not be nested and can not contain wildcards, constraints,
37399 flexible records, or layering.</simpara>
37400 </section>
37401 <section id="_implementation_71">
37402 <title>Implementation</title>
37403 <itemizedlist>
37404 <listitem>
37405 <simpara>
37406 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/xml.sig"><literal>xml.sig</literal></ulink>
37407 </simpara>
37408 </listitem>
37409 <listitem>
37410 <simpara>
37411 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/xml.fun"><literal>xml.fun</literal></ulink>
37412 </simpara>
37413 </listitem>
37414 <listitem>
37415 <simpara>
37416 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/xml-tree.sig"><literal>xml-tree.sig</literal></ulink>
37417 </simpara>
37418 </listitem>
37419 <listitem>
37420 <simpara>
37421 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/xml-tree.fun"><literal>xml-tree.fun</literal></ulink>
37422 </simpara>
37423 </listitem>
37424 </itemizedlist>
37425 </section>
37426 <section id="_type_checking_8">
37427 <title>Type Checking</title>
37428 <simpara><link linkend="XML">XML</link> also has a type checker, used for debugging. At present, the
37429 type checker is also the best specification of the type system of
37430 <link linkend="XML">XML</link>. If you need more details, the type checker
37431 (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/type-check.sig"><literal>type-check.sig</literal></ulink>,
37432 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/type-check.fun"><literal>type-check.fun</literal></ulink>), is pretty short.</simpara>
37433 <simpara>Since the type checker does not affect the output of the compiler
37434 (unless it reports an error), it can be turned off. The type checker
37435 recursively descends the program, checking that the type annotating
37436 each node is the same as the type synthesized from the types of the
37437 expressions subnodes.</simpara>
37438 </section>
37439 <section id="_details_and_notes_68">
37440 <title>Details and Notes</title>
37441 <simpara><link linkend="XML">XML</link> uses the same atoms as <link linkend="CoreML">CoreML</link>, hence all identifiers
37442 (constructors, variables, etc.) are unique and can have properties
37443 attached to them. Finally, <link linkend="XML">XML</link> has a simplifier (<link linkend="XMLShrink">XMLShrink</link>),
37444 which implements a reduction system.</simpara>
37445 <section id="_types_3">
37446 <title>Types</title>
37447 <simpara><link linkend="XML">XML</link> types are either type variables or applications of n-ary type
37448 constructors. There are many utility functions for constructing and
37449 destructing types involving built-in type constructors.</simpara>
37450 <simpara>A type scheme binds list of type variables in a type. The only
37451 interesting operation on type schemes is the application of a type
37452 scheme to a list of types, which performs a simultaneous substitution
37453 of the type arguments for the bound type variables of the scheme. For
37454 the purposes of type checking, it is necessary to know the type scheme
37455 of variables, constructors, and primitives. This is done by
37456 associating the scheme with the identifier using its property list.
37457 This approach is used instead of the more traditional environment
37458 approach for reasons of speed.</simpara>
37459 </section>
37460 <section id="_xmltree">
37461 <title>XmlTree</title>
37462 <simpara>Before defining <literal>XML</literal>, the signature for language <link linkend="XML">XML</link>, we need to
37463 define an auxiliary signature <literal>XML_TREE</literal>, that contains the datatype
37464 declarations for the expression trees of <link linkend="XML">XML</link>. This is done solely
37465 for the purpose of modularity&#8201;&#8212;&#8201;it allows the simplifier and type
37466 checker to be defined by separate functors (which take a structure
37467 matching <literal>XML_TREE</literal>). Then, <literal>Xml</literal> is defined as the signature for a
37468 module containing the expression trees, the simplifier, and the type
37469 checker.</simpara>
37470 <simpara>Both constructors and variables can have type schemes, hence both
37471 constructor and variable references specify the instance of the scheme
37472 at the point of references. An instance is specified with a vector of
37473 types, which corresponds to the type variables in the scheme.</simpara>
37474 <simpara><link linkend="XML">XML</link> patterns are flat (i.e. not nested). A pattern is a
37475 constructor with an optional argument variable. Patterns only occur
37476 in <literal>case</literal> expressions. To evaluate a case expression, compare the
37477 test value sequentially against each pattern. For the first pattern
37478 that matches, destruct the value if necessary to bind the pattern
37479 variables and evaluate the corresponding expression. If no pattern
37480 matches, evaluate the default. All patterns of a case statement are
37481 of the same variant of <literal>Pat.t</literal>, although this is not enforced by ML&#8217;s
37482 type system. The type checker, however, does enforce this. Because
37483 tuple patterns are irrefutable, there will only ever be one tuple
37484 pattern in a case expression and there will be no default.</simpara>
37485 <simpara><link linkend="XML">XML</link> contains value, exception, and mutually recursive function
37486 declarations. There are no free type variables in <link linkend="XML">XML</link>. All type
37487 variables are explicitly bound at either a value or function
37488 declaration. At some point in the future, exception declarations may
37489 go away, and exceptions may be represented with a single datatype
37490 containing a <literal>unit ref</literal> component to implement genericity.</simpara>
37491 <simpara><link linkend="XML">XML</link> expressions are like those of <link linkend="CoreML">CoreML</link>, with the following
37492 exceptions. There are no records expressions. After type inference,
37493 all records (some of which may have originally been tuples in the
37494 source) are converted to tuples, because once flexible record patterns
37495 have been resolved, tuple labels are superfluous. Tuple components
37496 are ordered based on the field ordering relation. <link linkend="XML">XML</link> eta expands
37497 primitives and constructors so that there are always fully applied.
37498 Hence, the only kind of value of arrow type is a lambda. This
37499 property is useful for flow analysis and later in code generation.</simpara>
37500 <simpara>An <link linkend="XML">XML</link> program is a list of toplevel datatype declarations and a
37501 body expression. Because datatype declarations are not generative,
37502 the defunctorizer can safely move them to toplevel.</simpara>
37503 <simpara><?asciidoc-pagebreak?></simpara>
37504 </section>
37505 </section>
37506 </section>
37507 <section id="XMLShrink">
37508 <title>XMLShrink</title>
37509 <simpara>XMLShrink is an optimization pass for the <link linkend="XML">XML</link>
37510 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="XMLSimplify">XMLSimplify</link>.</simpara>
37511 <section id="_description_66">
37512 <title>Description</title>
37513 <simpara>This pass performs optimizations based on a reduction system.</simpara>
37514 </section>
37515 <section id="_implementation_72">
37516 <title>Implementation</title>
37517 <itemizedlist>
37518 <listitem>
37519 <simpara>
37520 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/shrink.sig"><literal>shrink.sig</literal></ulink>
37521 </simpara>
37522 </listitem>
37523 <listitem>
37524 <simpara>
37525 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/shrink.fun"><literal>shrink.fun</literal></ulink>
37526 </simpara>
37527 </listitem>
37528 </itemizedlist>
37529 </section>
37530 <section id="_details_and_notes_69">
37531 <title>Details and Notes</title>
37532 <simpara>The simplifier is based on <link linkend="References_AppelJim97">Shrinking Lambda Expressions in Linear Time</link>.</simpara>
37533 <simpara>The source program may contain functions that are only called once, or
37534 not even called at all. Match compilation introduces many such
37535 functions. In order to reduce the program size, speed up later
37536 phases, and improve the flow analysis, a source to source simplifier
37537 is run on <link linkend="XML">XML</link> after type inference and match compilation.</simpara>
37538 <simpara>The simplifier implements the reductions shown below. The reductions
37539 eliminate unnecessary declarations (see the side constraint in the
37540 figure), applications where the function is immediate, and case
37541 statements where the test is immediate. Declarations can be
37542 eliminated only when the expression is nonexpansive (see Section 4.7
37543 of the <link linkend="DefinitionOfStandardML">Definition</link>), which is a syntactic
37544 condition that ensures that the expression has no effects
37545 (assignments, raises, or nontermination). The reductions on case
37546 statements do not show the other irrelevant cases that may exist. The
37547 reductions were chosen so that they were strongly normalizing and so
37548 that they never increased tree size.</simpara>
37549 <itemizedlist>
37550 <listitem>
37551 <simpara>
37552 </simpara>
37553 <programlisting language="sml" linenumbering="unnumbered">let x = e1 in e2</programlisting>
37554 <simpara>reduces to</simpara>
37555 <programlisting language="sml" linenumbering="unnumbered">e2 [x -&gt; e1]</programlisting>
37556 <simpara>if <literal>e1</literal> is a constant or variable or if <literal>e1</literal> is nonexpansive and <literal>x</literal> occurs zero or one time in <literal>e2</literal></simpara>
37557 </listitem>
37558 <listitem>
37559 <simpara>
37560 </simpara>
37561 <programlisting language="sml" linenumbering="unnumbered">(fn x =&gt; e1) e2</programlisting>
37562 <simpara>reduces to</simpara>
37563 <programlisting language="sml" linenumbering="unnumbered">let x = e2 in e1</programlisting>
37564 </listitem>
37565 <listitem>
37566 <simpara>
37567 </simpara>
37568 <programlisting language="sml" linenumbering="unnumbered">e1 handle e2</programlisting>
37569 <simpara>reduces to</simpara>
37570 <programlisting language="sml" linenumbering="unnumbered">e1</programlisting>
37571 <simpara>if <literal>e1</literal> is nonexpansive</simpara>
37572 </listitem>
37573 <listitem>
37574 <simpara>
37575 </simpara>
37576 <programlisting language="sml" linenumbering="unnumbered">case let d in e end of p1 =&gt; e1 ...</programlisting>
37577 <simpara>reduces to</simpara>
37578 <programlisting language="sml" linenumbering="unnumbered">let d in case e of p1 =&gt; e1 ... end</programlisting>
37579 </listitem>
37580 <listitem>
37581 <simpara>
37582 </simpara>
37583 <programlisting language="sml" linenumbering="unnumbered">case C e1 of C x =&gt; e2</programlisting>
37584 <simpara>reduces to</simpara>
37585 <programlisting language="sml" linenumbering="unnumbered">let x = e1 in e2</programlisting>
37586 </listitem>
37587 </itemizedlist>
37588 <simpara><?asciidoc-pagebreak?></simpara>
37589 </section>
37590 </section>
37591 <section id="XMLSimplify">
37592 <title>XMLSimplify</title>
37593 <simpara>The optimization passes for the <link linkend="XML">XML</link> <link linkend="IntermediateLanguage">IntermediateLanguage</link> are
37594 collected and controlled by the <literal>XmlSimplify</literal> functor
37595 (<ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/xml-simplify.sig"><literal>xml-simplify.sig</literal></ulink>,
37596 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/xml-simplify.fun"><literal>xml-simplify.fun</literal></ulink>).</simpara>
37597 <simpara>The following optimization passes are implemented:</simpara>
37598 <itemizedlist>
37599 <listitem>
37600 <simpara>
37601 <link linkend="XMLSimplifyTypes">XMLSimplifyTypes</link>
37602 </simpara>
37603 </listitem>
37604 <listitem>
37605 <simpara>
37606 <link linkend="XMLShrink">XMLShrink</link>
37607 </simpara>
37608 </listitem>
37609 </itemizedlist>
37610 <simpara>The optimization passes can be controlled from the command-line by the options</simpara>
37611 <itemizedlist>
37612 <listitem>
37613 <simpara>
37614 <literal>-diag-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;keep diagnostic info for pass
37615 </simpara>
37616 </listitem>
37617 <listitem>
37618 <simpara>
37619 <literal>-disable-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;skip optimization pass (if normally performed)
37620 </simpara>
37621 </listitem>
37622 <listitem>
37623 <simpara>
37624 <literal>-enable-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;perform optimization pass (if normally skipped)
37625 </simpara>
37626 </listitem>
37627 <listitem>
37628 <simpara>
37629 <literal>-keep-pass &lt;pass&gt;</literal>&#8201;&#8212;&#8201;keep the results of pass
37630 </simpara>
37631 </listitem>
37632 <listitem>
37633 <simpara>
37634 <literal>-xml-passes &lt;passes&gt;</literal>&#8201;&#8212;&#8201;xml optimization passes
37635 </simpara>
37636 </listitem>
37637 </itemizedlist>
37638 <simpara><?asciidoc-pagebreak?></simpara>
37639 </section>
37640 <section id="XMLSimplifyTypes">
37641 <title>XMLSimplifyTypes</title>
37642 <simpara><link linkend="XMLSimplifyTypes">XMLSimplifyTypes</link> is an optimization pass for the <link linkend="XML">XML</link>
37643 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="XMLSimplify">XMLSimplify</link>.</simpara>
37644 <section id="_description_67">
37645 <title>Description</title>
37646 <simpara>This pass simplifies types in an <link linkend="XML">XML</link> program, eliminating all
37647 unused type arguments.</simpara>
37648 </section>
37649 <section id="_implementation_73">
37650 <title>Implementation</title>
37651 <itemizedlist>
37652 <listitem>
37653 <simpara>
37654 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/simplify-types.sig"><literal>simplify-types.sig</literal></ulink>
37655 </simpara>
37656 </listitem>
37657 <listitem>
37658 <simpara>
37659 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/xml/simplify-types.fun"><literal>simplify-types.fun</literal></ulink>
37660 </simpara>
37661 </listitem>
37662 </itemizedlist>
37663 </section>
37664 <section id="_details_and_notes_70">
37665 <title>Details and Notes</title>
37666 <simpara>It first computes a simple fixpoint on all the <literal>datatype</literal> declarations
37667 to determine which <literal>datatype</literal> <literal>tycon</literal> args are actually used. Then it
37668 does a single pass over the program to determine which polymorphic
37669 declaration type variables are used, and rewrites types to eliminate
37670 unused type arguments.</simpara>
37671 <simpara>This pass should eliminate any spurious duplication that the
37672 <link linkend="Monomorphise">Monomorphise</link> pass might perform due to phantom types.</simpara>
37673 <simpara><?asciidoc-pagebreak?></simpara>
37674 </section>
37675 </section>
37676 <section id="Zone">
37677 <title>Zone</title>
37678 <simpara><link linkend="Zone">Zone</link> is an optimization pass for the <link linkend="SSA2">SSA2</link>
37679 <link linkend="IntermediateLanguage">IntermediateLanguage</link>, invoked from <link linkend="SSA2Simplify">SSA2Simplify</link>.</simpara>
37680 <section id="_description_68">
37681 <title>Description</title>
37682 <simpara>This pass breaks large <link linkend="SSA2">SSA2</link> functions into zones, which are
37683 connected subgraphs of the dominator tree. For each zone, at the node
37684 that dominates the zone (the "zone root"), it places a tuple
37685 collecting all of the live variables at that node. It replaces any
37686 variables used in that zone with offsets from the tuple. The goal is
37687 to decrease the liveness information in large <link linkend="SSA">SSA</link> functions.</simpara>
37688 </section>
37689 <section id="_implementation_74">
37690 <title>Implementation</title>
37691 <itemizedlist>
37692 <listitem>
37693 <simpara>
37694 <ulink url="https://github.com/MLton/mlton/blob/master/mlton/ssa/zone.fun"><literal>zone.fun</literal></ulink>
37695 </simpara>
37696 </listitem>
37697 </itemizedlist>
37698 </section>
37699 <section id="_details_and_notes_71">
37700 <title>Details and Notes</title>
37701 <simpara>Compute strongly-connected components to avoid put tuple constructions
37702 in loops.</simpara>
37703 <simpara>There are two (expert) flags that govern the use of this pass</simpara>
37704 <itemizedlist>
37705 <listitem>
37706 <simpara>
37707 <literal>-max-function-size &lt;n&gt;</literal>
37708 </simpara>
37709 </listitem>
37710 <listitem>
37711 <simpara>
37712 <literal>-zone-cut-depth &lt;n&gt;</literal>
37713 </simpara>
37714 </listitem>
37715 </itemizedlist>
37716 <simpara>Zone splitting only works when the number of basic blocks in a
37717 function is greater than <literal>n</literal>. The <literal>n</literal> used to cut the dominator tree
37718 is set by <literal>-zone-cut-depth</literal>.</simpara>
37719 <simpara>There is currently no attempt to be safe-for-space. That is, the
37720 tuples are not restricted to containing only "small" values.</simpara>
37721 <simpara>In the <literal>HOL</literal> program, the particular problem is the main function,
37722 which has 161,783 blocks and 257,519 variables&#8201;&#8212;&#8201;the product of those
37723 two numbers being about 41 billion. Now, we&#8217;re not likely going to
37724 need that much space since we use a sparse representation. But even
37725 1/100th would really hurt. And of course this rules out bit vectors.</simpara>
37726 <simpara><?asciidoc-pagebreak?></simpara>
37727 </section>
37728 </section>
37729 <section id="ZZZOrphanedPages">
37730 <title>ZZZOrphanedPages</title>
37731 <simpara>The contents of these pages have been moved to other pages.</simpara>
37732 <simpara>These templates are used by other pages.</simpara>
37733 <itemizedlist>
37734 <listitem>
37735 <simpara>
37736 <link linkend="CompilerPassTemplate">CompilerPassTemplate</link>
37737 </simpara>
37738 </listitem>
37739 <listitem>
37740 <simpara>
37741 <link linkend="TalkTemplate">TalkTemplate</link>
37742 </simpara>
37743 </listitem>
37744 </itemizedlist>
37745 <simpara><?asciidoc-pagebreak?></simpara>
37746 </section>
37747 </article>