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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>The Universal structure</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="docstyle.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY BGCOLOR="#ffffff">
<ul class="nav">
<li><a href="Threads.html">Previous</a></li>
<li><a href="Basis.html">Up</a></li>
<li><a href="Weak.html">Next</a></li>
</ul>
<H2><STRONG><font face="Arial, Helvetica, sans-serif">Universal structure</font></STRONG></H2>
<p>The <span class="identifier">Universal</span> structure provides a universal
union type. It allows value of any type to be stored in a single table without
knowing in advance the types to be stored. Note that this is not the same as
a dynamic type. The values are discriminated by the tag, not by the type. There
may be more than one tag that can be used with values of a particular type and
these are treated as completely different. <span class="identifier">Universal</span>
is built in for efficiency reasons but it is perfectly feasible to implement
it in Standard ML using <span class="identifier">exception</span> bindings.
</p>
<pre class="mainsig">structure Universal:
sig
type universal
type 'a tag
val tag: unit -> 'a tag
val tagInject: 'a tag -> 'a -> universal
val tagIs: 'a tag -> universal -> bool
val tagProject: 'a tag -> universal -> 'a
end</pre>
<div class="entryblock">
<pre class="entrycode"><a name="universal" id="universal"></a>type universal</pre>
<div class="entrytext">
<p>The type of the universal union.</p>
</div>
</div>
<div class="entryblock">
<pre class="entrycode"><a name="tag_type" id="tag_type"></a>type 'a tag</pre>
<div class="entrytext">
<p>The type of a tag that can be used to mark a value of the argument type.</p>
</div>
</div>
<div class="entryblock">
<pre class="entrycode"><a name="tag" id="tag"></a>val tag: unit -> 'a tag</pre>
<div class="entrytext">
<p>Create a tag that can be used to identify a value of a particular type.</p>
</div>
</div>
<div class="entryblock">
<pre class="entrycode"><a name="tagInject" id="tagInject"></a>val tagInject: 'a tag -> 'a -> universal</pre>
<div class="entrytext">
<p>Inject a value into the union. This marks the value with the tag.</p>
</div>
</div>
<div class="entryblock">
<pre class="entrycode"><a name="tagIs" id="tagIs"></a>val tagIs: 'a tag -> universal -> bool</pre>
<div class="entrytext">
<p>Test whether the value was marked with the tag.</p>
</div>
</div>
<div class="entryblock">
<pre class="entrycode"><a name="tagProject" id="tagProject"></a>val tagProject: 'a tag -> universal -> 'a</pre>
<div class="entrytext">
<p>Project a value from the union. The tag must match the tag that was used
to create union value otherwise a <span class="identifier">Match</span>
exception will be raised.</p>
</div>
</div>
<ul class="nav">
<li><a href="Threads.html">Previous</a></li>
<li><a href="Basis.html">Up</a></li>
<li><a href="Weak.html">Next</a></li>
</ul>
</BODY>
</HTML>
|