Word8-Based IO

Wolfgang Jeltsch wolfgang@jeltsch.net
21 Aug 2002 20:52:51 +0200


On Wednesday, 2002-08-21, 06:55, CEST, Ashley Yakeley wrote:
> [...]

> * System.IO: addition of new Word8-based functions
> 
>   hGetOctet :: Handle -> IO Word8
>   hLookAheadOctet :: Handle -> IO Word8
>   hPutOctet :: Handle -> Word8 -> IO ()
>   hPutArray :: Handle -> [Word8] -> IO ()
>   hLazyGetArray :: Handle -> IO [Word8]

I wouldn't speak of arrays here because the functions don't operate with
arrays but with Word8 lists.

> ...as per hGetChar, hLookAhead, hPutChar, hPutStr and hGetContents.

To achieve consistency, it would be nice to rename some of the
Char-based functions according to their Word8 counterparts and provide
the same functions under their old names for compatibility.

>   hGetArrayBlock :: Handle -> Int -> IO [Word8]
>   hGetArrayReady :: Handle -> Int -> IO [Word8]

See above for the problem with "array".

> [...]

>   hSetFileSize :: Handle -> Integer -> IO ()
> 
> There's currently no way to set the size of a file. hSetFileSize would 
> truncate the file or pad with zero octets.

Maybe it would be good to split this into two functions according to the
two functionalities:
    hEnlargeFile :: Handle -> Integer -> IO ()
    hCutFile     :: Handle -> Integer -> IO ()
These functions would have to check if the Integer argument is less than
the current file size (hEnlargeFile) or greater than the current file
size (hCutFile) and throw an exception in this case.

> [...]

>   sendTo :: Socket -> [Word8] -> SockAddr -> IO Int
>   recvFrom :: Socket -> Int -> IO ([Word8], Int, SockAddr)
>   send :: Socket -> [Word8] -> IO Int
>   recv :: Socket -> Int -> IO [Word8]

Isn't "recv" an ugly abbreviation?

> -- 
> Ashley Yakeley, Seattle WA

Wolfgang