John's stToIO could be implemented in terms of runST, like so:
stToIO :: (forall s . ST s a) -> IO a
stToIO st = return (runST st)
maybe you want strictness here (i.e. applying seq to the result of runST
before returning), maybe not. I'm sure there are arguments both ways.
GHC's stToIO currently has a different meaning: it embeds the ST computation
into the I/O monad, using the fact that IO is an instance of ST. Or in
other words, IO is just one distinguished state thread, which we're calling
RealWorld. It seems to me that embedding ST computations in the IO monad is
entirely reasonable, potentially useful, and we shouldn't disallow it on the
grounds that it exposes RealWorld to the programmer. RealWorld is just an
abstract placeholder after all.
Cheers,
Simon
> Ross
>
> Your example below isn't very compelling (i.e. I wouldn't mind
> losing the expressive power you exploit). And something in me
> dislikes the idea of exposing RealWorld as a type to the programmer.
>
> I don't know a technical basis for making this choice. I wonder what
> John thinks.
>
> Simon
>
>
> -----Original Message-----
> From: Ross Paterson [mailto:[EMAIL PROTECTED]]
> Sent: 05 October 2000 18:24
> To: Simon Peyton-Jones
> Cc: [EMAIL PROTECTED]
> Subject: Re: type of stToIO
>
>
> On Thu, Oct 05, 2000 at 09:25:18AM -0700, Simon Peyton-Jones wrote:
> | | The library documentation says
> | |
> | | stToIO :: ST s a -> IO a
> | |
> | | but PrelIOBase says
> | |
> | | stToIO :: ST RealWorld a -> IO a
> | |
> | | The documented type would be unsafe (as it is in Classic
> Hugs), so it
> | | seems necessary to mention the real world in the documentation.
> |
> | I discussed this with John Launchbury who pointed out a much
> | better type for stToIO
> |
> | stToIO :: (forall s. ST s a) -> IO a
> |
> | That avoids exposing RealWorld while preserving soundness.
> Better, eh?
>
> I'm not so sure. The current type (in GHC) means something: the IO
> monad ensures sequential access to its own region of the heap (though
> maybe RealWorld isn't the best name for this). And it's more general,
> e.g. I can write
>
> > data Var v = Var { readVar :: IO v, writeVar :: v -> IO () }
>
> > newVar :: v -> IO (Var v)
> > newVar v = stToIO $ do
> > r <- newSTRef v
> > return (Var {
> > readVar = stToIO (readSTRef r),
> > writeVar = stToIO . writeSTRef r
> > })
>
> which would be forbidden by the John's runST-style type.
>
> _______________________________________________
> Glasgow-haskell-bugs mailing list
> [EMAIL PROTECTED]
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
>
> _______________________________________________
> Glasgow-haskell-bugs mailing list
> [EMAIL PROTECTED]
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
>
_______________________________________________
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs