Hi Jan,
> When can I safely cheat haskell compiler/interpreter
> by pretending that I perform pure computations,
> when in fact they are not?
If the computation is not pure, you cannot pretend it is.
> Here is a real example,
> from my Md5Digest module which works fine in Hugs:
>
> digest :: String -> String
> digest string
> = unsafePerformIO (
> marshall_string_ string >>= \x1 ->
> prim_Md5Digest_digest x1 >>= \x2 ->
> unmarshall_string_ x2 >>= \x3 ->
> return x3
> )
I gues that for digest it holds that
s1 == s2
==>
digest s1 == digest s2
The only reason that the underlying function is impure is that is allocates
memory to marshall its argument and then calls a C function. These
side-effects don't influence the result of computing digest (it would be
different if prim_Md5Digest_digest would take into account the actual
address of its argument, or the time of day, the current Microsoft
stockprice, ...
> currentSecond dummyInput
> = cheat expression involving dummyInput and unsafePerformIO
This function however *should* return a different answer each time it is
called, otherwise you will get distressed again that the clock stopped yet
again. Some people pay lots of money to stop the time (they get a face-lift,
take mega doses of vitamins, go jogging, or put their corpse in a freezer
after they die). Perhaps we can sell them FP!
Erik