Monad composition

Rijk-Jan van Haaften
Thu, 24 Jan 2002 23:23:28 +0100

Andre W B Furtado wrote:
>Well, it's also possible to interchange data between these two monads by:
>unsafeIOToST :: IO a -> ST s a
>stToIO :: ST s a -> IO a
>Can anyone tell the possible problems related to

Probably in the same manner as with unsafePerformIO:
it can break referential transparency.

changeFile fileName   = unsafePerformIO (writeFile fileName "Hello, world")
fileContents fileName = unsafePerformIO (readFile  fileName)

Now, if there is a call to changeFile between two calls to fileContents with
the same filename (assumed that the file didn't contain the text "Hello, 
the function returns different answers in exactly syntactic identical calls.
Thus, referential transparency is broken.

Rijk-Jan van Haaften