[project @ 2004-05-12 12:55:12 by simonpj]
authorsimonpj <unknown>
Wed, 12 May 2004 12:55:12 +0000 (12:55 +0000)
committersimonpj <unknown>
Wed, 12 May 2004 12:55:12 +0000 (12:55 +0000)
commit825fba2af286272a61a712ce65802fd85b338c23
tree908b2a8cdea3594684ec7ed8a0b7c44f96ee1903
parent2db3d8c5641cd35b70da34e0b1da4629c62b694a
[project @ 2004-05-12 12:55:12 by simonpj]
---------------------------------
Another delicate fix to the way that the
Dreaded Monomorpism Restriction is handled
---------------------------------

     I think this should merge nicely to the STABLE branch

In TcSimplify 1.130 I changed tcSimplifyRestricted (used for
declarations that fall under the monomorphism restriction) to use Plan
C.  Unfortunately, it later transpired that George Russel and Serge
Mechveliani both made somewhat-dubious use of overlapping instances
that conflicted with this change. Here's the example

  instance (HasBinary ty IO) => HasCodedValue ty

  foo :: HasCodedValue a => String -> IO a

  doDecodeIO :: HasCodedValue a => () -> () -> IO a
  doDecodeIO codedValue view = let { act = foo "" } in  act

You might think this should work becuase the call to 'foo' in the last
line gives rise to a constraint (HasCodedValue t), which can be
satisfied by the type sig for doDecodeIO.  But the restricted binding
act = ... calls tcSimplifyRestricted, and Plan C simplifies the
constraint using the (rather bogus) instance declaration, and now we
are stuffed.

This commit implements Plan D, which is like plan B except that it does no
improvement, and hence avoids plan B's flaw.  See the comments with Plan D.

The only criticism one might make of Plan D is that it may sometimes quantify
a restricted binding over "too few" type variables; but one can solve that
by adding a type sig.  So this seems better than the very subtle problems
with Plan C.

All of this is very much at the margin: George and Sergey are pushing
their luck.
ghc/compiler/typecheck/TcSimplify.lhs