Jan Skibinski wrote:
> digest :: String -> String
> digest string
> = unsafePerformIO (
> marshall_string_ string >>= \x1 ->
> prim_Md5Digest_digest x1 >>= \x2 ->
> unmarshall_string_ x2 >>= \x3 ->
> return x3
> )
>
> From my naive perspective it should look to Hugs
> as a pure function - due to input argument.
>
> If this is correct then
>
> currentSecond dummyInput
> = cheat expression involving dummyInput and unsafePerformIO
>
> from my previous example should be, by extension, also
> safe to use. Correct? Or are there some lurking
> surprises that I am not aware of?
There's a big difference between digest and currentSecond. The first is really
a mathematical function, the second is not. I.e., given the same argument to
digest you expect the same result. This is not the case with currentSecond.
So, currentSecond is not safe to the kind of compiler optimizations that a good
Haskell compiler can do.
You can't make a working currentSecond if you don't involve IO in the type,
that's just the way it is.
--
-- Lennart