Recommended
PPTX
PDF
awk v.s. bashどっちが強い?@OSC2011Tokyo
PDF
PPTX
PDF
PDF
PythonでLispを実装した (evalつき)
PDF
PDF
PDF
[TL06] 日本の第一人者が C# の現状と今後を徹底解説! 「この素晴らしい C# に祝福を!」
PPTX
PDF
PDF
Everyday Life with clojure.spec
PDF
PDF
200319 eash python_shareslide_functions
KEY
PPT
CPANの依存モジュールをもう少し正しく検出したい
PPTX
XMonad-oid on Emacs & More functional Emacs Lisp | 関数型LT大会
PDF
KEY
PDF
Java SE 8 lambdaで変わる プログラミングスタイル
PDF
(Ruby使いのための)Scalaで学ぶ関数型プログラミング
PDF
プログラミング言語のパラダイムシフトーScalaから見る関数型と並列性時代の幕開けー
PDF
「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」
PDF
Composable Callbacks & Listeners
PDF
PDF
Data processing at spotify using scio
PPT
PDF
PDF
PDF
More Related Content
PPTX
PDF
awk v.s. bashどっちが強い?@OSC2011Tokyo
PDF
PPTX
PDF
PDF
PythonでLispを実装した (evalつき)
PDF
PDF
What's hot
PDF
[TL06] 日本の第一人者が C# の現状と今後を徹底解説! 「この素晴らしい C# に祝福を!」
PPTX
PDF
PDF
Everyday Life with clojure.spec
PDF
PDF
200319 eash python_shareslide_functions
KEY
PPT
CPANの依存モジュールをもう少し正しく検出したい
PPTX
XMonad-oid on Emacs & More functional Emacs Lisp | 関数型LT大会
PDF
KEY
PDF
Java SE 8 lambdaで変わる プログラミングスタイル
PDF
(Ruby使いのための)Scalaで学ぶ関数型プログラミング
PDF
プログラミング言語のパラダイムシフトーScalaから見る関数型と並列性時代の幕開けー
PDF
「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」
PDF
Composable Callbacks & Listeners
PDF
PDF
Data processing at spotify using scio
PPT
PDF
Similar to Haskell で CLI
PDF
PDF
ODP
PDF
PDF
PDF
KEY
PDF
PDF
PDF
PDF
PDF
GitHub での Haskell の色が変わったんで
PDF
関数型言語テイスティング: Haskell, Scala, Clojure, Elixirを比べて味わう関数型プログラミングの旨さ
PDF
PPT
PDF
PDF
One - Common Lispでもワンライナーしたい
More from Nobutada Matsubara
PDF
PDF
PDF
PDF
Build Dockferile with Haskell
PDF
Elixir Programming with Type checking
PDF
PDF
PDF
PDF
ADVENTAR の Bot を作る with Haskell
PDF
PDF
PDF
PDF
PDF
Haskell で LINE Bot を作ってみた
PDF
PDF
PDF
PDF
PDF
PDF
Recently uploaded
PDF
Reiwa 7 IT Strategist Afternoon I Question-1 3C Analysis
PDF
2025→2026宙畑ゆく年くる年レポート_100社を超える企業アンケート総まとめ!!_企業まとめ_1229_3版
PDF
第21回 Gen AI 勉強会「NotebookLMで60ページ超の スライドを作成してみた」
PDF
Starlink Direct-to-Cell (D2C) 技術の概要と将来の展望
PPTX
PDF
さくらインターネットの今 法林リージョン:さくらのAIとか GPUとかイベントとか 〜2026年もバク進します!〜
PDF
Reiwa 7 IT Strategist Afternoon I Question-1 Ansoff's Growth Vector
PDF
PDF
100年後の知財業界-生成AIスライドアドリブプレゼン イーパテントYouTube配信
Haskell で CLI 1. 2. 3. 4. 5. 6. 7. 8. System.Console.GetOpt
これも base にある
getArgs で得た文字列を特定の型に変換してくれる.
getOpt
:: ArgOrder a -- ^ non-opts な文字列の取り扱い方
-> [OptDescr a] -- ^ opts な文字列の扱い方
-> [String] -- ^ getArgs などで得た文字列
-> ([a], [String], [String])
返り値の型は (オプションの型, non-opts な文字列, エラー)
(細かい説明は割愛)
9. System.Console.GetOpt の使用例
import System.Console.GetOpt
main :: IO ()
main = do
args <- getArgs
let (opts, rest, err) = getOpt Permute options args
print opts
data Flag = Verbose | Version deriving (Show, Eq)
options :: [OptDescr Flag]
options =
[ Option ['v'] ["verbose"] (NoArg Verbose) "..."
, Option ['V'] ["version"] (NoArg Version) "..."
]
10. 11. optparse-applicative の使用例
import Options.Applicative
main :: IO ()
main = print =<< execParser options
where
opts = sample `withInfo` "Print a greeting for TARGET"
data Sample = Sample { hello :: String, verbose :: Bool }
sample :: Parser Sample
sample = Sample
<$> strOption ( long "hello" <> help ".." )
<*> switch ( long "verbose" <> short 'v' <> help ".." )
withInfo :: Parser a -> String -> ParserInfo a
withInfo opts = info (helper <*> opts) . progDesc
12. 13. optparse-applicative でサブコマンド
サブコマンドのパーサー
subcmdParser :: Parser SubCmd
subcmdParser = subparser
$ command "new" (pure NewCmd `withInfo` "...")
<> command "add" (AddCmd <$> ... `withInfo` "...")
<> command "done" (DoneCmd <$> ... `withInfo` "...")
<> command "list" (pure ListCmd `withInfo` "...")
hoge new とか hoge add ってサブコマンドになる
Semigroup の結合( <> )しかしてないんで網羅性チェッ
クは無理
14. 15. 16. 拡張可能バリアントの導入
variantFrom ::
Forall (KeyIs KnownSymbol) xs =>
RecordOf ParserInfo xs -> Parser (Variant xs)
variantFrom = subparser . subcmdVariant
where
subcmdVariant =
hfoldMapWithIndexFor (Proxy @ (KeyIs KnownSymbol))
$ m x ->
let k = symbolVal (proxyAssocKey m)
in command k
((EmbedAt m . Field . pure) <$> getField x)
instance Wrapper ParserInfo where
type Repr ParserInfo a = ParserInfo a
_Wrapper = id
17. 18. 19. 20. 21. RIO ライブラリの使用例
run :: RIO Env () -> Options -> IO ()
run cmd opts = do
token <- liftIO $ getEnv "MEDIUM_TOKEN"
logOpts <- logOptionsHandle stdout (opts ^. #verbose)
withLogFunc logOpts $ logger -> do
let env = #logger @= logger
<: #token @= fromString token
<: nil
runRIO env cmd
callMeAPI :: RIO Env ()
callMeAPI = do
logDebug "Run cmd: call me api"
token <- asks (view #token)
user <- API.getMe token
logDebug $ display ("get: " <> tshow user)
logInfo $ display ("Hi " <> user ^. #name <> "!!")
22. 実行してみる
$ mdium --version
Version 0.2.0.0, Git revision
efcf1856b6b065141a6d366663b97b0301053ffd (23 commits)
$ mdium --verbose --me
2018-11-10 10:28:53.049919: [debug] Run cmd: call me api
@(src/Mdium/Cmd/Run.hs:57:3)
2018-11-10 10:28:54.721968: [debug] get: id @= "..." <:
username @= "nobutada" <: name @= "matsubara" <: url @=
"https://medium.com/@nobutada" <: imageUrl @= ".." <: nil
@(src/Mdium/Cmd/Run.hs:60:3)
2018-11-10 10:28:54.722133: [info] Hi matsubara!!
@(src/Mdium/Cmd/Run.hs:61:3)
23. 24. 25. 26. 自作テンプレートの例 (hsfiles)
{-# START_FILE package.yaml #-}
name: {{name}}
version: 0.1.0.0
homepage: https://github.com/{{github-username}}/{{name}}
...
dependencies:
- base >= 4.7 && < 5
- rio >= 0.1.1.0
- extensible >= 0.4.9
- yaml
...
{-# START_FILE app/Main.hs #-}
module Main where
import RIO
import Data.Extensible
...
27. 28. 29. 30. 31.