我是Haskell的新手,我只是想编写一个简单的列表解析来从列表列表中删除空列表的每个实例,即输入此..
> remove ["abfwfw", "wfgwg", "", "dfw"]
Run Code Online (Sandbox Code Playgroud)
将导致此输出...
> ["abfwfw", "wfgwg", "dfw"]
Run Code Online (Sandbox Code Playgroud)
提前致谢 :)
如何将trial输出转换为JUnit xml格式?没有这种可能的报告格式trial.
$> trial --help-reporters
Trial's output can be customized using plugins called Reporters. You can
select any of the following reporters using --reporter=<foo>
subunit subunit output
bwverbose Colorless verbose output
text terse text output
verbose verbose color output (default reporter)
timing Timing output
summary minimal summary output
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习Haskell,但我在使用monad时遇到问题.
我导入了模块Data.Maybe.
但我不知道如何使用>>=运营商.
鉴于(>>=) :: Monad m => m a -> (a -> m b) -> m b我无法理解如何定义一个函数(a -> m b).
有人可以提供一些教学示例吗?
我在Haskell Emacs页面上看到haskell-mode中有许多可用的键绑定.我下载了Emacs 24.1并加载了一个Haskell文件,但绑定不起作用.例如,C-c C-=应该插入一个=和排队类型的签名,但Emacs给了我一个C-c C-= is undefined.
如何启用这些键绑定?
当我使用fromIntegral函数时,我希望有人可以在GHCi中解释以下行为:
Prelude> let x = 1 :: Integer
Prelude> :t x
x :: Integer
Prelude> sqrt $ fromIntegral x
1.0
Prelude> let y = fromIntegral x
Prelude> sqrt y
<interactive>:181:1:
No instance for (Floating Integer)
arising from a use of `sqrt'
Possible fix: add an instance declaration for (Floating Integer)
In the expression: sqrt y
In an equation for `it': it = sqrt y
Run Code Online (Sandbox Code Playgroud)
为什么我设置y然后采取它sqrt或直接采取sqrt?
我是Haskell的新手.我正在尝试编写一个程序,该程序将列表作为输入复制列表的每个元素k次,其中k=列表中元素的位置.
例如replic[5,6,7]给[[5],[6,6],[7,7,7]].
另一个条件是解决方案必须使用map功能.
直到现在我写的代码是:
replic [] = []
replic (x:xs) = map (replicate 2 ) [x] ++ replic xs
Run Code Online (Sandbox Code Playgroud)
这会复制每个元素两次,因为replicate具有输入参数2.
我需要的是replicate函数应该1 ,2 ,3在连续调用中给出输入.所以我需要一个柜台.我如何在那里使用计数器或做任何能给我元素位置的东西?
import Data.Attoparsec.Text.Lazy
import Data.Text.Lazy.Internal (Text)
import Data.Text.Lazy (pack)
data List a = Nil | Cons a (List a)
list :: Text
list = pack $ unlines
[ "0"
, "1"
, "2"
, "5"
]
Run Code Online (Sandbox Code Playgroud)
如何List Int解析器coud实现解析Cons 0 (Cons 1 (Cons 2 (Cons 5 Nil)))从list?
ps:纯解析器而不解析a [Int]并将其转换List Int为更好.
假设有一个F#定义:
type Either<'a,'b> = | Left of 'a | Right of 'b
let f (i : int) : Either<int, string> =
if i > 0
then Left i
else Right "nothing"
Run Code Online (Sandbox Code Playgroud)
函数f用于C#代码:
var a = Library.f(5);
Run Code Online (Sandbox Code Playgroud)
结果值如何a与数据构造函数进行模式匹配?就像是:
/*
(if a is Left x)
do something with x
(if a is Right y)
do something with y
*/
Run Code Online (Sandbox Code Playgroud) 假设有一个文件/etc/nixos/configuration.nix曾经用于一个nixos-rebuild switch进程。假设它是从文件系统中意外删除的。
有没有办法以某种方式恢复它?
我有一个运行的脚本curl.-H如果字符串不为空,我希望能够选择添加参数.引用和空格的级别有多复杂.
caption="Test Caption"
if [ "${caption}" != "" ]; then
CAPT=-H "X-Caption: ${caption}"
fi
curl -A "$UA" -H "Content-MD5: $MD5" -H "X-SessionID: $SID" -H "X-Version: 1" $CAPT http://upload.example.com/$FN
Run Code Online (Sandbox Code Playgroud)
这个想法是CAPT变量为空,或者包含与其他变量相同形式的所需-H头,例如, -H "X-Caption: Test Caption"
问题是在运行时,它将赋值解释为要执行的命令:
$bash -x -v test.sh
+ '[' 'Test caption' '!=' '' ']'
+ CAPT=-H
+ 'X-Caption: Test caption'
./test.sh: line 273: X-Caption: Test caption: command not found
Run Code Online (Sandbox Code Playgroud)
我已经尝试在代码之前重置IFS,但它没有什么区别.