Last active
September 29, 2016 14:10
-
-
Save hiratara/22384fab8cbf5ca7670b2dc348b916c7 to your computer and use it in GitHub Desktop.
An answer of http://qiita.com/hiratara/items/169b5cb83b0adbfda764
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --resolver lts-7.0 --install-ghc runghc --package turtle | |
{-# OPTIONS_GHC -fwarn-name-shadowing #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
main = do | |
name <- hostname | |
echo name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack runghc | |
{-# OPTIONS_GHC -fwarn-name-shadowing #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
main = do | |
args <- arguments | |
let fileTxt = head args | |
file = fromText fileTxt | |
dt <- datefile file | |
let dateTxt = repr dt | |
echo dateTxt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack runghc | |
{-# OPTIONS_GHC -fwarn-name-shadowing #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
echoModified fname = do | |
let file = fromText fname | |
dt <- datefile file | |
printf (s%"\t"%utc%"\n") fname dt | |
main = do | |
args <- arguments | |
mapM echoModified args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --resolver lts-7.0 --install-ghc runghc --package turtle | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
nestedIO = do | |
putStr "Hello, " | |
return (putStrLn "I/O!") | |
main = do | |
printIO <- nestedIO | |
printIO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --install-ghc runghc --package turtle | |
{-# OPTIONS_GHC -fwarn-name-shadowing #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
main = do | |
args <- arguments | |
let path = head args | |
empty & inproc "find" ([path] <> ["-name", "*.hs"]) | |
& inshell "xargs grep '^import '" | |
& shell "wc -l" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --install-ghc runghc --package turtle | |
{-# OPTIONS_GHC -fwarn-name-shadowing #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
import qualified Control.Foldl as Fold | |
main = do | |
args <- arguments | |
let path' = head args | |
path = fromText path' | |
find (suffix ".hs") path | |
& grepImport | |
& (`fold` Fold.length) | |
& view | |
grepImport upstream = do | |
path <- upstream | |
input path & grep (prefix "import") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --install-ghc runghc --package turtle | |
{-# OPTIONS_GHC -fwarn-name-shadowing #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
import qualified Control.Foldl as Fold | |
parser = optional $ optText "dir" 'd' "the root of search directories" | |
main = do | |
mPath' <- options "Count imported modules" parser | |
let path' = case mPath' of Nothing -> "." | |
Just p -> p | |
path = fromText path' | |
find (suffix ".hs") path | |
& grepImport | |
& (`fold` Fold.length) | |
& view | |
grepImport upstream = do | |
path <- upstream | |
input path & grep (prefix "import ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --install-ghc runghc --package turtle | |
{-# OPTIONS_GHC -fwarn-name-shadowing #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
import qualified Control.Foldl as Fold | |
parser = (,) <$> optional (optText "dir" 'd' "the root of search directories") | |
<*> switch "show" 's' "Show the name of all imported modules" | |
main = do | |
(mPath', isShow) <- options "Count imported modules" parser | |
let path' = case mPath' of Nothing -> "." | |
Just p -> p | |
path = fromText path' | |
sink = if isShow then dump else wc | |
find (suffix ".hs") path | |
& grepImport | |
& sink | |
grepImport upstream = do | |
path <- upstream | |
input path & grep (prefix "import ") | |
wc src = src & (`fold` Fold.length) & view | |
dump src = src | |
& sed (prefix (importDef *> moduleName)) | |
& stdout | |
where | |
importDef = "import" <> spaces1 <> ("qualified" <> spaces1 <|> "") | |
moduleName = plus (notChar ' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Haskell Day のチュートリアル](http://qiita.com/hiratara/items/169b5cb83b0adbfda764) で出題した問題の回答例をここで公開予定です。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment