Re: [Haskell-cafe] Mutable data within a (non-IO) monad

2009-10-05 Thread Bryan O'Sullivan
On Sat, Oct 3, 2009 at 1:57 AM, Duncan Coutts duncan.cou...@googlemail.comwrote: Internally, each time you demand the next random number, it is mutating the internal ST array. This is the same thing that the Statistics.RandomVariate code in the statistics package does, and it can be very

Re: [Haskell-cafe] Mutable data within a (non-IO) monad

2009-10-03 Thread Duncan Coutts
On Fri, 2009-10-02 at 20:00 -0700, Gregory Crosswhite wrote: Sorry to reply to my own posting, but... AHA! I see now what's going on. The purpose of the rank-2 qualifier is to prevent STRefs from leaking outside of the runST call, and what the code does at the lowest level is that it

Re: [Haskell-cafe] Mutable data within a (non-IO) monad

2009-10-03 Thread Henning Thielemann
On Fri, 2 Oct 2009, Gregory Crosswhite wrote: Do you all have any thoughts on ways to solve this problem, and/or a high-level explanation of what is going behind the scenes with STRefs and MArrays? http://www.haskell.org/haskellwiki/Monad/ST ___

[Haskell-cafe] Mutable data within a (non-IO) monad

2009-10-02 Thread Gregory Crosswhite
Hey everyone, I am thinking about creating a particular data structure with an immutable and mutable version. The key of my problem is that I would like the user to be able to work with a mutable version of the data within a non-IO monad and then get an immutable value at the end,

Re: [Haskell-cafe] Mutable data within a (non-IO) monad

2009-10-02 Thread Gregory Crosswhite
Sorry to reply to my own posting, but... AHA! I see now what's going on. The purpose of the rank-2 qualifier is to prevent STRefs from leaking outside of the runST call, and what the code does at the lowest level is that it passes around a token state object to force the compiler to