[Haskell] line-based interactive program

Bulat Ziganshin bulatz at HotPOP.com
Sat Jul 9 12:17:30 EDT 2005


Hello Wolfgang,

Saturday, July 09, 2005, 7:01:06 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 

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

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

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

sorry, it is probably not what i'm think about. as i can see, you are
provide safe equivalent of interleaveIO, while i'm think about
approach that simplifies creating of I/O and mutable-state programs,
something like:

string <- [readChar h, readChar h]

which automatically perform I/O actions `readChar h` in I/O monad and
then uses their results as in ordinal computation. this will allow
"do" syntax to more close imitate imperative languages


-- 
Best regards,
 Bulat                            mailto:bulatz at HotPOP.com





More information about the Haskell mailing list