This file is indexed.

/usr/share/doc/mlton/guide/MLBasisExamples is in mlton-doc 20100608-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="robots" content="index,nofollow">



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


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


</head>

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

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-833377-1";
urchinTracker();
</script>
<table bgcolor = lightblue cellspacing = 0 style = "border: 0px;" width = 100%>
  <tr>
    <td style = "
		border: 0px;
		color: darkblue; 
		font-size: 150%;
		text-align: left;">
      <a class = mltona href="Home">MLton MLTONWIKIVERSION</a>
    <td style = "
		border: 0px;
		font-size: 150%;
		text-align: center;
		width: 50%;">
      MLBasisExamples
    <td style = "
		border: 0px;
		text-align: right;">
      <table cellspacing = 0 style = "border: 0px">
        <tr style = "vertical-align: middle;">
      </table>
  <tr style = "background-color: white;">
    <td colspan = 3
	style = "
		border: 0px;
		font-size:70%;
		text-align: right;">
      <a href = "Home">Home</a>
      &nbsp;<a href = "TitleIndex">Index</a>
      &nbsp;
</table>
<div id="content" lang="en" dir="ltr">
Here are some example uses of <a href="MLBasis">ML Basis</a> files. <h2 id="head-47367b6e18a7e13a70299d934342eaad85f98a84">Complete program</h2>
Suppose your complete program consists of the files <tt>file1.sml</tt>, ..., <tt>filen.sml</tt>, which depend upon libraries <tt>lib1.mlb</tt>, ..., <tt>libm.mlb</tt>. 
<pre>(* import libraries *)
lib1.mlb
...
libm.mlb

(* program files *)
file1.sml
...
filen.sml
</pre><p>
The bases denoted by <tt>lib1.mlb</tt>, ..., <tt>libm.mlb</tt> are merged (bindings of names in later bases take precedence over bindings of the same name in earlier bases), producing a basis in which <tt>file1.sml</tt>, ..., <tt>filen.sml</tt> are elaborated, adding additional bindings to the basis. 
</p>
<h2 id="head-bbdea99ed8fa0bf96f01819de00940a9a5bd15df">Export filter</h2>
<p>
Suppose you only want to export certain structures, signatures, and functors from a collection of files. 
</p>

<pre>local
  file1.sml
  ...
  filen.sml
in
  (* export filter here *)
  functor F
  structure S
end
</pre><p>
While <tt>file1.sml</tt>, ..., <tt>filen.sml</tt> may declare top-level identifiers in addition to <tt>F</tt> and <tt>S</tt>, such names are not accessible to programs and libraries that import this <tt>.mlb</tt>. 
</p>
<h2 id="head-109e200ced2bf5d4c6ce6619a4e1f67caf0b81a5">Export filter with renaming</h2>
<p>
Suppose you want an export filter, but want to rename one of the modules. 
</p>

<pre>local
  file1.sml
  ...
  filen.sml
in
  (* export filter, with renaming, here *)
  functor F
  structure S' = S
end
</pre><p>
Note that <tt>functor&nbsp;F</tt> is an abbreviation for <tt>functor&nbsp;F&nbsp;=&nbsp;F</tt>, which simply exports an identifier under the same name. 
</p>
<h2 id="head-f266e8ecbc717ff659224d8ad3a7d4a937429adb">Import filter</h2>
<p>
Suppose you only want to import a functor <tt>F</tt> from one library and a structure <tt>S</tt> from another library. 
</p>

<pre>local
  lib1.mlb
in
  (* import filter here *)
  functor F
end
local
  lib2.mlb
in
  (* import filter here *)
  structure S
end
file1.sml
...
filen.sml
</pre><h2 id="head-90f8bc63c1e2a572a4d5c05af4cd2c6c8ebd0080">Import filter with renaming</h2>
<p>
Suppose you want to import a structure <tt>S</tt> from one library and another structure <tt>S</tt> from another library. 
</p>

<pre>local
  lib1.mlb
in
  (* import filter, with renaming, here *)
  structure S1 = S
end
local
  lib2.mlb
in
  (* import filter, with renaming, here *)
  structure S2 = S
end
file1.sml
...
filen.sml
</pre><h2 id="head-b0df1400a6248030b137c5676e8feb1a2195343d">Full Basis</h2>
<p>
Since the Modules level of SML is the natural means for organizing program and library components, MLB files provide convenient syntax for renaming Modules level identifiers (in fact, renaming of functor identifiers provides a mechanism that is not available in SML). However, please note that <tt>.mlb</tt> files elaborate to full bases including top-level types and values (including infix status), in addition to structures, signatures, and functors.  For example, suppose you wished to extend the <a href="BasisLibrary">Basis Library</a> with an <tt>('a,&nbsp;'b)&nbsp;either</tt> datatype corresponding to a disjoint sum; the type and some operations should be available at the top-level; additionally, a signature and structure provide the complete interface. 
</p>
<p>
We could use the following files. 
</p>
<p>
<tt>either-sigs.sml</tt> 
</p>

    <ul>

 
<pre class=code>
<B><FONT COLOR="#0000FF">signature</FONT></B> EITHER_GLOBAL =
  <B><FONT COLOR="#0000FF">sig</FONT></B>
    <B><FONT COLOR="#A020F0">datatype</FONT></B><B><FONT COLOR="#228B22"> ('a, 'b) either </FONT></B>=<B><FONT COLOR="#228B22"> <FONT COLOR="#B8860B">Left</FONT> <B><FONT COLOR="#A020F0">of</FONT></B> 'a </FONT></B>|<B><FONT COLOR="#228B22"> <FONT COLOR="#B8860B">Right</FONT> <B><FONT COLOR="#A020F0">of</FONT></B> 'b
    </FONT></B><B><FONT COLOR="#A020F0">val</FONT></B> &amp;  : ('a -&gt; 'c) * ('b -&gt; 'c) -&gt; ('a, 'b) either -&gt; 'c
    <B><FONT COLOR="#A020F0">val</FONT></B> &amp;&amp; : ('a -&gt; 'c) * ('b -&gt; 'd) -&gt; ('a, 'b) either -&gt; ('c, 'd) either
  <B><FONT COLOR="#0000FF">end</FONT></B>

<B><FONT COLOR="#0000FF">signature</FONT></B> EITHER =
  <B><FONT COLOR="#0000FF">sig</FONT></B>
    <B><FONT COLOR="#0000FF">include</FONT></B> EITHER_GLOBAL
    <B><FONT COLOR="#A020F0">val</FONT></B> isLeft  : ('a, 'b) either -&gt; bool
    <B><FONT COLOR="#A020F0">val</FONT></B> isRight : ('a, 'b) either -&gt; bool
    ...
  <B><FONT COLOR="#0000FF">end</FONT></B>
</PRE>
<p>
 
</p>

    </ul>


<p>
<tt>either-strs.sml</tt> 
</p>

    <ul>

 
<pre class=code>
<B><FONT COLOR="#0000FF">structure</FONT></B> Either : EITHER =
  <B><FONT COLOR="#0000FF">struct</FONT></B>
    <B><FONT COLOR="#A020F0">datatype</FONT></B><B><FONT COLOR="#228B22"> ('a, 'b) either </FONT></B>=<B><FONT COLOR="#228B22"> <FONT COLOR="#B8860B">Left</FONT> <B><FONT COLOR="#A020F0">of</FONT></B> 'a </FONT></B>|<B><FONT COLOR="#228B22"> <FONT COLOR="#B8860B">Right</FONT> <B><FONT COLOR="#A020F0">of</FONT></B> 'b
    </FONT></B><B><FONT COLOR="#A020F0">fun</FONT></B> f &amp; g = <B><FONT COLOR="#A020F0">fn</FONT></B> x =&gt;
      <B><FONT COLOR="#A020F0">case</FONT></B> x <B><FONT COLOR="#A020F0">of</FONT></B> Left z =&gt; f z | Right z =&gt; g z
    <B><FONT COLOR="#A020F0">fun</FONT></B> f &amp;&amp; g = (Left o f) &amp; (Right o g)
    <B><FONT COLOR="#A020F0">fun</FONT></B> isLeft x = ((<B><FONT COLOR="#A020F0">fn</FONT></B> _ =&gt; true) &amp; (<B><FONT COLOR="#A020F0">fn</FONT></B> _ =&gt; false)) x
    <B><FONT COLOR="#A020F0">fun</FONT></B> isRight x = (not o isLeft) x
    ...
  <B><FONT COLOR="#0000FF">end</FONT></B>
<B><FONT COLOR="#0000FF">structure</FONT></B> EitherGlobal : EITHER_GLOBAL = Either
</PRE>
<p>
 
</p>

    </ul>


<p>
<tt>either-infixes.sml</tt> 
</p>

    <ul>

 
<pre class=code>
<B><FONT COLOR="#A020F0">infixr</FONT></B> 3 &amp; &amp;&amp;
</PRE>
<p>
 
</p>

    </ul>


<p>
<tt>either-open.sml</tt> 
</p>

    <ul>

 
<pre class=code>
<B><FONT COLOR="#0000FF">open</FONT></B> EitherGlobal
</PRE>
<p>
 
</p>

    </ul>


<p>
<tt>either.mlb</tt> 
</p>

    <ul>

 
<pre>either-infixes.sml
local
  (* import Basis Library *)
  $(SML_LIB)/basis/basis.mlb
  either-sigs.sml
  either-strs.sml
in
  signature EITHER
  structure Either
  either-open.sml
end
</pre>
    </ul>


<p>
A client that imports <tt>either.mlb</tt> will have access to neither <tt>EITHER_GLOBAL</tt> nor <tt>EitherGlobal</tt>, but will have access to the type <tt>either</tt> and the values <tt>&amp;</tt> and <tt>&amp;&amp;</tt> (with infix status) in the top-level environment.  Note that  <tt>either-infixes.sml</tt> is outside the scope of the local, because we want the infixes available in the implementation of the library and to clients of the library. 
</p>
</div>



<p>
<hr>
Last edited on 2005-12-02 04:21:48 by <span title="ppp-71-139-183-221.dsl.snfc21.pacbell.net"><a href="StephenWeeks">StephenWeeks</a></span>.
</body></html>