Re: [Haskell-cafe] Writing binary files?

2004-09-12 Thread Sven Panne
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.

Re: [Haskell-cafe] Writing binary files?

2004-09-12 Thread Glynn Clements
Abraham Egnor wrote: Passing a Ptr isn't that onerous; it's easy enough to make functions that have the signature you'd like: import System.IO import Data.Word (Word8) import Foreign.Marshal.Array hPutBytes :: Handle - [Word8] - IO () hPutBytes h ws = withArray ws $ \p - hPutBuf h p $

Re: [Haskell-cafe] Writing binary files?

2004-09-12 Thread Sven Panne
Glynn Clements wrote: The problem with this approach is that the entire array has to be held in memory, which could be an issue if the amount of data involved is large. Simple reasoning: If the amount of data is large, you don't want the overhead of lists because it kills performance. If the

Re: [Haskell-cafe] Writing binary files?

2004-09-12 Thread Glynn Clements
Sven Panne wrote: Also, changing the existing functions to deal with encodings is likely to break a lot of things (i.e. anything which reads or writes data which is in neither UTF-8 nor the locale-specified encoding). Hmmm, the Unicode tables start with ISO-Latin-1, so what would

Re: [Haskell-cafe] Writing binary files?

2004-09-12 Thread Marcin 'Qrczak' Kowalczyk
Sven Panne [EMAIL PROTECTED] writes: Hmmm, the Unicode tables start with ISO-Latin-1, so what would exactly break when we stipulate that the standard encoding for string I/O in Haskell is ISO-Latin-1? Additional encodings could be specified e.g. via a new open variant. That the encoding of

Re: [Haskell-cafe] Writing binary files?

2004-09-12 Thread Glynn Clements
Marcin 'Qrczak' Kowalczyk wrote: But the default encoding should come from the locale instead of being ISO-8859-1. The problem with that is that, if the locale's encoding is UTF-8, a lot of stuff is going to break (i.e. anything in ISO-8859-* which isn't limited to the 7-bit ASCII subset).

Re: [Haskell-cafe] Writing binary files?

2004-09-12 Thread Marcin 'Qrczak' Kowalczyk
Glynn Clements [EMAIL PROTECTED] writes: But the default encoding should come from the locale instead of being ISO-8859-1. The problem with that is that, if the locale's encoding is UTF-8, a lot of stuff is going to break (i.e. anything in ISO-8859-* which isn't limited to the 7-bit ASCII

Re: [Haskell-cafe] Writing binary files?

2004-09-12 Thread Glynn Clements
Marcin 'Qrczak' Kowalczyk wrote: But the default encoding should come from the locale instead of being ISO-8859-1. The problem with that is that, if the locale's encoding is UTF-8, a lot of stuff is going to break (i.e. anything in ISO-8859-* which isn't limited to the 7-bit ASCII