Note [Desugaring overloaded list patterns]

GHC/Rename/Pat.hs:337 compiler 2 tickets

If OverloadedLists is enabled, we desugar a list pattern to a view pattern:

  [p1, p2, p3]
==>
  toList -> [p1, p2, p3]

This happens directly in the renamer, using the HsPatExpansion mechanism
detailed in Note [Rebindable syntax and XXExprGhcRn].

Note that we emit a special view pattern: we additionally keep track of an
inverse to the pattern.
See Note [Invertible view patterns] in GHC.Tc.TyCl.PatSyn for details.

== Wrinkle ==

This is all fine, except in one very specific case:
When the type being matched on is already a list type, so that the
pattern looks like
     toList @[ty] dict -> pat
then we know for certain that `toList` is an identity function, so we can
behave exactly as if the pattern was just `pat`.  This is important when
we have `OverloadedLists`.  For example (#14547, #25257)

> {-# LANGUAGE OverloadedLists #

References 2

Referenced by 5