Opened 3 years ago

Last modified 6 weeks ago

#11251 new bug

isInstance does not work on Typeable with base-4.8 anymore

Reported by: songzh Owned by: goldfire
Priority: normal Milestone:
Component: Template Haskell Version: 7.10.1
Keywords: Typeable, isInstance Cc: javran
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


> :set -XTemplateHaskell
> :m +Data.Tyepable
> :m +Language.Haskell.TH

--- With GHC 7.8 or earlier versions of GHC (I only tried with GHC 7.6, but my friends tried on 7.8 and earlier versoin)
> $(isInstance ''Typeable [ConT ''Char] >>=

--- With GHC 7.10.1
> $(isInstance ''Typeable [ConT ''Char] >>=

I have noticed that standalone derivings of Typeable instances in Data.Typeable are disappared magically in base-4.8 of GHC 7.10,also one cannot query the instances of it by using :i Typeable in GHCi, however, obviously, I can use typeOf function in base-4.8 to get the TypeRep of Char.

The problem is that isInstance in template-haskell library doesn't know Char and many other types are instances of Typeable anymore.

Change History (8)

comment:1 Changed 3 years ago by javran

Cc: javran added

comment:2 Changed 3 years ago by goldfire

Component: libraries/baseTemplate Haskell
Owner: set to goldfire

Will fix. Thanks!

comment:3 Changed 13 months ago by songzh

I also find it is allowed to derive Typeable class several times for one data type. I am now with GHC 8.2

{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
import Data.Typeable

data TT = TT

deriving instance Typeable TT
-- allowed to derive twice.
deriving instance Typeable TT

deriving instance Show TT
-- Not allowed to derive twice
-- deriving instance Show TT

Should this be allowed? Or they are the same problem with this ticket. I speculate these are the same problem since GHC does not know TT is already an instance of Typeable or not after the first time of deriving.

Do I need to open another ticket for this problem?

Last edited 13 months ago by songzh (previous) (diff)

comment:4 in reply to:  2 Changed 13 months ago by songzh

Replying to goldfire:

Will fix. Thanks!

I want to see what is actually the problems is in template-haskell package but I did not find any clue by following the definition of isInstance. Could you give me any clues on this problem in the source code of GHC?

comment:5 Changed 13 months ago by simonpj

Re comment:3, we automatically derive a Typeable instance for every type, so it should probably be an error to derive it explicitly. Does everyone agree?

comment:6 Changed 13 months ago by RyanGlScott

FWIW, there is already a warning for this sort of thing in the form of -Wderiving-typeable:

$ ghci Bug.hs -Wderiving-typeable
GHCi, version 8.2.1:  :? for help                                      
Loaded GHCi configuration from /home/rgscott/.ghci                                                 
[1 of 1] Compiling Main             ( Bug.hs, interpreted )

Bug.hs:6:1: warning: [-Wderiving-typeable]
    • Deriving ‘Typeable’ has no effect: all types now auto-derive Typeable
    • In the stand-alone deriving instance for ‘Typeable TT’
6 | deriving instance Typeable TT
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Bug.hs:8:1: warning: [-Wderiving-typeable]
    • Deriving ‘Typeable’ has no effect: all types now auto-derive Typeable
    • In the stand-alone deriving instance for ‘Typeable TT’
8 | deriving instance Typeable TT
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Why this isn't enabled in -Wall is beyond me.

comment:7 Changed 13 months ago by bgamari

Why this isn't enabled in -Wall is beyond me.

Yes, at this point it sounds like it should be.m

comment:8 Changed 6 weeks ago by Ryan Scott <…>

In 85376570/ghc:

Documentation fixes in 'template-haskell'

 * Clarify the non-presence of derived classes in reified decls (#15167)
 * Clarify the shallowness of "reifyInstances" (#7066)
 * Mention that 'Typeable' instances are not found by reifyInstances (#11251)
 * Various Haddock markup issues fixed

Reviewers: goldfire, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, carter

GHC Trac Issues: #15167, #7066, #11251

Differential Revision:
Note: See TracTickets for help on using tickets.