[READ-ONLY] Mirror of https://github.com/shuuji3/normal-haskell-programming-book. Codes for『ふつうのHaskellプログラミング』http://www.loveruby.net/ja/stdhaskell/
0

Configure Feed

Select the types of activity you want to include in your feed.

tail.hs をポイントフリースタイルに書き換える

+15 -2
+13
fgrep.hs
··· 1 + import System.Environment 2 + import Data.List 3 + 4 + main :: IO () 5 + main = do args <- getArgs 6 + cs <- getContents 7 + putStr $ fgrep (head args) cs 8 + 9 + fgrep :: String -> String -> String 10 + fgrep pattern = unlines . filter (match pattern) . lines 11 + 12 + match :: String -> String -> Bool 13 + match pattern = any (pattern `isPrefixOf`) . tails
+2 -2
tail.hs
··· 3 3 putStr $ lastNLines 10 cs 4 4 5 5 lastNLines :: Int -> String -> String 6 - lastNLines n cs = unlines $ takeLast n $ lines cs 6 + lastNLines n = unlines . takeLast n . lines 7 7 8 8 takeLast :: Int -> [a] -> [a] 9 - takeLast n xs = reverse $ take n $ reverse xs 9 + takeLast n = reverse . take n . reverse