
Thanks for the answers. I already had a look at Binary but, as said above, it doesn't support bit manipulation, only bytes. On Wed, Sep 30, 2009 at 11:18:03AM +0200, Paul.Brauner@loria.fr wrote:
Hello,
I haven't found a function in hackage or in the standard library that takes a list of booleans (or a list of 0s and 1s, or a tuple of booleans or 0s and 1s) and outputs a Word8 or Word32.
I have written one which seems very inefficient :
toWord8 :: [Bool] -> Word8 toWord8 bs = go 0 0 bs where go n r [] = r go n r (b:bs) = go (n+1) (if b then setBit r n else clearBit r n) bs
Is there a better way to do this out there ?
(If it helps, i'm writting a toy compression algorithm, which outputs binary as lists of booleans, and I'd like to output that in a file).
Cheers Paul _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe