<!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"> <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%;"> 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> <a href = "TitleIndex">Index</a> </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><N><tt>.int</tt>, <tt>string</tt>, and <tt>Word</tt><N><tt>.word</tt> are equality types. </p> </li> <li class="gap"> <p> for any <tt>t</tt>, both <tt>t array</tt> and <tt>t ref</tt> are equality types. </p> </li> <li class="gap"> <p> if <tt>t</tt> is an equality type, then <tt>t list</tt>, and <tt>t vector</tt> are equality types. </p> </li> <li class="gap"> <p> if <tt>t1</tt>, ..., <tt>tn</tt> are equality types, then <tt>t1 * ... * tn</tt> and <tt>{l1: t1, ..., ln: tn} </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, ..., tn) 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><B><FONT COLOR="#228B22"> t </FONT></B><B><FONT COLOR="#0000FF">end</FONT></B> = <B><FONT COLOR="#0000FF">struct</FONT></B> <B><FONT COLOR="#A020F0">type</FONT></B><B><FONT COLOR="#228B22"> t </FONT></B>=<B><FONT COLOR="#228B22"> </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 -> 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 13 = ref 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 => i + 1) </pre></div> <p> <hr> Last edited on 2007-08-15 22:05:47 by <span title="fenrir.uchicago.edu"><a href="MatthewFluet">MatthewFluet</a></span>. </body></html>