[GHC] #12787: Weird type constraint with undecidable instances

GHC ghc-devs at haskell.org
Mon Oct 31 20:49:54 UTC 2016


#12787: Weird type constraint with undecidable instances
-------------------------------------+-------------------------------------
        Reporter:  nome              |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  8.0.1
  checker)                           |             Keywords:
      Resolution:                    |  UndecidableInstances
Operating System:  Linux             |         Architecture:  x86_64
 Type of failure:  GHC rejects       |  (amd64)
  valid program                      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by nome):

 Maybe I've minimized the example a bit too much. The `PartialOrd` instance
 given is not meant to be universal, but as a default. In a slightly more
 realistic example, it would be made overlappable, like so:
 {{{#!hs
 instance {-# OVERLAPPABLE #-} TotalOrd a => PartialOrd a where
     tryCompare x y = Just $ tcompare x y
 }}}
 And there would be additional instances, e.g.
 {{{#!hs
 import Data.List
 -- insert classes and instances as above
 instance Eq a => PartialOrd [a] where
     tryCompare xs ys =
         if xs == ys then Just EQ
         else if null (xs \\ ys) then Just LT
         else if null (ys \\ xs) then Just GT
         else Nothing
 }}}
 If I understand
 [https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html
 #instance-overlap overlapping instances] correctly, GHC should consider
 ''all'' applicable instances and be "conservative about committing to an
 overlapping instance", so I would expect it to refrain from committing to
 the `TotalOrd a => PartialOrd a` one. Still, even with these additions, I
 get the same error.

 Ideally, the default implementation would be part of the `PartialOrd`
 class (like default implementations of the class's own methods); but it
 seems that there's no way to provide default implementations for
 superclass methods in a class declaration.

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


More information about the ghc-tickets mailing list