Entries from 2015-10-25 to 1 day

プログラミングHaskell 7章問題9

import Data.Char type Bit = Int bin2int :: [Bit] -> Int bin2int = foldr (\x y -> x + 2*y) 0 int2bin :: Int -> [Bit] int2bin 0 = [] int2bin n = n `mod` 2 : int2bin (n `div` 2) make8 :: [Bit] -> [Bit] make8 bits = take 8 (bits ++ repeat 0) e…

プログラミングHaskell 7章問題7

type Bit = Int unfold :: (a -> Bool) -> (a -> b) -> (a -> a) -> a -> [b] unfold p h t x | p x = [] | otherwise = h x : unfold p h t (t x) chop8 :: [Bit] -> [[Bit]] chop8 = unfold (\x -> null x) (take 8) (drop 8) map' :: (a -> b) -> [a] -> …