[GHC] #10959: MINIMAL pragma and default implementations

GHC ghc-devs at haskell.org
Sun Oct 11 13:51:24 UTC 2015


#10959: MINIMAL pragma and default implementations
-------------------------------------+-------------------------------------
           Reporter:  basvandijk     |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  7.10.2
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  Other
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 The `ToJSON` class from the `aeson` library recently gained the new method
 `toEncoding` which has a default implementation based on the existing
 `toJSON` method.

 A MINIMAL pragma was added to `toJSON` to make sure instances will define
 it.

 However, `toJSON` also has a default implementation but only if the type
 has an instance for `Generic`:

 {{{
 class ToJSON a where
     toJSON     :: a -> Value
     {-# MINIMAL toJSON #-}

     default toJSON :: (Generic a, GToJSON (Rep a)) => a -> Value
     toJSON = genericToJSON defaultOptions

     toEncoding :: a -> Encoding
     toEncoding = Encoding . E.encodeToBuilder . toJSON
 }}}

 The problem is that users of `aeson` who are using the generic
 implementation get warnings that their `toJSON` method is not defined:

 {{{
 No explicit implementation for
   ‘toJSON’
 In the instance declaration for ‘ToJSON MyType’
 }}}

 It would be nice if GHC is a bit smarter in this case so that when a a
 default implementation is used it won't give the warning.

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


More information about the ghc-tickets mailing list