[GHC] #7401: Can't derive instance for Eq when datatype has no constructor, while it is trivial do do so.

GHC ghc-devs at haskell.org
Mon Jun 15 08:50:40 UTC 2015


#7401: Can't derive instance for Eq when datatype has no constructor, while it is
trivial do do so.
-------------------------------------+-------------------------------------
        Reporter:  jpbernardy        |                   Owner:  osa1
            Type:  feature request   |                  Status:  new
        Priority:  normal            |               Milestone:  7.12.1
       Component:  Compiler          |                 Version:  7.6.1
      Resolution:                    |                Keywords:  deriving,
Operating System:  Unknown/Multiple  |  newcomer
 Type of failure:  GHC rejects       |            Architecture:
  valid program                      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:  Phab:D978
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Responding to Phab here, because the design discussion is less likely to
 get lost here.

 1.  Thank you for the user manual update.  Can you add a paragraph or two
 explaining the design choice?  After all, if I did `deriving( Eq )` on an
 empty data type, or standalone deriving, I would expect a static error;
 the generated code is never useful.  But on the contrary, we now propose
 to give a dynamic error, postponing a crash until runtime.  Why is this
 good?  Explain either in the user manual or on a wiki page that discusses.
 comment:6 seems relevant, but is cryptic.

 2.  I'm certain that standalone deriving and `deriving(...)` on a data
 type declaration should behave the same.  Imagine trying to explain the
 difference in the user manual, if they differed! Can you make it so?

 3. For Ix, Enum, Bounded, the
 [https://www.haskell.org/onlinereport/haskell2010/haskellch19.html#x27-22700019.2
 2010 report] uses words like "derived instance declarations for the class
 Ix are only possible for enumerations (i.e. datatypes having only nullary
 constructors) and single-constructor datatypes".

   It seems odd to make them fail with a static error if Eq etc fail with a
 dynamic error.  We can interpret the words "having only nullary
 constructors" as true for an empty data type; after all all the
 constructors it has are nullary.  So let's make `isEnumeration` true for
 empty types too.  (Make a `Note` to explain; and the user manual.)

 Simon

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


More information about the ghc-tickets mailing list