File: Overloading

package info (click to toggle)
mlton 20130715-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 60,900 kB
  • ctags: 69,386
  • sloc: xml: 34,418; ansic: 17,399; lisp: 2,879; makefile: 1,605; sh: 1,254; pascal: 256; python: 143; asm: 97
file content (136 lines) | stat: -rw-r--r-- 6,465 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.8">
<title>Overloading</title>
<link rel="stylesheet" href="./asciidoc.css" type="text/css">
<link rel="stylesheet" href="./pygments.css" type="text/css">


<script type="text/javascript" src="./asciidoc.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install();
/*]]>*/
</script>
<link rel="stylesheet" href="./mlton.css" type="text/css"/>
</head>
<body class="article">
<div id="banner">
<div id="banner-home">
<a href="./Home">MLton 20130715</a>
</div>
</div>
<div id="header">
<h1>Overloading</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>In <a href="StandardML">Standard ML</a>, constants (like <span class="monospaced">13</span>, <span class="monospaced">0w13</span>, <span class="monospaced">13.0</span>)
are overloaded, meaning that they can denote a constant of the
appropriate type as determined by context.  SML defines the
overloading classes <em>Int</em>, <em>Real</em>, and <em>Word</em>, which denote the sets
of types that integer, real, and word constants may take on.  In
MLton, these are defined as follows.</p></div>
<table class="tableblock frame-all grid-all"
style="
width:100%;
">
<col style="width:25%;">
<col style="width:75%;">
<tbody>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock"><em>Int</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">Int2.int</span>, <span class="monospaced">Int3.int</span>, &#8230; <span class="monospaced">Int32.int</span>, <span class="monospaced">Int64.int</span>, <span class="monospaced">Int.int</span>, <span class="monospaced">IntInf.int</span>, <span class="monospaced">LargeInt.int</span>, <span class="monospaced">FixedInt.int</span>, <span class="monospaced">Position.int</span></p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock"><em>Real</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">Real32.real</span>, <span class="monospaced">Real64.real</span>, <span class="monospaced">Real.real</span>, <span class="monospaced">LargeReal.real</span></p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock"><em>Word</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">Word2.word</span>, <span class="monospaced">Word3.word</span>, &#8230; <span class="monospaced">Word32.word</span>, <span class="monospaced">Word64.word</span>, <span class="monospaced">Word.word</span>, <span class="monospaced">LargeWord.word</span>, <span class="monospaced">SysWord.word</span></p></td>
</tr>
</tbody>
</table>
<div class="paragraph"><p>The <a href="DefinitionOfStandardML">Definition</a> allows flexibility in how
much context is used to resolve overloading.  It says that the context
is <em>no larger than the smallest enclosing structure-level
declaration</em>, but that <em>an implementation may require that a smaller
context determines the type</em>.  MLton uses the largest possible context
allowed by SML in resolving overloading.  If the type of a constant is
not determined by context, then it takes on a default type.  In MLton,
these are defined as follows.</p></div>
<table class="tableblock frame-all grid-all"
style="
width:100%;
">
<col style="width:25%;">
<col style="width:75%;">
<tbody>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock"><em>Int</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">Int.int</span></p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock"><em>Real</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">Real.real</span></p></td>
</tr>
<tr>
<td class="tableblock halign-center valign-top" ><p class="tableblock"><em>Word</em></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">Word.word</span></p></td>
</tr>
</tbody>
</table>
<div class="paragraph"><p>Other implementations may use a smaller context or different default
types.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_also_see">Also see</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
<a href="http://www.standardml.org/Basis/top-level-chapter.html">discussion of overloading in the Basis Library</a>
</p>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_examples">Examples</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
The following program is rejected.
</p>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">structure</span><span class="w"> </span><span class="n">S</span><span class="p">:</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="p">:</span><span class="w"> </span><span class="n">Word8</span><span class="p">.</span><span class="n">word</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">struct</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="mi">0w0</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>The smallest enclosing structure declaration for <span class="monospaced">0w0</span> is
<span class="monospaced">val x = 0w0</span>.  Hence, <span class="monospaced">0w0</span> receives the default type for words,
which is <span class="monospaced">Word.word</span>.</p></div>
</li>
</ul></div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
</div>
<div id="footer-badges">
</div>
</div>
</body>
</html>