[Haskell-cafe] Writing binary files?
Sven.Panne at aedion.de
Sun Sep 12 05:29:47 EDT 2004
Glynn Clements wrote:
> main :: IO ()
> main = do
> h <- openBinaryFile "out.dat" WriteMode
> hPutStr h $ map (octetToChar . bitsToOctet) bits
> hClose h
Hmmm, using string I/O when one really wants to do binary I/O gives me a bad
feeling. Haskell characters are defined to be Unicode characters, so the
above only works because current Haskell implementations usually get this wrong
(either no Unicode support at all and/or ignoring any encodings and doing I/O
only with the lower 8 bits of the characters)... hGetBuf/hPutBuf plus their
non-blocking variants are the only way to *really* do binary I/O currently.
More information about the Haskell-Cafe