[GHC] #12240: Common Sense for Type Classes

GHC ghc-devs at haskell.org
Wed Jul 6 03:37:56 UTC 2016


#12240: Common Sense for Type Classes
-------------------------------------+-------------------------------------
        Reporter:  Mathnerd314       |                Owner:
            Type:  feature request   |               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 rwbarton):

 > It is a blatant violation of the Haskell Report ("A type may not be
 declared as an instance of a particular class more than once in the
 program."), yet it compiles in GHC with no extensions.

 Yes, so it is a bug. See #2356.

 > Meanwhile, all I want to do is relax instantiation from "a single
 instance matches and no other instance unifies" to "a single instance
 unifies and no other instance unifies". This is only interesting in
 limited situations, such as the example in comment:4, and leaves all
 Haskell 98 instances unchanged. I do not see how it adds any incoherence,
 because in both rules only a single instance is allowed.

 Your proposal seems to even allow situations like
 {{{#!hs
 class C a b where
     f :: a -> Int

 instance C String () where
     f _ = 1

 instance C String Bool where
     f _ = 2
 }}}
 If the two instances are in different modules, the expression `f "a" ::
 Int` will type check but have value `1` or `2` depending on which module
 is imported. Yet the instances are not even overlapping.

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


More information about the ghc-tickets mailing list