<!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>EqualityType - 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">

<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 20051202</a>
    <td style = "
		border: 0px;
		font-size: 150%;
		text-align: center;
		width: 50%;">
      EqualityType
    <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 = "Index">Index</a>
      &nbsp;
</table>
<div id="content" lang="en" dir="ltr">
An equality type is a type to which <a href="PolymorphicEquality">PolymorphicEquality</a> can be applied.  The <a href="DefinitionOfStandardML"> Definition</a> and the <a href="BasisLibrary">Basis Library</a> precisely spell out which types are equality types. 
    <ul>

    <li>
<p>
 <tt>bool</tt>, <tt>char</tt>, <tt>IntInf.int</tt>, <tt>Int</tt>&lt;N&gt;<tt>.int</tt>,  <tt>string</tt>, and <tt>Word</tt>&lt;N&gt;<tt>.word</tt> are equality types.  
</p>
</li>
    <li class="gap">
<p>
 for any <tt>t</tt>, both <tt>t&nbsp;array</tt> and <tt>t&nbsp;ref</tt> are equality  types.  
</p>
</li>
    <li class="gap">
<p>
 if <tt>t</tt> is an equality type, then <tt>t&nbsp;list</tt>, and   <tt>t&nbsp;vector</tt> are equality types. 
</p>
</li>
    <li class="gap">
<p>
 if <tt>t1</tt>, ..., <tt>tn</tt> are equality types, then  <tt>t1&nbsp;*&nbsp;...&nbsp;*&nbsp;tn</tt>  and <tt>{l1:&nbsp;t1,&nbsp;...,&nbsp;ln:&nbsp;tn}&nbsp;</tt>  are equality types. 
</p>
</li>
    <li class="gap">
<p>
 if <tt>t1</tt>, ..., <tt>tn</tt> are equality types and <tt>t</tt>   <a href="AdmitsEquality">AdmitsEquality</a>, then <tt>(t1,&nbsp;...,&nbsp;tn)&nbsp;t</tt> is an equality type. 
</p>
</li>

    </ul>


<p>
To check that a type t is an equality type, use the following idiom. 
<pre class=code>
<B><FONT COLOR="#0000FF">structure</FONT></B> S: <B><FONT COLOR="#0000FF">sig</FONT></B> <B><FONT COLOR="#A020F0">eqtype</FONT></B><FONT COLOR="#228B22"><B> t </FONT></B><B><FONT COLOR="#0000FF">end</FONT></B> =
   <B><FONT COLOR="#0000FF">struct</FONT></B>
      <B><FONT COLOR="#A020F0">type</FONT></B><FONT COLOR="#228B22"><B> t </FONT></B>=<FONT COLOR="#228B22"><B> </FONT></B>...
   <B><FONT COLOR="#0000FF">end</FONT></B>
</PRE>
 
</p>
<p>
Notably, <tt>exn</tt> and <tt>real</tt> are not equality types.  Neither is <tt>t1&nbsp;-&gt;&nbsp;t2</tt>, for any <tt>t1</tt> and <tt>t2</tt>. 
</p>
<p>
Equality on arrays and ref cells is by identity, not structure.  For example, <tt>ref&nbsp;13&nbsp;=&nbsp;ref&nbsp;13</tt> is <tt>false</tt>. On the other hand, equality for lists, strings, and vectors is by structure, not identity.  For example, the following equalities hold. 
</p>

<pre>[1, 2, 3] = 1 :: [2, 3]
"foo" = concat ["f", "o", "o"]
Vector.fromList [1, 2, 3] = Vector.tabulate (3, fn i =&gt; i + 1)
</pre></div>



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