[GHC] #12797: Default Rules stop working when providing some constraints

GHC ghc-devs at haskell.org
Wed Nov 2 09:21:28 UTC 2016


#12797: Default Rules stop working when providing some constraints
-------------------------------------+-------------------------------------
        Reporter:  danilo2           |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  GHC rejects       |  Unknown/Multiple
  valid program                      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 I took a quick look.  It's because `TcSimplify.findDefaultableGroups` uses
 `TcSimplify.approximateWC`; and the latter is also used when inferring the
 most general type of a function that lacks a type signature.  And
 `approximateWC` has the following note:
 {{{
 Note [ApproximateWC]
 ~~~~~~~~~~~~~~~~~~~~
 1.  We do *not* float anything out if the implication binds equality
     constraints, because that defeats the OutsideIn story.  Consider
        data T a where
          TInt :: T Int
          MkT :: T a

        f TInt = 3::Int

     We get the implication (a ~ Int => res ~ Int), where so far we've
 decided
       f :: T a -> res
     We don't want to float (res~Int) out because then we'll infer
       f :: T a -> Int
     which is only on of the possible types. (GHC 7.6 accidentally *did*
     float out of such implications, which meant it would happily infer
     non-principal types.)
 }}}
 But in the case of ''defaulting'' we ''do'' want to infer a less-than-
 most-general type; and that's just what is happening here.

 The fix is easy: give a boolean flag to `approximateWC`.  I'll do that
 soon.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12797#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list