Note [Demand type Divergence]

GHC/Types/Demand.hs:1959 compiler

In contrast to DmdSigs, DmdTypes are elicited under a specific incoming demand.
This is described in detail in Note [Understanding DmdType and DmdSig].
Here, we'll focus on what that means for a DmdType's Divergence in a higher-order
scenario.

Consider
  err x y = x `seq` y `seq` error (show x)
this has a strictness signature of
  <1L><1L>b
meaning that we don't know what happens when we call err in weaker contexts than
C(1,C(1,L)), like @err `seq` ()@ (1A) and @err 1 `seq` ()@ (C(S,A)). We
may not unleash the botDiv, hence assume topDiv. Of course, in
@err 1 2 `seq` ()@ the incoming demand C(S,C(S,A)) is strong enough and we see
that the expression diverges.

Now consider a function
  f g = g 1 2
with signature <C(1,C(1,L))>, and the expression
  f err `seq` ()
now f puts a strictness demand of C(1,C(1,L)) onto its argument, which is unleashed
on err via the App rule. In contrast to weaker head strictness, this demand is
strong enough to unleash err's signature and hence we see that the whole
expression diverges!

References 1

Referenced by 2