[Haskell-cafe] convert a list of booleans into Word*

Paul.Brauner at loria.fr Paul.Brauner at loria.fr
Wed Sep 30 09:29:26 EDT 2009

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 at 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list