Jan Skibinski writes:
 >      When can I safely cheat haskell compiler/interpreter
 >      by pretending that I perform pure computations,
 >      when in fact they are not? Here is a real example,
 >      from my Md5Digest module which works fine in Hugs:

I don't understand what is impure about the MD5 example, but the time example
is clearly state-dependant. I think the bottom line is that unsafePerformIO
has no semantics beside the fact that it _forgets_ the effectful semantics of
the inner expression, and since we don't have an operational semantics for
Haskell, you can in principle expect any "bad" use of unsafePerformIO to fail.

For example, even if you try to suspend the evaluation by guarding the
expression with a (), as Nigel explained, a smart compiler could recognize
that a function of type () -> a is denotationally equivalent to a constant
of type a.

So what you are really doing in these cases is trying to outsmart the
compiler('s designers), which is IMO a pointless exercise. (Think: "the
compiler as a black box".)

-- 
Frank Atanassow, Dept. of Computer Science, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-1012, Fax +31 (030) 251-3791


Reply via email to