我想模拟Date构造函数,这样每当我调用new Date()时,它总是返回特定的时间.
我发现Sinon.js提供useFakeTimers来模拟时间.但是以下代码对我不起作用.
sinon.useFakeTimers(new Date(2011,9,1));
//expect : 'Sat Oct 01 2011 00:00:00' ,
//result : 'Thu Oct 27 2011 10:59:44‘
var d = new Date();
Run Code Online (Sandbox Code Playgroud) 优先级是什么::
,是否有任何运营商的优先级甚至低于它?
似乎优先级::
低于$
,因为下面的表达式都返回"ab"
map head $ ["alice", "bob"] :: String
map head ["alice", "bob"] :: String
Run Code Online (Sandbox Code Playgroud) 如果我使用"undefined"这样定义一个函数,它会进行类型检查.
add2 :: Int -> Int -> Int
add2 = undefined
Run Code Online (Sandbox Code Playgroud)
是否可以检测函数定义中是否有任何函数使用"未定义",并将其转换为警告?
在开发阶段,我可以使用"undefined"在我实现函数之前检查类型签名是否正确.然后在制作中我可以有一些方法来捕捉我忘记为"未定义"的函数实现的错误.
我正在发送一个带有 10 秒超时指定的上下文的请求:
ctx, cancel := context.WithTimeout(context.Background(), time.Second * 10)
defer cancel()
_, err := client.SendRequest(ctx)
if err != nil {
return 0, err
}
Run Code Online (Sandbox Code Playgroud)
现在,当我达到超时时,错误消息令人困惑:
超出上下文截止日期
是否可以检查 err 是否是超时错误,以便我可以打印更好的错误消息?
ctx, cancel := context.WithTimeout(context.Background(), time.Second * 10)
defer cancel()
_, err := client.SendRequest(ctx)
if err != nil {
if isTimeoutError(err) {
return nil, fmt.Errorf("the request is timeout after 10 seconds")
}
return nil, err
}
Run Code Online (Sandbox Code Playgroud)
如何实现这样的isTimeoutError
功能?
我有以下代码:
handledIO :: Int -> IO Int
handledIO x = handle (printException x) $ return $ [1, 2, 3] !! x
printException :: Int -> SomeException -> IO Int
printException x (SomeException e) = do
print ("Exception", x, e)
throw e
Run Code Online (Sandbox Code Playgroud)
当我输入handledIO 8
ghci时,我希望看到("Exception", 8, "*** Exception: Prelude.!!: index too large")
将被打印,但实际上只打印异常.为什么?
Chrome开发者工具的字体太小.每次打开Developer Tool时我都要修改devTools.css.
有没有办法修改devTools.css并保存?
我正在使用ARC.ARC会自动释放所有属性dealloc
吗?是否有必要手动设置所有公共属性和私有字段nil
?有什么好的模式可以遵循吗?
我在我的MacOS上安装了ghc 8.2.1.但是我的全局ghc-mod
仍在使用8.0.2,因为我最近将ghc升级到8.2.1.我想升级ghc-mod
.我尝试了以下命令,它返回错误如下:
? ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.2.1
? ghc-mod --version
ghc-mod version 5.7.0.0 compiled by GHC 8.0.2
? stack build --copy-compiler-tool ghc-mod hoogle weeder
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for ghc-mod-5.8.0.0:
Cabal-2.0.1.1 from stack configuration does not match >=1.18 && <1.25 (latest matching version is 1.24.2.0)
base-4.10.1.0 from stack configuration does not match >=4.6.0.1 && <4.10 (latest matching version is 4.9.1.0) …
Run Code Online (Sandbox Code Playgroud) 我有一个列表,我想将列表分成两个,一个是偶数索引中的元素,另一个是奇数索引.
breakByIndexes :: [a] -> ([a], [a])
例如:
> breakByIndexes ["A", "B", "C", "D"]
(["A", "C"], ["B", "D"]
> breakByIndexes ["A", "B", "C", "D", "E"]
(["A", "C", "E"], ["B", "D"]
Run Code Online (Sandbox Code Playgroud)
我得到了这样的解决方案
breakByIndexes [] = ([], [])
breakByIndexes [e] = ([e], [])
breakByIndexes (e:o:xs) =
let (es, os) = breakByIndexes xs
in (e : es, o : os)
Run Code Online (Sandbox Code Playgroud)
但我很好奇是否可以在不使用递归的情况下实现?是否可以通过编写现有函数来实现Data.List
?
我正在尝试在项目中使用以下命令构建本地 hoogle 服务器,该项目lts-11.1
用作解析器stack.yaml
stack hoogle -- server --local --port=8080
Run Code Online (Sandbox Code Playgroud)
它曾经可以工作,但现在由于此错误而失败:
? stack hoogle -- server --local --port=8080
Hoogle isn't installed. Automatically installing (use --no-setup to disable) ...
Minimum version is hoogle-5.0. Found acceptable hoogle-5.0.17.6 in your index, installing it.
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for hoogle-5.0.17.6:
haskell-src-exts-1.20.3 from stack configuration does not match >=1.21 && <1.22 (latest matching version is 1.21.0)
needed since hoogle is a build target. …
Run Code Online (Sandbox Code Playgroud)