FW: type of stToIO
Simon Peyton-Jones
simonpj at microsoft.com
Fri Oct 6 05:15:17 EDT 2000
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:ross at soi.city.ac.uk]
Sent: 05 October 2000 18:24
To: Simon Peyton-Jones
Cc: glasgow-haskell-bugs at haskell.org
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
Glasgow-haskell-bugs at haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
More information about the Glasgow-haskell-bugs
mailing list