more unsafePerformIO questions (is it safe to use with ReadMode Handles)?

Simon Marlow simonmar@microsoft.com
Tue, 19 Aug 2003 12:18:27 +0100


=20
> >> Isn't there the possibility of inlining causing a read to=20
> >> happen twice even if it only appears to happen once?
> >
> >In theory that would be a valid transformation, but in practice no
> >compiler would duplicate arbitrary computations.  GHC=20
> certainly doesn't.
>=20
> I was thinking of a situation like=20
>=20
> let x =3D unsafePerformIO readFooFromDB in x+x
>=20
> I see from your "Secrets of the GHC inliner" paper that x wouldn't be
> inlined by GHC, but it seems to me like a serious abuse of=20
> the principle of
> referential transparency to write programs that _assume_ that.

Yes, I agree that one shouldn't rely on the "no duplication of work"
property.  However, folloing this argument we arrive at the conclusion
that hGetContents is an invalid use of unsafePerformIO.  (which is
something I've been saying for a while now :-).

Cheers,
	Simon