Hello!
On Tue, Sep 14, 1999 at 12:43:11AM -0700, Simon Peyton-Jones wrote:
{-# notInline test #-}
test :: IORef [a]
test = unsafePerformIO $ newIORef []
main = do
writeIORef test [42]
bang - readIORef test
print (bang :: [Char])
[...]
Hmmm. The type of test should
On Wed, Sep 22, 1999 at 00:36:27 +0200, Hannah Schroeter wrote:
On Tue, Sep 14, 1999 at 12:43:11AM -0700, Simon Peyton-Jones wrote:
{-# notInline test #-}
test :: IORef [a]
test = unsafePerformIO $ newIORef []
main = do
writeIORef test [42]
bang - readIORef test
{-# notInline test #-}
test :: IORef [a]
test = unsafePerformIO $ newIORef []
main = do
writeIORef test [42]
bang - readIORef test
print (bang :: [Char])
This is a very well-known problem in the ML community.
In the original monadic I/O paper (POPL'93), Phil and I mentioned
I don't know any way to make unsafePerformIO type-safe without imposing
some drastic or complicated restriction. Something in the back of
my mind tells me that John Launchbury has another example of
type unsafety induced by unsafePerformIO but I can't remember what;
so I'm cc'ing him.
\begin{code}
{-# OPTIONS -fglasgow-exts #-}
import IO
import IOExts
{-# notInline test #-}
test :: IORef [a]
test = unsafePerformIO $ newIORef []
main = do
writeIORef test [42]
bang - readIORef test
print (bang :: [Char])
\end{code}
The problem cause is clear, but