<div><span class="Apple-style-span" style="font-family: sans-serif; font-size: medium; ">Hi haskell cafe:</span></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium;"><br>
</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; ">concerning Stable Names </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br>
</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><span class="Apple-style-span" style="font-family: arial, sans-serif; border-collapse: collapse; font-size: 13px; "><a href="http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/System-Mem-StableName.html" target="_blank" style="color: rgb(42, 93, 176); ">http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/System-Mem-StableName.html</a></span></span></font></div>
<div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br>
</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; ">makeStableName :: a -&gt; IO (StableName a)<table class="vanilla" cellspacing="0" cellpadding="0" style="width: 981px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; ">
</table></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br></span></font></div><div><span class="Apple-style-span" style="font-family: sans-serif; font-size: medium; ">I Did not test fully my proposal, and I´m thinking aloud, Just to inpire others and fish some ideas;</span></div>
<div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br></span></font></div><div><span class="Apple-style-span" style="font-family: sans-serif; font-size: medium; ">The IO in makeStableName  suggest more side effects than makeStableName really do. But still the call isn&#39;t pure.</span></div>
<div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; ">For calls such are makeStableName that gives a different result the FIRST time they are called but return the same result every time in the same session,  I suggest to use a Transient monad:</span></font></div>
<div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br>
</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; ">makeStableName :: a -&gt; Transient (StableName a)</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br>
</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><div>The key here is to maintain the programmer aware that it is not pure, but there are no IO and that  the results have no meaning from session to session.</div>
<div><br></div><div>Instance Monad Transient where</div><div>     Transient x ↠ f =  f  x</div><div>     return x = Transient x</div><div><br></div><div>We can Transient`ize IO calls by means of an implicit memoization:</div>
<div><br></div><div>liftT:: IO a -&gt; Transient a</div><div>liftT= &lt; whatever memoization code&gt;</div><div>liftT2=....</div><div>liftT3=....</div><div><br></div><div>Memorization then is embedded in the monad transformation</div>
<div>This may be more elegant than  IO plus unsafePerformIO and is more informative for the programmer. The transition form IO to pure can be done in two steps, see below</div><div><br></div><div>  Instead of unsafePerformIO,  we can use:</div>
</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br></span></font></div><div><span class="Apple-style-span" style="font-family: sans-serif; font-size: medium; ">unsafePurifyTransient :: Transient a -&gt; a</span></div>
<div><span class="Apple-style-span" style="font-family: sans-serif; font-size: medium; ">unsafePurifyTransient  (Transient x) = x<br><table class="vanilla" cellspacing="0" cellpadding="0" style="width: 991px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; ">
<tbody><tr><td class="body" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-left: 10px; "></td></tr></tbody></table><br></span></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; ">for the inherently transient calls</span></font></div>
<div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="font-size: medium; "><br></span></font></div><div><span class="Apple-style-span" style="font-family: sans-serif; font-size: medium; ">A safer version of unsafePerformIO using implicit memoization could be:<br>
<div>unsafePerformIOT :: IO a -&gt; a</div><div>unsafePerformIOT = unsafePurifyTransient  .  liftT</div><div><br></div><div>unsafePerformIOT guatantee that it returns the same value in the same session.</div><br></span></div>
<div><br></div><div><br></div><br><div class="gmail_quote">2009/12/8 Vladimir Zlatanov <span dir="ltr">&lt;<a href="mailto:vlado@dikini.net">vlado@dikini.net</a>&gt;</span><br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<div class="im">&lt;<a href="mailto:jeanchristophe.mincke@gmail.com">jeanchristophe.mincke@gmail.com</a>&gt; wrote:<br>&gt; I think lisp like symbols could be quite useful in the context of embedded<br>&gt; DSL to create ... well... symbols that can be interpreted as variables in<br>
&gt; that DSL.<br><br></div>Well for such use-case you could use either stable names, or recode<br>them into a state monad- you will get either a global i.e. lisp like<br>unique symbols, or their equivalent within a state context. Or some<br>
variation of the code posted previously in this thread.<br><br><a href="http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/System-Mem-StableName.html" target="_blank">http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/System-Mem-StableName.html</a><br>
<div><div></div><div class="h5">_______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div><div><br></div></div></blockquote></div>