What is the effect of freeze in the definition of Hedgehog.Gen.list

64 Views Asked by At

Hedgehog.Gen.list is defined as follows:

-- | 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)

I would have expected that using Shrink.list would be enough to produce all the shrinks of the list. However it makes a call to 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

From the function's comments I understand why it is used, but I'm puzzled about how this goal is acheived and what the effect would be of leaving this out.

0

There are 0 best solutions below