在Haskell开展工作,我正试图将一大批女bo写到双亲档案中。
我可以书写文字(字数为8字),但可以说明如何从8个Bool的名单中转换为8个语言。
这里我迄今为止所做的事情:
toByte :: [Bool] -> Word8
toByte list = toByteh list 0 0
toByteh :: [Bool] -> Int -> Word8 -> Word8
toByteh list 8 _ = 0
toByteh list i result
| head list == True = toByteh (tail list) (i + 1) (result .|. (2^i :: Word8))
| otherwise = toByte_h (tail list) (i + 1) result
When I use this I just get a 0 byte. Can anyone see where this isn t working? Or are there better ways of doing this?