Ga! Before to many people start flooding me responses of &quot;This is really dumb idea don&#39;t do it!&quot; I would like to clarify that for the most part IKnowWhatI&#39;mDoing(TM)<br><div id=":o9" dir="ltr" class="kl">
<br>I am well aware of the usual ST/IORefs as the usual solutions to data mutability in haskell. <br>I very very much understand purity, and why it is a good thing, and why we should try to stay away from IO and ST as much as possible.<br>
I am very much away that even if I had such a function that it will probably break everything.<br>I am not just trying to make things run faster.<br><br>What I am trying to do is hyper unusual and I really do need an unsafeHorribleThings to do it.<br>
<br>- Job<br></div><br><br><br><div class="gmail_quote">On Tue, Aug 11, 2009 at 12:14 PM, Max Desyatov <span dir="ltr">&lt;<a href="mailto:explicitcall@googlemail.com">explicitcall@googlemail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">Job Vranish &lt;<a href="mailto:jvranish@gmail.com">jvranish@gmail.com</a>&gt; writes:<br>

<br>
&gt; Does anybody know if there is some unsafe IO function that would let me do destructive assignment?<br>
&gt; Something like:<br>
&gt;<br>
&gt; a = 5<br>
&gt; main = do<br>
&gt;   veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8<br>
&gt;   print a<br>
&gt;&gt; 8<br>
<br>
</div>Aren&#39;t StateT or IORefs the exact thing you are looking for?<br>
<div class="im"><br>
&gt; I&#39;m also looking for a way to make actual copies of data.<br>
&gt; so I could do something like this:<br>
&gt;<br>
&gt; a = Node 5 [Node 2 [], Node 5 [a]]<br>
&gt; main = do<br>
&gt;   b &lt;- makeCopy a<br>
&gt;   veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign b (Node 0 [])<br>
&gt;   -- &#39;a&#39; is unchanged<br>
&gt;<br>
&gt; It would be even more fantastic, if the copy function was lazy.<br>
&gt; I think the traverse function might actually make a copy, but I would be happier with something more general (doesn&#39;t<br>
&gt; require membership in traversable), and more explicit (was actually designed for making real copies).<br>
<br>
</div>Same thing, IORefs could help you.  Anyway, I can&#39;t imagine any case<br>
where veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign<br>
could be useful with its imperative semantics as you&#39;ve described.  The<br>
point is that Haskell is pure language and I use it because of this<br>
feature (not only because of this, to be exact).  I don&#39;t want to use<br>
any library code that brokes pure semantics and launches nuclear bombs<br>
behind the IO monad.  GHC is smart enough these days to do all optimised<br>
destructive assignments, copies and all that imperative stuff and there<br>
are plenty of other ways to get a performance boost without<br>
unsafeHorribleThings.<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></blockquote></div><br>