1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<HTML>
3<HEAD>
4	<TITLE>The Universal structure</TITLE>
5<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6<link href="docstyle.css" rel="stylesheet" type="text/css">
7</HEAD>
8<BODY BGCOLOR="#ffffff">
9<ul class="nav">
10	<li><a href="Threads.html">Previous</a></li>
11	<li><a href="Basis.html">Up</a></li>
12	<li><a href="Weak.html">Next</a></li>
13</ul>
14<H2><STRONG><font face="Arial, Helvetica, sans-serif">Universal structure</font></STRONG></H2>
15<p>The <span class="identifier">Universal</span> structure provides a universal 
16  union type. It allows value of any type to be stored in a single table without 
17  knowing in advance the types to be stored. Note that this is not the same as 
18  a dynamic type. The values are discriminated by the tag, not by the type. There 
19  may be more than one tag that can be used with values of a particular type and 
20  these are treated as completely different. <span class="identifier">Universal</span> 
21  is built in for efficiency reasons but it is perfectly feasible to implement 
22  it in Standard ML using <span class="identifier">exception</span> bindings. 
23</p>
24<pre class="mainsig">structure Universal:
25  sig
26    type universal
27    type 'a tag
28    val tag: unit -&gt; 'a tag
29    val tagInject: 'a tag -&gt; 'a -&gt; universal
30    val tagIs: 'a tag -&gt; universal -&gt; bool
31    val tagProject: 'a tag -&gt; universal -&gt; 'a
32  end</pre>
33<div class="entryblock"> 
34  <pre class="entrycode"><a name="universal" id="universal"></a>type universal</pre>
35  <div class="entrytext">
36    <p>The type of the universal union.</p>
37  </div>
38</div>
39<div class="entryblock"> 
40  <pre class="entrycode"><a name="tag_type" id="tag_type"></a>type 'a tag</pre>
41  <div class="entrytext">
42    <p>The type of a tag that can be used to mark a value of the argument type.</p>
43  </div>
44</div>
45<div class="entryblock"> 
46  <pre class="entrycode"><a name="tag" id="tag"></a>val tag: unit -&gt; 'a tag</pre>
47  <div class="entrytext">
48    <p>Create a tag that can be used to identify a value of a particular type.</p>
49  </div>
50</div>
51<div class="entryblock"> 
52  <pre class="entrycode"><a name="tagInject" id="tagInject"></a>val tagInject: 'a tag -&gt; 'a -&gt; universal</pre>
53  <div class="entrytext">
54    <p>Inject a value into the union. This marks the value with the tag.</p>
55  </div>
56</div>
57<div class="entryblock"> 
58  <pre class="entrycode"><a name="tagIs" id="tagIs"></a>val tagIs: 'a tag -&gt; universal -&gt; bool</pre>
59  <div class="entrytext">
60    <p>Test whether the value was marked with the tag.</p>
61  </div>
62</div>
63<div class="entryblock"> 
64  <pre class="entrycode"><a name="tagProject" id="tagProject"></a>val tagProject: 'a tag -&gt; universal -&gt; 'a</pre>
65  <div class="entrytext">
66    <p>Project a value from the union. The tag must match the tag that was used 
67      to create union value otherwise a <span class="identifier">Match</span> 
68      exception will be raised.</p>
69  </div>
70</div>
71<ul class="nav">
72	<li><a href="Threads.html">Previous</a></li>
73	<li><a href="Basis.html">Up</a></li>
74	<li><a href="Weak.html">Next</a></li>
75</ul>
76</BODY>
77</HTML>