Haskell 的cmdArgs包提供了命令选项解析.
基于此页面的文档http://hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/System-Console-CmdArgs-Explicit.html#g:4及其来源http:/ /hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/src/System-Console-CmdArgs-Explicit-Complete.html#Complete
它似乎能够支持bash完成,但我无法使用解析器的隐式版本.http://hackage.haskell.org/packages/archive/cmdargs/0.10.3/doc/html/System-Console-CmdArgs-Implicit.html
有没有人有这样做的例子?
编辑添加了更好的示例
如果我有这个程序
{-# LANGUAGE DeriveDataTypeable #-}
import System.Console.CmdArgs
data Sample = Sample {hello :: String}
deriving (Show, Data, Typeable)
sample = Sample{hello = def}
main = print =<< cmdArgs sample
Run Code Online (Sandbox Code Playgroud)
与解析以下选项
The sample program
sample [OPTIONS]
Common flags:
-h --hello=ITEM
-? --help Display help message
-V --version Print version information
Run Code Online (Sandbox Code Playgroud)
如何使用cmdArgs的bash完成功能?
如果我fork和子进程然后exec创建更多子进程(它们本身可以创建更多进程),我如何pid从第一个进程中获取所有后代进程的列表?
有没有更好的方法然后循环/proc/并检查PPid每个进程的(进程id的父进程)?
如果一个程序的进程 ID 为 P,那么子进程(及其子进程)的进程 ID 是否严格大于 P?
当进程 ID 被重用时,会选择哪些进程 ID,例如,最低的进程 ID 是否可用?
我想将目录从 mac 计算机同步到服务器到 linux 计算机,同时排除 .o 文件和二进制可执行文件等已编译文件。如何排除二进制文件?
我现在正在使用的:
rsync -av --compress --exclude="*.o" dir server:dir
Run Code Online (Sandbox Code Playgroud) 加入https://doc.rust-lang.org/std/str/struct.Split.html有一个关于字符串rev结果的方法split
我收到以下错误
error: the trait `core::str::pattern::DoubleEndedSearcher<'_>` is not
implemented for the type `core::str::pattern::StrSearcher<'_, '_>` [E0277]
for part in "1:30".split(":").rev() {
Run Code Online (Sandbox Code Playgroud)
我用过的代码
let mut length = 0;
let mut mult = 1;
for part in "1:30".split(":").rev() {
length += mult * part.parse::<i32>().unwrap();
mult *= 60;
}
Run Code Online (Sandbox Code Playgroud) 移动目录及其所有内容的最有效方法是什么?
有没有更有效的方法然后只是循环目录中的每个文件并调用System.Directory.renameFile 它?
如何使用createProcessin 将std_in和std_err重定向到文件System.Process?
是否可以a使用pattens匹配/保护写入函数?
{-# LANGUAGE PatternGuards #-}
import Control.Monad.State.Strict(State, gets, runStateT)
data MyState = MyState
{ counter :: Int
} deriving (Show)
a :: State MyState String
a = do
i <- gets counter
case i of
0 -> return "hello"
1 -> return "bye"
run = runStateT a ( MyState{counter=0} )
Run Code Online (Sandbox Code Playgroud)
我试着写a为
a' :: State MyState String
a' | i <- gets counter, i == 0 = return "hello"
Run Code Online (Sandbox Code Playgroud)
但得到了错误:
No instance for (Control.Monad.State.Class.MonadState MyState m0)
arising …Run Code Online (Sandbox Code Playgroud) 我有一堆条件返回列表,有没有一种方法来评估它们而不给每个条件一个名字?
简化示例:
conditions i j = c1 i j ++ c2 i j ++ c3 i j
where
c1 i j | i > 2 = ["x"]
| otherwise = []
c2 i j | j > 5 = ["y", "a"]
| otherwise = []
c3 i j | j > 10 = ["z"]
| otherwise = []
c4 i j | j > 10 && i > 1 = ["z", "c", "hello"]
| otherwise = []
Run Code Online (Sandbox Code Playgroud) haskell functional-programming if-statement pattern-matching
我有一个函数arbExample来生成一个随机Example数据类型,它取决于许多函数.
我试图通过做一些属性测试quickCheck prop_example,问题是我不知道如何定义一个Arbitrary实例Example使用arbExample.
我喜欢quickCheck prop_example在指定使用的Gens数据结构时运行arbExample.
data Example = Example
{ myInt :: Int
, myList :: [String]
} deriving (Show)
data Gens = Gens
{ gen1 :: Gen Int
, gen2 :: Gen String }
arbExample :: Gens -> Gen Example
arbExample gens = do
i <- gen1 gens
xs <- vectorOf i (gen2 gens)
return Example{myInt=i, myList=xs}
prop_example :: Example -> …Run Code Online (Sandbox Code Playgroud) haskell ×6
linux ×3
io ×2
pid ×2
process ×2
autocomplete ×1
c ×1
file ×1
fork ×1
generator ×1
if-statement ×1
quickcheck ×1
rsync ×1
rust ×1
state-monad ×1
string ×1
testing ×1
unix ×1