[Haskell-cafe] convert a list of booleans into Word*
lemming at henning-thielemann.de
Wed Sep 30 20:07:12 EDT 2009
On Wed, 30 Sep 2009, Jochem Berndsen wrote:
> Bulat Ziganshin wrote:
>> Hello Paul,
>> Wednesday, September 30, 2009, 1:18:03 PM, you wrote:
>>> 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.
>> sum . zipWith (*) (map (2^) [0..])
> I'd turn this into
>> sum . zipWith (*) (iterate (2*) 1)
> , but it's probably not very important.
sum . zipWith (*) (iterate (flip shiftL 1) 1) . map fromEnum
in order to make the bitset nature more explicit.
More information about the Haskell-Cafe