Skip to content
  • Simon Peyton Jones's avatar
    [project @ 2004-05-12 12:55:12 by simonpj] · 825fba2a
    Simon Peyton Jones authored
    ---------------------------------
    	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.
    825fba2a