Re: [Haskell-cafe] unsafeSTToIO and stToIO

2009-04-30 Thread Ross Paterson
On Thu, Apr 30, 2009 at 12:44:49PM -0700, Jason Dusek wrote: > I gather that "...making it possible to use ST code directly > on IORef's." is what we have today? No, we have stToIO :: ST RealWorld a -> IO a, but STRef and IORef are still incompatible types. (I now think that's a good thing, b

Re: [Haskell-cafe] unsafeSTToIO and stToIO

2009-04-30 Thread Jason Dusek
I gather that "...making it possible to use ST code directly on IORef's." is what we have today? -- Jason Dusek |...making it possible to use ST code directly on IORef's.| http://www.mail-archive.com/glasgow-haskell-b...@haskell.org/msg03568.html _

Re: [Haskell-cafe] unsafeSTToIO and stToIO

2009-04-29 Thread Ross Paterson
On Wed, Apr 29, 2009 at 05:26:46PM -0400, Xiao-Yong Jin wrote: > Between the following two functions > > stToIO:: ST RealWorld a -> IO a > stToIO (ST m) = IO m > > unsafeSTToIO :: ST s a -> IO a > unsafeSTToIO (ST m) = IO (unsafeCoerce# m) > > All I can see is that the safe one uses Real

Re: [Haskell-cafe] unsafeSTToIO and stToIO

2009-04-29 Thread Dan Doel
On Wednesday 29 April 2009 5:26:46 pm Xiao-Yong Jin wrote: > Hi, > > Between the following two functions > > stToIO:: ST RealWorld a -> IO a > stToIO (ST m) = IO m > > unsafeSTToIO :: ST s a -> IO a > unsafeSTToIO (ST m) = IO (unsafeCoerce# m) > > All I can see is that the safe one uses Rea

Re: [Haskell-cafe] unsafeSTToIO and stToIO

2009-04-29 Thread Ryan Ingram
The main difference is that the state thread reference can leak out of the unsafe version: question :: forall s. IO (STRef s Int) question = unsafeSTToIO (newSTRef 1) I was trying to use this to inject the reference into a later ST computation, but I couldn't figure out how to build an object of

[Haskell-cafe] unsafeSTToIO and stToIO

2009-04-29 Thread Xiao-Yong Jin
Hi, Between the following two functions stToIO:: ST RealWorld a -> IO a stToIO (ST m) = IO m unsafeSTToIO :: ST s a -> IO a unsafeSTToIO (ST m) = IO (unsafeCoerce# m) All I can see is that the safe one uses RealWorld instead of an arbitrary thread s used in the unsafe one. I really don