Hedgehog.Gen.list的定义中冻结的影响是什么

时间:2019-03-07 11:18:44

标签: haskell property-based-testing haskell-hedgehog

Hedgehog.Gen.list的定义如下:

-- | Generates a list using a 'Range' to determine the length.
--
list :: MonadGen m => Range Int -> m a -> m [a]
list range gen =
  sized $ \size ->
    (traverse snd =<<) .
    ensure (atLeast $ Range.lowerBound size range) .
    shrink Shrink.list $ do
      k <- integral_ range
      replicateM k (freeze gen)

我希望使用Shrink.list足以产生列表的所有收缩。但是,它会调用freeze

-- | Freeze the size and seed used by a generator, so we can inspect the value
--   which it will produce.
--
--   This is used for implementing `list` and `subtermMVec`. It allows us to
--   shrink the list itself before trying to shrink the values inside the list.
--
freeze :: MonadGen m => m a -> m (a, m a)
freeze =
  freezeGen

从函数的注释中我理解了为什么要使用它,但是我对如何实现此目标以及将其遗忘会产生什么效果感到困惑。

0 个答案:

没有答案