Haskell

Haskell 覚え書き

等しくない 3 /= 5 内包表記 ghci> [x * y | x <- [2,5,10], y <- [8, 10, 11], x * y > 50] [55,80,100,110] asパターン firstLetter :: String -> String firstLetter "" = "Empty String." firstLetter all@(x:xs) = "The first letter of " ++ all ++ " …

パスカルの三角形(Haskell)

その1。 main :: IO () main = print $ map pascal [0..8] pascal :: Int -> [Int] pascal 0 = [1] pascal n = [1] ++ eachCons (pascal (n - 1)) ++ [1] eachCons :: [Int] -> [Int] eachCons xs = if length xs < 2 then [] else (head xs + (head . tail…

Haskell 遊び

リストのインデックス n 番目を置き換える replace 関数。文字列(というかリストなら何でもいい)の n 番目(0 番が最初)を chr で置き換える。 main = print $ replace "Hallo!!" 1 'e' replace :: [a] -> Int -> a -> [a] replace st n chr = take n st …

Haskell 写経

cat.hs(p.28) ファイルの内容を出力する。 main = do cs <- getContents putStr cs 実行。 $ ghc cat.hs -o cat $ ./cat < cat.hs main = do cs <- getContents putStr cs countline.hs(p.36) ファイルの行数を出力する。 main = do cs <- getContents p…

Haskell 事始めノート

すごいHaskellたのしく学ぼう!作者: Miran Lipovača,田中英行,村主崇行出版社/メーカー: オーム社発売日: 2012/05/23メディア: 単行本(ソフトカバー)購入: 25人 クリック: 580回この商品を含むブログ (73件) を見るこれを見ている。 第一章 真理値は True …