[Haskell] line-based interactive program

Wolfgang Jeltsch wolfgang at jeltsch.net
Sat Jul 9 11:01:06 EDT 2005

Am Samstag, 9. Juli 2005 08:31 schrieb Bulat Ziganshin:
> Hello Wolfgang,
> Friday, July 08, 2005, 11:55:48 PM, you wrote:
> > As part of my diploma thesis, I'm working on a small collection of modules
> > which provides safe I/O interleaving.  The key point is to split the state
> > of the world since I/O on different parts of the world can be interleaved
> > arbitrarily.  If someone is interested, I can post more details.   
> yes, i am interested. i feel that this would be very interesting and useful
> for real programs 


the idea is to have different monads for I/O on different resources.  A simple 
example is to have the two monads WorldIO and FileIO and a type FileIOHandle.  
A file is a part of the world.  You have the following functions:

    readChar :: FileIO Char
    writeChar :: Char -> FileIO ()
    runFileIO :: FilePath -> FileIO a -> WorldIO (a, FileIOHandle)
    finishFileIO :: FileIOHandle -> WorldIO ()

readChar and writeChar should be self-explanatory.  At first, runFileIO does 
nothing instead of opening the file and returning the result.  Whenever parts 
of the first component of the result pair are evaluated, as much readChar and 
writeChar actions of the file I/O action are executed as are needed to 
produce the desired parts of the result.  finishFileIO executes the remainder 
of the file I/O and closes the file afterwards.

An extended version of this approach shall also handle situations like pure 
reading of files where not all read operations have to be carried out if they 
are not needed to produce the desired result.  In this case, finishFileIO 
would just close the file without previously executing the remainder of the 
file I/O action.  The problem is that it cannot be assured that as yet 
unevaluated parts of the result aren't evaluated after exeuction of 
finishFileIO.  Therefore, if evaluation after finishing demands the execution 
of read operations these operations shall not actually be executed but 
instead _|_ shall be returned.

I also plan to provide a general framework for working on parts of the state 
interleaved with working on the remainder of the state.  The framework shall 
be hierarchical in the sense that you cannot just work on parts of the world 
but also on parts of parts of the world and so on.  It will probably use 
multi-parameter classes to describe which thing is part of which other thing.

When my diploma thesis and the corresponding talk are finished (which will 
probably at the end of September), I may post a more detailed description on 
this list and also provide some code.

Best wishes,

More information about the Haskell mailing list