Skip to content

unexpected difference between newtype and data

The following code compiles fine

-- | A referable class
-- An object can only have one reference.
-- For example, a function is either referenced by name of by signature but not both.
class ( Eq (Ref a)
      , Ord (Ref a)
      , Hashable (Ref a)
      , Show (Ref a)
      , Read (Ref a)
      , Data (Ref a)
      ) => Referable a where
    type Ref a
    toRef :: a -> Ref a

data Referable a => 
            RefMap a = RefMap { -- | the HashMap
                                toHashMap :: HashMap.Map (Ref a) a
                              } deriving (Eq, Ord, Show, Read, Data)

yet following the hlint hint to replace data by the equivalent newtype results in the following issues:

  src\TorXakis\Referable.hs:59:43: error:
        * Could not deduce (Eq (Ref a))
            arising from the 'deriving' clause of a data type declaration
          from the context: Eq a
            bound by the deriving clause for `Eq (RefMap a)'
            at src\TorXakis\Referable.hs:59:43-44
          Possible fix:
            use a standalone 'deriving instance' declaration,
              so you can specify the instance context yourself
        * When deriving the instance for (Eq (RefMap a))
       |
    59 |                               } deriving (Eq, Ord, Show, Read, Data)
       |                                           ^^

    src\TorXakis\Referable.hs:59:47: error:
        * Could not deduce (Ord (Ref a))
            arising from the 'deriving' clause of a data type declaration
          from the context: Ord a
            bound by the deriving clause for `Ord (RefMap a)'
            at src\TorXakis\Referable.hs:59:47-49
          Possible fix:
            use a standalone 'deriving instance' declaration,
              so you can specify the instance context yourself
        * When deriving the instance for (Ord (RefMap a))
       |
    59 |                               } deriving (Eq, Ord, Show, Read, Data)

I assume this is a bug...

Trac metadata
Trac field Value
Version 8.2.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information