Instantiate GND bindings with an explicit type signature

Authored by RyanGlScott on Jul 5 2018, 7:30 AM.

Description

Instantiate GND bindings with an explicit type signature

Summary:
Before, we were using visible type application to apply
impredicative types to coerce in
GeneralizedNewtypeDeriving-generated bindings. This approach breaks
down when combined with QuantifiedConstraints in certain ways,
which Trac #14883 and Trac #15290 provide examples of. See
Note [GND and QuantifiedConstraints] for all the gory details.

To avoid this issue, we instead use an explicit type signature to
instantiate each GND binding, and use that to bind any type variables
that might be bound by a class method's type signature. This reduces
the need to impredicative type applications, and more importantly,
makes the programs from Trac #14883 and Trac #15290 work again.

Test Plan: make test TEST="T15290b T15290c T15290d T14883"

Reviewers: simonpj, bgamari

Reviewed By: simonpj

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: Trac #14883, Trac #15290

Differential Revision: https://phabricator.haskell.org/D4895

(cherry picked from commit 132273f34e394bf7e900d0c15e01e91edd711890)