Wed Sep 10 01:51:21 PDT 2008 [EMAIL PROTECTED]
* 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!
M ./compiler/typecheck/TcClassDcl.lhs -62 +98
M ./compiler/typecheck/TcExpr.lhs -3 +6
M ./compiler/typecheck/TcInstDcls.lhs -118 +84
M ./compiler/typecheck/TcUnify.lhs -22 +18
View patch online:
http://darcs.haskell.org/ghc/_darcs/patches/20080910085121-1287e-1aa91ac80b8e879f6a2a4ad4d876434ac58c4355.gz
_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc