RSpec before(:suite)和after(:suite)MiniTest 有替代品吗?
我怀疑自定义测试运行器是有序的,但我无法想象这不是一个常见的要求,所以有人可能实现了.:-)
有没有办法为值构造函数的参数定义类约束?
像这样的东西:
data Point2D = (Num a) => Point a a
Run Code Online (Sandbox Code Playgroud)
只要它们属于Num类,Point就可以接受任何参数?
我试图在Vim中捕获错误(E490),如下所示:
:try | foldopen! | catch | | endtry
Run Code Online (Sandbox Code Playgroud)
仍然,在执行此操作时,Vim显示错误:
Error detected while processing :
E490: No fold found
Run Code Online (Sandbox Code Playgroud)
如果有任何折叠,我想打开所有折叠.
有任何想法吗?
有人可以发一个使用IndentParser的小例子吗?我想解析类似YAML的输入,如下所示:
fruits:
apples: yummy
watermelons: not so yummy
vegetables:
carrots: are orange
celery raw: good for the jaw
Run Code Online (Sandbox Code Playgroud)
我知道有一个YAML包.我想学习IndentParser的用法.
考虑以下
data Predicate = Pred Name Arity Arguments
type Name = String
type Arity = Int
type Arguments = [Entity]
type Entity = String
Run Code Online (Sandbox Code Playgroud)
这将允许创建
Pred "divides" 2 ["1", "2"]
Pred "between" 3 ["2", "1", "3"]
Run Code Online (Sandbox Code Playgroud)
而且"非法"
Pred "divides" 2 ["1"]
Pred "between" 3 ["2", "3"]
Run Code Online (Sandbox Code Playgroud)
"非法"因为arity与参数列表的长度不匹配.
没有使用这样的功能
makePred :: Name -> Arity -> Arguments -> Maybe Predicate
makePred n a args | a == length args = Just (Pred n a args)
| otherwise = Nothing
Run Code Online (Sandbox Code Playgroud)
并且只从Predicate模块导出makePred,有没有办法强制值构造函数的正确性?
考虑以下:
module Main where
import Criterion.Main
import qualified Data.Vector as V
f1 :: V.Vector Double -> Double
f1 xs
| V.null xs = 0
| otherwise = V.last xss / V.head xss
where xss = V.dropWhile (< 10) xs
f2 :: V.Vector Double -> Double
f2 xs
| V.null xs = 0
| otherwise = V.last xs / V.head xs
setupEnv :: IO (V.Vector Double)
setupEnv = return $ V.enumFromN 0 10000000
main :: IO ()
main = defaultMain [ …Run Code Online (Sandbox Code Playgroud) 我最近被以下代码难住了:
class Foo
attr_accessor :n
def initialize(i)
@n = i
end
def val
n
end
def bump!
n += 1
end
end
f = Foo.new(0)
puts f.val
f.bump!
Run Code Online (Sandbox Code Playgroud)
puts f.val成功并按0预期打印出来.f.bump!导致以下情况NoMethodError
foo.rb:13:in `bump!': undefined method `+' for nil:NilClass (NoMethodError)
from foo.rb:20:in `<main>'
Run Code Online (Sandbox Code Playgroud)
任何想法,为什么n是nil在表达n += 1?
n = 1 + n相反,使用引发a TypeError(nil cannot be coerced into Fixnum),n实际上也是如此nil.
我有一个无限的实体列表,因此:
entities =
let f x = x ++ "'"
in "x" : "y" : "z" : map f entities
Run Code Online (Sandbox Code Playgroud)
我想定义一个函数,它在每个invokation上返回一个新实体.像这样:
> nextEntity
x
> nextEntity
y
.
.
.
Run Code Online (Sandbox Code Playgroud)
我想这是国家monad的地方,但是对指针感激不尽.
一些背景知识:如果您尝试在FOL中表示自然语言句子,则需要为实体指定变量."John loves Mary"需要两个变量(一个用于John,一个用于Mary),"John给Mary一本书"需要三个变量(John,Mary,书)等等.处理句子时遇到的每个"事物"的变量名称.
所以我想要使用的函数必须跟踪已生成的函数,并在调用时返回下一个函数.
haskell ×5
constructor ×2
ruby ×2
invariants ×1
minitest ×1
parsing ×1
sequence ×1
test-suite ×1
vector ×1
vim ×1
yaml ×1