MINIMAL pragma and default implementations
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.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.10.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |