Haskell

プログラミング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] -> …

プログラミングHakell 5章問題8

import Data.Char -- caeser encription (upper case version) let2int :: Char -> Int let2int c = ord c - ord 'a' int2let :: Int -> Char int2let n = chr (ord 'a' + n) shift :: Int -> Char -> Char shift n c | isLower c = int2let ((let2int c + n…