作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在使用 GHCi 的 Haskell 中,有一种方法可以加载如下所示的文件,让您可以测试具有绑定(bind)的方法。
用例: 尝试测试我的模块的一部分,同时拥有其余部分的框架代码。 (至于没有XY问题)
module X (methodA, methodB, methodC) where
methodA :: String->String
methodA name = "Hello " ++ name
methodB :: Int -> String
methodC :: String -> String
这显然会输出正确的错误:“methodB”的类型签名缺少附带的绑定(bind)
。例如,我想要类似于下面的东西来工作。
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Prelude> :l example.hs
[1 of 1] Compiling X ( example.hs, interpreted )
example.hs:6:1: error:
The type signature for ‘methodB’ lacks an accompanying binding
example.hs:8:1: error:
The type signature for ‘methodC’ lacks an accompanying binding
Failed, modules loaded: none.
Prelude> methodA "jamesmstone"
<interactive>:2:1: error:
Variable not in scope: methodA :: [Char] -> t
最佳答案
您可以使用-fdefer-type-errors
。这将向您发出有关类型错误的警告,但不会阻止您运行程序的其他类型正确的部分。
例子:
如果 Program.hs
包含:
foo :: Int
foo = 'a'
main = putStrLn "Hello, world"
然后使用 -fdefer-type-errors 你仍然可以加载并运行 main
:
$ ghci -fdefer-type-errors Program.hs
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( Program.hs, interpreted )
Program.hs:5:7: Warning:
Couldn't match expected type ‘Int’ with actual type ‘Char’
In the expression: 'a'
In an equation for ‘foo’: foo = 'a'
Ok, modules loaded: Main.
*Main> main
Hello, world
*Main>
关于Haskell:尽可能多地加载 GHCi,而不是失败或错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39136407/
我知道在 KDB 中,如果您有一个列表,例如... l:`apples`oranges`pears` 您可以像下面这样进行 N 次随机选择: 9?l 但是如何尽可能均匀地选择列表中的每个项目? 最佳答
我真的厌倦了它。我有一个高级 Web 应用程序依赖于大量 Javascript 库(jQuery、jQueryUI、OpenLayers、highcharts、EJSChart 等等)。不用说,Int
我是一名优秀的程序员,十分优秀!