
2 Sep
2010
2 Sep
'10
3:07 a.m.
2010/9/2 David Virebayre
Simple way :
l = [False,False,False,True,False,False,True] foldl' (\a b -> a*2 + if b then 1 else 0) 0 l
Oh sorry I answered too quickly and didn't see the list can have more than 8 bits. chunk :: [Bool] -> [[ Bool ]] chunk [] = [] chunk l = a : chunk b where (a,b) = splitAt 8 l conv1 = foldl' (\a b -> a*2 + if b then 1 else 0) 0 convlist = map conv1 . chunk test = convlist (replicate 8 True ++ replicate 8 False :: [Bool] )