Ga! Before to many people start flooding me responses of "This is really dumb idea don't do it!" I would like to clarify that for the most part IKnowWhatI'mDoing(TM)
I am well aware of the usual ST/IORefs as the usual solutions to data mutability in haskell. 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. I am very much away that even if I had such a function that it will probably break everything. I am not just trying to make things run faster. What I am trying to do is hyper unusual and I really do need an unsafeHorribleThings to do it. - Job On Tue, Aug 11, 2009 at 12:14 PM, Max Desyatov <explicitc...@googlemail.com>wrote: > Job Vranish <jvran...@gmail.com> writes: > > > Does anybody know if there is some unsafe IO function that would let me > do destructive assignment? > > Something like: > > > > a = 5 > > main = do > > veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign a 8 > > print a > >> 8 > > Aren't StateT or IORefs the exact thing you are looking for? > > > I'm also looking for a way to make actual copies of data. > > so I could do something like this: > > > > a = Node 5 [Node 2 [], Node 5 [a]] > > main = do > > b <- makeCopy a > > veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign b > (Node 0 []) > > -- 'a' is unchanged > > > > It would be even more fantastic, if the copy function was lazy. > > I think the traverse function might actually make a copy, but I would be > happier with something more general (doesn't > > require membership in traversable), and more explicit (was actually > designed for making real copies). > > Same thing, IORefs could help you. Anyway, I can't imagine any case > where veryUnsafeAndYouShouldNeverEveryCallThisFunction_DestructiveAssign > could be useful with its imperative semantics as you've described. The > point is that Haskell is pure language and I use it because of this > feature (not only because of this, to be exact). I don't want to use > any library code that brokes pure semantics and launches nuclear bombs > behind the IO monad. GHC is smart enough these days to do all optimised > destructive assignments, copies and all that imperative stuff and there > are plenty of other ways to get a performance boost without > unsafeHorribleThings. > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe