<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="polydoc.xsl"?>
<polydoc>
<title>Structure Universal</title>
<navigation>
<parent href="Basis.html">Basis</parent>
<previous href="Thread.xml">Thread</previous>
<next href="Weak.xml">Weak</next>
</navigation>
<headtext>
<p>
  The <identifier>Universal</identifier> 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. <identifier>Universal</identifier> 
  is built in for efficiency reasons but it is perfectly feasible to implement 
  it in Standard ML using <identifier>exception</identifier> bindings.
</p></headtext>
<topdecs>
<summary>structure Universal:
sig
    type universal 
    type 'a tag 
    val tag: unit -&gt; 'a tag
    val tagInject: 'a tag -&gt; 'a -&gt; universal
    val tagIs: 'a tag -&gt; universal -&gt; bool
    val tagProject: 'a tag -&gt; universal -&gt; 'a
end
</summary>
<bindings><binding>
<code>type <definition>universal</definition> 
</code>
<text><p>The type of the universal union.</p></text>
</binding>
<binding>
<code>type 'a <definition>tag</definition> 
</code>
<text><p>The type of a tag that can be used to mark a value of the argument type.</p></text>
</binding>
<binding>
<code>val <definition>tag</definition> : unit -&gt; 'a tag
</code>
<text><p>Create a tag that can be used to identify a value of a particular type.</p></text>
</binding>
<binding>
<code>val <definition>tagInject</definition> : 'a tag -&gt; 'a -&gt; universal
</code>
<text><p>Inject a value into the union. This marks the value with the tag.</p></text>
</binding>
<binding>
<code>val <definition>tagIs</definition> : 'a tag -&gt; universal -&gt; bool
</code>
<text><p>Test whether the value was marked with the tag.</p></text>
</binding>
<binding>
<code>val <definition>tagProject</definition> : 'a tag -&gt; universal -&gt; 'a
</code>
<text><p>Project a value from the union. The tag must match the tag that was used 
      to create union value otherwise a <identifier>Match</identifier> 
      exception will be raised.</p></text>
</binding>
</bindings>
</topdecs>
<tailtext>
<p></p></tailtext>
</polydoc>
