qforeign-0.65: Bzip2: problems with [Word8]
Michael Marte
marte@pms.informatik.uni-muenchen.de
Wed, 17 Oct 2001 11:27:38 +0200 (CEST)
On Tue, 16 Oct 2001, Ashley Yakeley wrote:
> At 2001-10-16 11:12, Michael Marte wrote:
>
> >But I need String -> String!
> >(Reading from a file, decompressing, and feeding it to the XML parser.)
> >How can I do this?
>
> The "reading from a file" part is arguably a misdesign in the standard
> libraries. There ought to be Word8-based file IO functions for
> reading/writing the bytes of a file. I'm not sure, but I think the
> Char-based functions may even do newline conversion.
readFile :: FilePath -> IO String works fine for me, also when reading
binary files.
But yes, maybe there should be a function returning IO Word8.
Obviously, the implementation of readFile automatically converts
from Word8 to Char and it is not only a type cast because Char has 16
bits.
> >I found out that fromIntegral does the conversion from Word8 to Char
> >but I do not know how to convert from Char to Word8.
>
> I think fromIntegral will work for that too.
No, there is no suitable instance.
However, it works like this:
map (toEnum . fromEnum) . Bzip2.decompress . map (toEnum . fromEnum)
Michael