[Haskell-cafe] Re: Top level mutable data structures problem

MR K P SCHUPKE k.schupke at imperial.ac.uk
Wed Oct 20 17:05:07 EDT 2004

A slight tangent, (and not GHC specific) so I have put this reply in the cafe.

a way to get mutable data outside the IO monad occurs to me.

If a file is a mutable data type outside of Haskell, we have
hGetContents... which can be implemented with
unsafeInterleaveIO, rather than unsafePerformIO. hGetContents
lets you read a file from outside the IO Monad. The same
applies to hGetChannel. What if there was a way to write in
the same way? Say you write a function that reads lazily
from a list ... you could then have:

        main :: IO ()
                a <- hGetChannel channel
                hPutChannel (f a)
		-- this lazily puts the list to the channel.

At the other end of the channel we have a state storage
thread, which obeys commands sent over the output channel
(read x, write y etc...)

You can then write a function, which prepends the next
instruction to the output list, and reads data from
the input list hence manipulates the state. (the
sequence of IO operations is preserved by the lists)


More information about the Haskell-Cafe mailing list