unsafePerformIO

Simon Marlow simonmar@microsoft.com
Mon, 14 Oct 2002 11:10:33 +0100


> [...]
>=20
>=20
> > As for sharing, we currently don't provide any guarnatees,=20
> although we
> > should.  It is currently the case that if you write
> >
> > a =3D unsafePerformIO (putStr "hello")
> > b =3D unsafePerformIO (putStr "hello")
> >
> > and both a and b are evaluated, then you may get either one or two
> > "hello"s on stdout.  You can currently make things more=20
> deterministic by
> > (a) adding NOINLINE pragmas for a and b, and (b) using the=20
> flag -fno-cse
> > to disable common sub-expression elimination.  Then you'll=20
> get exactly
> > two instances of "hello" on stdout, although we won't guarantee that
> > behaviour for ever.  At some point we'll fix it so that=20
> unsafePerformIO
> > applications are never duplicated or coalesced.
>=20
>=20
> Are there any (short) examples available where using of=20
> unsafePerformIO
> leads to unexpected behaviour,
> especially an example with the terms a and b from above?

I don't have any examples to hand, but you ought to be able to make one
up without too much difficulty.  You just need two identical bindings
such as in the example above, and compile with -O.

Cheers,
	Simon