Opened 2 years ago
Last modified 4 months 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: |
Description
> :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] >>= stringE.show) "True" --- With GHC 7.10.1 > $(isInstance ''Typeable [ConT ''Char] >>= stringE.show) "False"
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 (7)
comment:1 Changed 2 years ago by
Cc: | javran added |
---|
comment:2 follow-up: 4 Changed 2 years ago by
Component: | libraries/base → Template Haskell |
---|---|
Owner: | set to goldfire |
comment:3 Changed 4 months ago by
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?
comment:4 Changed 4 months ago by
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 4 months ago by
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 4 months ago by
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: http://www.haskell.org/ghc/ :? 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 4 months ago by
Why this isn't enabled in
-Wall
is beyond me.
Yes, at this point it sounds like it should be.m
Will fix. Thanks!