[GHC] #16319: unexpected difference between newtype and data

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[GHC] #16319: unexpected difference between newtype and data

GHC - devs mailing list
#16319: unexpected difference between newtype and data
----------------------------------------+---------------------------------
           Reporter:  pjljvdlaar        |             Owner:  (none)
               Type:  bug               |            Status:  new
           Priority:  normal            |         Milestone:
          Component:  Compiler          |           Version:  8.2.2
           Keywords:                    |  Operating System:  Windows
       Architecture:  Unknown/Multiple  |   Type of failure:  None/Unknown
          Test Case:                    |        Blocked By:
           Blocking:                    |   Related Tickets:
Differential Rev(s):                    |         Wiki Page:
----------------------------------------+---------------------------------
 The following code compiles fine
 {{{#!hs
 -- | 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...

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #16319: unexpected difference between newtype and data

GHC - devs mailing list
#16319: unexpected difference between newtype and data
---------------------------------+----------------------------------------
        Reporter:  pjljvdlaar    |                Owner:  (none)
            Type:  bug           |               Status:  new
        Priority:  normal        |            Milestone:
       Component:  Compiler      |              Version:  8.2.2
      Resolution:                |             Keywords:
Operating System:  Windows       |         Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown  |            Test Case:
      Blocked By:                |             Blocking:
 Related Tickets:                |  Differential Rev(s):
       Wiki Page:                |
---------------------------------+----------------------------------------

Comment (by goldfire):

 Hm. It looks like the `newtype` deriving strategy (which is what would be
 used for `Eq` and `Ord` but not for others) ignores datatype contexts.

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #16319: unexpected difference between newtype and data

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#16319: unexpected difference between newtype and data
---------------------------------+----------------------------------------
        Reporter:  pjljvdlaar    |                Owner:  (none)
            Type:  bug           |               Status:  new
        Priority:  normal        |            Milestone:
       Component:  Compiler      |              Version:  8.2.2
      Resolution:                |             Keywords:
Operating System:  Windows       |         Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown  |            Test Case:
      Blocked By:                |             Blocking:
 Related Tickets:                |  Differential Rev(s):
       Wiki Page:                |
---------------------------------+----------------------------------------

Comment (by RyanGlScott):

 Indeed, `GeneralizedNewtypeDeriving` (and `DerivingVia`) have never taken
 the "stupid theta" (i.e., `DatatypeContexts`) into account when generating
 code for whatever reason. Fixing this wouldn't be too difficult (I think
 you'd just need to change the relevant bits in `TcDeriv`), but is it
 really worth it? `DatatypeContexts` is a deprecated feature:

 {{{
 λ> :set -XDatatypeContexts

 <no location info>: warning:
     -XDatatypeContexts is deprecated: It was widely considered a
 misfeature, and has been removed from the Haskell language.
 }}}

 And I'm not sure if it's worthwhile to continue to maintain it.

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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #16319: unexpected difference between newtype and data

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#16319: unexpected difference between newtype and data
---------------------------------+----------------------------------------
        Reporter:  pjljvdlaar    |                Owner:  (none)
            Type:  bug           |               Status:  new
        Priority:  normal        |            Milestone:
       Component:  Compiler      |              Version:  8.2.2
      Resolution:                |             Keywords:  DatatypeContexts
Operating System:  Windows       |         Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown  |            Test Case:
      Blocked By:                |             Blocking:
 Related Tickets:                |  Differential Rev(s):
       Wiki Page:                |
---------------------------------+----------------------------------------
Changes (by RyanGlScott):

 * keywords:   => DatatypeContexts


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

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets