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

Aai bradypus at xs4all.nl
Wed Sep 30 10:27:31 EDT 2009


Very fast for long boolean lists by using a strict foldl and reversing
the input:

bsToInt :: [Bool] -> Integer
bsToInt = foldl' ((.fromIntegral.fromEnum).(+).join(+)) 0. reverse


Try this:

(>1) $ bsToInt $ take 100000 $ cycle [True,True,False,True,True,False,True]


>> bitsToInt :: [Bool] -> Integer
>> bitsToInt = foldr((.(flip shiftL 1)).(+)) 0. map (fromIntegral.fromEnum)
>>
>>
>>     

-- 
Met vriendelijke groet,
=@@i



More information about the Haskell-Cafe mailing list