[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
Fri Aug 16 13:48:37 CEST 2013


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

Comment (by simonpj):

 Omer writes: I just started GHC development made a commit for ticket 7401:
 http://ghc.haskell.org/trac/ghc/ticket/7401

 My patch is here:
 https://github.com/osa1/ghc/commit/3ec257ff48372de30df59cd8854ce28954c9db95

 `make test` succeeds. My test case for this patch is something like this:
 {{{
     data D deriving Eq

     main :: IO ()
     main = print ((undefined :: D) == (undefined :: D))
 }}}
 example:
 {{{
 haskell$  ./ghc/inplace/bin/ghc-stage2 --interactive derive.hs
 GHCi, version 7.7.20130806: http://www.haskell.org/ghc/  :? for help
 Loading package ghc-prim ... linking ... done.
 Loading package integer-gmp ... linking ... done.
 Loading package base ... linking ... done.
 [1 of 1] Compiling Main             ( derive.hs, interpreted )
 Ok, modules loaded: Main.
 ghci> main
 True
 it :: ()
 }}}
 This behavior (returning True) is consistent with standalone deriving
 version:
 {{{
     haskell$  cat derive_standalone.hs
     {-# LANGUAGE StandaloneDeriving #-}

     data D

     deriving instance Eq D

     main :: IO ()
     main = print ((undefined :: D) == (undefined :: D))

     haskell$  ./ghc/inplace/bin/ghc-stage2 --interactive
 derive_standalone.hs
     GHCi, version 7.7.20130806: http://www.haskell.org/ghc/  :? for help
     Loading package ghc-prim ... linking ... done.
     Loading package integer-gmp ... linking ... done.
     Loading package base ... linking ... done.
     [1 of 1] Compiling Main             ( derive_standalone.hs,
 interpreted )
     Ok, modules loaded: Main.
     ghci> main
     True
     it :: ()
     ghci>
     Leaving GHCi.
 }}}

 However, if you want (==) implementation in this case to be `error
 "Void (==)"`, I think I can also do that by first fixing the code
 generated by `StandaloneDeriving` extension and then fixing my current
 patch.

 Any comments and reviews would be appreciated!

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




More information about the ghc-tickets mailing list