我试图从_prop的例子写同样的东西在美味。(来自http://primitive-automaton.logdown.com/posts/142511/tdd-with-quickcheck的例子)
game9_prop :: Game9 -> Bool
game9_prop = (9==) . length . unGame . unGame9这就是我尝试的美味:
qcTestGengame9 :: TestTree
qcTestGengame9 = QC.testProperty "Better gen rate" $
\ (g :: Game9) -> length . unGame . unGame9 g == 9 --ERROR LINE此转换将给出以下错误:
test/Tasty.hs:53:11:
Illegal type signature: `Game9'
Perhaps you intended to use -XScopedTypeVariables
In a pattern type-signature这是Game9类型:
-- To make generation rate better
newtype Game9 = Game9 { unGame9 :: Game }
deriving (Eq, Show)
instance Arbitrary Game9 where
arbitrary = (Game9 . Game) `liftM` replicateM 9 arbitrary发布于 2014-04-08 21:43:04
若要修复即时错误,请删除类型注释,即使用
qcTestGengame9 :: TestTree
qcTestGengame9 = QC.testProperty "Better gen rate" $
\ g -> (length . unGame . unGame9) g == 9表达式unGame9 g已经确保了g :: Game9。
但实际上它更简单:使用定义的game9_prop,您可以只使用
qcTestGengame9 :: TestTree
qcTestGengame9 = QC.testProperty "Better gen rate" game9_prophttps://stackoverflow.com/questions/22899081
复制相似问题