ajb:
> Quoting tom <[EMAIL PROTECTED]>:
> This looks cool:
> 
>     bytes2int = foldr ((. (256 *)) . (+)) 0 . (map toInteger)
> 
> but I'm not smart enough to parse it.  This is both more readable and
> shorter:
> 
>     bytes2int = foldr (\x r -> r*256 + fromInteger x) 0
> 
> Integer log2's are probably better done using integers only, or at least
> abstracted out into a separate function.

Reminds me of this code from Data.Binary:

    unroll :: Integer -> [Word8]
    unroll = unfoldr step
      where
        step 0 = Nothing
        step i = Just (fromIntegral i, i `shiftR` 8)

    roll :: [Word8] -> Integer
    roll   = foldr unstep 0
      where
        unstep b a = a `shiftL` 8 .|. fromIntegral b

Which is a bit stream-fusion inspired, I must admit.

-- Don
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to