<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>System.Mem.StableName</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_System-Mem-StableName.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">base-4.5.1.0: Basic libraries</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>non-portable</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Maintainer</th><td>libraries@haskell.org</td></tr><tr><th>Safe Haskell</th><td>Trustworthy</td></tr></table><p class="caption">System.Mem.StableName</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Stable Names </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Stable names are a way of performing fast (O(1)), not-quite-exact comparison between objects. </p><p>Stable names solve the following problem: suppose you want to build a hash table with Haskell objects as keys, but you want to use pointer equality for comparison; maybe because the keys are large and hashing would be slow, or perhaps because the keys are infinite in size. We can't build a hash table using the address of the object as the key, because objects get moved around by the garbage collector, meaning a re-hash would be necessary after every garbage collection. </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">data</span> <a href="#t:StableName">StableName</a> a</li><li class="src short"><a href="#v:makeStableName">makeStableName</a> :: a -> <a href="System-IO.html#t:IO">IO</a> (<a href="System-Mem-StableName.html#t:StableName">StableName</a> a)</li><li class="src short"><a href="#v:hashStableName">hashStableName</a> :: <a href="System-Mem-StableName.html#t:StableName">StableName</a> a -> <a href="Data-Int.html#t:Int">Int</a></li></ul></div><div id="interface"><h1 id="g:1">Stable Names </h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:StableName" class="def">StableName</a> a </p><div class="doc"><p>An abstract name for an object, that supports equality and hashing. </p><p>Stable names have the following property: </p><ul><li> If <code>sn1 :: StableName</code> and <code>sn2 :: StableName</code> and <code>sn1 == sn2</code> then <code>sn1</code> and <code>sn2</code> were created by calls to <code>makeStableName</code> on the same object. </li></ul><p>The reverse is not necessarily true: if two stable names are not equal, then the objects they name may still be equal. Note in particular that <code>mkStableName</code> may return a different <code><a href="System-Mem-StableName.html#t:StableName">StableName</a></code> after an object is evaluated. </p><p>Stable Names are similar to Stable Pointers (<a href="Foreign-StablePtr.html">Foreign.StablePtr</a>), but differ in the following ways: </p><ul><li> There is no <code>freeStableName</code> operation, unlike <a href="Foreign-StablePtr.html">Foreign.StablePtr</a>s. Stable names are reclaimed by the runtime system when they are no longer needed. </li><li> There is no <code>deRefStableName</code> operation. You can't get back from a stable name to the original Haskell object. The reason for this is that the existence of a stable name for an object does not guarantee the existence of the object itself; it can still be garbage collected. </li></ul></div><div class="subs instances"><p id="control.i:StableName" class="caption collapser" onclick="toggleSection('i:StableName')">Instances</p><div id="section.i:StableName" class="show"><table><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable1">Typeable1</a> <a href="System-Mem-StableName.html#t:StableName">StableName</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> (<a href="System-Mem-StableName.html#t:StableName">StableName</a> a)</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:makeStableName" class="def">makeStableName</a> :: a -> <a href="System-IO.html#t:IO">IO</a> (<a href="System-Mem-StableName.html#t:StableName">StableName</a> a)</p><div class="doc"><p>Makes a <code><a href="System-Mem-StableName.html#t:StableName">StableName</a></code> for an arbitrary object. The object passed as the first argument is not evaluated by <code><a href="System-Mem-StableName.html#v:makeStableName">makeStableName</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:hashStableName" class="def">hashStableName</a> :: <a href="System-Mem-StableName.html#t:StableName">StableName</a> a -> <a href="Data-Int.html#t:Int">Int</a></p><div class="doc"><p>Convert a <code><a href="System-Mem-StableName.html#t:StableName">StableName</a></code> to an <code><a href="Data-Int.html#t:Int">Int</a></code>. The <code><a href="Data-Int.html#t:Int">Int</a></code> returned is not necessarily unique; several <code><a href="System-Mem-StableName.html#t:StableName">StableName</a></code>s may map to the same <code><a href="Data-Int.html#t:Int">Int</a></code> (in practice however, the chances of this are small, so the result of <code><a href="System-Mem-StableName.html#v:hashStableName">hashStableName</a></code> makes a good hash key). </p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>