I Hate IO

Ashley Yakeley ashley@semantic.org
Thu, 9 Aug 2001 04:01:02 -0700


At 2001-08-09 03:53, Ashley Yakeley wrote:

>--
>data OpenFile = ...
>
>openFileReadOnly :: FilePath -> IO OpenFile
>openFileReadWrite :: FilePath -> IO OpenFile
>closeFile :: OpenFile -> IO ()
>
>fileWritable :: OpenFile -> IO Bool
>
>fileLength :: OpenFile -> IO Integer
>
>setFileLength :: OpenFile -> Integer -> IO ()
>-- fill with zeros if extending
>
>readFileBlock :: OpenFile -> Integer -> Integer -> IO [Word8]
>-- "readFileBlock file start length", return truncated array if past file 
>end
>
>writeFileBlock :: OpenFile -> Integer -> [Word8] -> IO ()
>-- would extend file if writing past end
>--

Note that any number of threads could be permitted to call 'read' 
operations (fileLength,readFileBlock) simultaneously, but if a thread is 
calling a 'write' operation (setFileLength,writeFileBlock), other threads 
must wait on both read and write operations. It's _so_ much simpler when 
you don't have that pesky "file pointer" to worry about.

-- 
Ashley Yakeley, Seattle WA