【发布时间】:2016-02-21 22:06:01
【问题描述】:
我有以下数据和函数
data Foo = A | B deriving (Show)
foolist :: Maybe Foo -> [Foo]
foolist Nothing = [A]
foolist (Just x) = [x]
prop_foolist x = (length (foolist x)) == 1
在运行quickCheck prop_foolist 时,ghc 告诉我 Foo 需要是 Arbitrary 的一个实例。
No instance for (Arbitrary Foo) arising from a use of ‘quickCheck’
In the expression: quickCheck prop_foolist
In an equation for ‘it’: it = quickCheck prop_foolist
我试过data Foo = A | B deriving (Show, Arbitrary),但结果是
Can't make a derived instance of ‘Arbitrary Foo’:
‘Arbitrary’ is not a derivable class
Try enabling DeriveAnyClass
In the data declaration for ‘Foo’
但是,我不知道如何启用DeriveAnyClass。我只是想用我的简单功能使用快速检查! x 的可能值是 Nothing,Just A 和 Just B。这应该可以测试吗?
【问题讨论】:
标签: haskell generics testing quickcheck