unsafePtrCompare, anybody?

Simon Marlow simonmar@microsoft.com
Tue, 18 Sep 2001 12:57:31 +0100


> One's intuition would suggest that you could be safely=20
> implement mkAtom=20
> without wrapping it in a IO monad.   After all, at least at a=20
> abstract level,=20
> an atom table is referentially transparent.  The library=20
> documentation says=20
> that lack of side effects and environmental independance is=20
> sufficent to=20
> order for uses of unsafePerformIO to be safe.  Is there a=20
> exact (or at least=20
> better) criterion for safety?  =20

An exact criterion would require a formal semantics for Haskell, which
we don't have.  But informally, if a function which is implemented using
unsafePerformIO is pure - that is, its result depends only on the values
of its arguments and possibly its free variables - then that is a "safe"
use of unsafePerformIO.

> "unsafePerformIO" is used in the implementation of=20
> mkFastString, so how is it's side effects "safe".

It is safe because the side effects aren't visible outside the
implementation of mkFastString.

HTH,
	Simon