More refactoring of instance declarations (fixes Trac #2572)
In refactoring instance declarations I'd taken a short cut over
scoped type variables, but it wasn't right as #2572 shows.
Fixing it required a significant chunk of further refactoring,
alas. But it's done! Quite tidily as it turns out.
The main issue is that when typechecking a default method, we
need two sets of type variables in scope
class C a where
op :: forall b. ...
op = e
In 'e', *both* 'a' and 'b' are in scope. But the type of the
default method has a nested flavour
op :: forall a. C a => forall b. ....
and our normal scoping mechanisms don't bring 'b' into scope.
(And probably shouldn't.)
Solution (which is done for instance methods too) is to use
a local defintion, like this:
$dmop :: forall a. C a => forall b. ....
$dmop a d = let
op :: forall b. ...
op = e
in op
and now the scoping works out. I hope I have now see the
last of this code for a bit!