Then &quot;don&#39;t do that.&quot; =) I should have mentioned, parametric keys are a no no and can do bad things. ;)<div><br></div><div><div>-Edward<br><br><div class="gmail_quote">On Thu, Sep 22, 2011 at 2:33 PM, James Cook <span dir="ltr">&lt;<a href="mailto:mokus@deepbondi.net">mokus@deepbondi.net</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word"><div>I may be wrong, but I think the original SNMap was a map from &#39;StableName&#39;s to the specific values they were derived from, which also (IIRC) had some weak referencing aspect as well.  Using them as keys for arbitrary elements of the phantom type is actually not type-safe, because equality of &#39;StableName&#39;s does not imply equality of types.  Here&#39;s a simple demonstration (also at [1] with slightly more commentary) which defines a working equivalent of &#39;return unsafeCoerce&#39;  without directly using any &quot;unsafe&quot; function: </div>
<div><br></div><div>&gt; import Prelude hiding (lookup)</div><div>&gt; </div><div>&gt; import Data.Functor.Identity</div><div>&gt; import System.Mem.StableName</div><div>&gt; import System.Mem.StableName.Map</div><div>&gt; </div>
<div>&gt; unsafeCoerceIO :: IO (a -&gt; b)</div><div>&gt; unsafeCoerceIO = do</div><div>&gt;     sn1 &lt;- makeStableName undefined</div><div>&gt;     sn2 &lt;- makeStableName undefined</div><div>&gt;     </div><div>&gt;     return $ \x -&gt;</div>
<div>&gt;         let m = singleton sn1 (Identity x)</div><div>&gt;             Just (Identity y) = lookup sn2 m</div><div>&gt;          in y</div><div>&gt; </div><div>&gt; main :: IO ()</div><div>&gt; main = do</div><div>
&gt;     unsafeCoerce &lt;- unsafeCoerceIO</div><div>&gt;     unsafeCoerce () &quot;what did you do to my argument stack?!&quot;</div><div><br></div><div>-- James</div><div><br></div><div>[1] <a href="https://github.com/mokus0/junkbox/blob/master/Haskell/TypeExperiments/UnsafeStableMap.hs" target="_blank">https://github.com/mokus0/junkbox/blob/master/Haskell/TypeExperiments/UnsafeStableMap.hs</a> </div>
<div><div></div><div class="h5"><div><blockquote type="cite"><div><br></div></blockquote></div></div></div></div></blockquote></div></div></div>