[GHC] #9757: Warn about derivable instances

GHC ghc-devs at haskell.org
Mon Nov 3 15:50:55 UTC 2014


#9757: Warn about derivable instances
-------------------------------------+-------------------------------------
              Reporter:  dfeuer      |            Owner:
                  Type:  feature     |           Status:  new
  request                            |        Milestone:
              Priority:  normal      |          Version:  7.9
             Component:  Compiler    |         Keywords:
            Resolution:              |     Architecture:  Unknown/Multiple
      Operating System:              |       Difficulty:  Unknown
  Unknown/Multiple                   |       Blocked By:
       Type of failure:              |  Related Tickets:
  None/Unknown                       |
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by goldfire):

 Replying to [comment:2 dfeuer]:
 > Replying to [comment:1 goldfire]:
 > > To my knowledge, GHC can ''not'' derive instances better than anyone
 else. Since the advent of `coerce`, `GeneralizedNewtypeDeriving` has no
 magic -- any GND instance can be written by hand, sometimes with lots of
 type annotations and `ScopedTypeVariables`, though.
 >
 > I don't ''think'' this is exactly right. As I understand it, `coerce`
 should let you hand-build an exact ''copy'' of an existing dictionary, but
 `GeneralizedNewtypeDeriving` lets you actually ''reuse'' the dictionary.

 No, GND doesn't let you reuse dictionaries. Superclass instances might be
 different between the representation type and the newtype, and so reusing
 a dictionary might be wrong. GND builds a copy. (This surprised me, too,
 when I learned it.)


 > It's useful because GHC can derive a lot more things today than in olden
 times, and there's a lot of old code that hasn't noticed yet.

 I still think this would be quite a bit of work and one more thing to
 maintain within GHC. The feature would also necessarily be heuristic in
 nature.

 It strikes me this would make a great feature in HLint, but I personally
 don't think GHC is the right home for it.

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


More information about the ghc-tickets mailing list