more unsafePerformIO questions (is it safe to use with
ReadMode Handles)?
Andrew J Bromage
ajb@spamcop.net
Wed, 20 Aug 2003 11:20:34 +1000
G'day all.
On Tue, Aug 19, 2003 at 11:11:23AM +0100, Ganesh Sittampalam wrote:
> I was thinking of a situation like
>
> let x = unsafePerformIO readFooFromDB in x+x
>
> 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 the principle of
> referential transparency to write programs that _assume_ that.
I would have thought that this was the principle of full laziness
(which Haskell doesn't guarantee, but all compilers in practice
support) was more important here. If the code instead was this:
let x = expensiveComputation foo in x + x
I would certainly hope that expensiveComputation wasn't called twice,
and even though the language doesn't guarantee it, I have already
written code that assumed it.
Cheers,
Andrew Bromage