![](/img/trans.png)
[英]What is the difference between forall a. [a] and [forall a. a]?
[英]Difference between generating random input through 'Gen' or through 'forAll' in Hedgehog
假設,我想在Haskell的hedgehog庫的幫助下測試Sum
的以下關聯屬性:
a <> (b <> c) ≡ (a <> b) <> c
我實際上有兩種方法來生成隨機輸入。
Gen
生成所有內容(使用Gen
的Applicative和Monad實例) genTriple :: Get (Int, Int, Int)
genTriple = liftA3 (,,) Gen.enumBounded Gen.enumBounded Gen.enumBounded
prop_assoc :: Property
prop_assoc = property $ do
(a, b, c) <- forAll genTriple
(Sum a <> Sum b) <> Sum c === Sum a <> (Sum b <> Sum c)
forAll
下生成每個字段 prop_assoc :: Property
prop_assoc = property $ do
a <- forAll Gen.enumBounded
b <- forAll Gen.enumBounded
c <- forAll Gen.enumBounded
(Sum a <> Sum b) <> Sum c === Sum a <> (Sum b <> Sum c)
我想知道,兩種方法有什么區別? 它是否以某種方式影響性能或並行化或隨機性?
包維護者在相應的GitHub問題下回答了這個問題:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.