From 562a8f20393b3e36dbd4ea9d5b7c4d3797c0182e Mon Sep 17 00:00:00 2001 From: autonym8 Date: Thu, 6 Jun 2024 15:00:07 +0200 Subject: [PATCH] Uniformize instances for newtype monoids --- src/Data/Aeson/Types/FromJSON.hs | 32 +++++--------------------------- src/Data/Aeson/Types/ToJSON.hs | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/src/Data/Aeson/Types/FromJSON.hs b/src/Data/Aeson/Types/FromJSON.hs index ac3e0091..7451ea7c 100644 --- a/src/Data/Aeson/Types/FromJSON.hs +++ b/src/Data/Aeson/Types/FromJSON.hs @@ -2382,67 +2382,45 @@ instance FromJSON a => FromJSON (Monoid.Last a) where omittedField = omittedField1 instance FromJSON1 Semigroup.Min where - liftParseJSON _ p _ a = coerce (p a) - - liftParseJSONList _ _ p a = coerce (p a) + liftParseJSON _ p _ = coerce p liftOmittedField = coerce instance (FromJSON a) => FromJSON (Semigroup.Min a) where parseJSON = parseJSON1 - parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList - - omittedField = omittedField1 - instance FromJSON1 Semigroup.Max where - liftParseJSON _ p _ a = coerce (p a) + liftParseJSON _ p _ = coerce p - liftParseJSONList _ _ p a = coerce (p a) liftOmittedField = coerce instance (FromJSON a) => FromJSON (Semigroup.Max a) where parseJSON = parseJSON1 - parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList - omittedField = omittedField1 - instance FromJSON1 Semigroup.First where - liftParseJSON _ p _ a = coerce (p a) + liftParseJSON _ p _ = coerce p - liftParseJSONList _ _ p a = coerce (p a) liftOmittedField = coerce instance (FromJSON a) => FromJSON (Semigroup.First a) where parseJSON = parseJSON1 - parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList - - instance FromJSON1 Semigroup.Last where - liftParseJSON _ p _ a = coerce (p a) + liftParseJSON _ p _ = coerce p - liftParseJSONList _ _ p a = coerce (p a) liftOmittedField = coerce instance (FromJSON a) => FromJSON (Semigroup.Last a) where parseJSON = parseJSON1 - parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList - omittedField = omittedField1 - instance FromJSON1 Semigroup.WrappedMonoid where - liftParseJSON _ p _ a = coerce (p a) + liftParseJSON _ p _ = coerce p - liftParseJSONList _ _ p a = coerce (p a) liftOmittedField = coerce instance (FromJSON a) => FromJSON (Semigroup.WrappedMonoid a) where parseJSON = parseJSON1 - parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList - omittedField = omittedField1 - #if !MIN_VERSION_base(4,16,0) instance FromJSON1 Semigroup.Option where liftParseJSON o = coerce (liftParseJSON @Maybe o) diff --git a/src/Data/Aeson/Types/ToJSON.hs b/src/Data/Aeson/Types/ToJSON.hs index 3fea324c..2649e9f0 100644 --- a/src/Data/Aeson/Types/ToJSON.hs +++ b/src/Data/Aeson/Types/ToJSON.hs @@ -2091,8 +2091,8 @@ instance ToJSON a => ToJSON (Down a) where ------------------------------------------------------------------------------- instance ToJSON1 Monoid.Dual where - liftToJSON _ t _ = t . Monoid.getDual - liftToEncoding _ t _ = t . Monoid.getDual + liftToJSON _ t _ = coerce t + liftToEncoding _ t _ = coerce t liftOmitField = coerce instance ToJSON a => ToJSON (Monoid.Dual a) where @@ -2155,8 +2155,8 @@ instance ToJSON a => ToJSON (Monoid.Last a) where omitField = omitField1 instance ToJSON1 Semigroup.Min where - liftToJSON _ t _ (Semigroup.Min x) = t x - liftToEncoding _ t _ (Semigroup.Min x) = t x + liftToJSON _ t _ = coerce t + liftToEncoding _ t _ = coerce t liftOmitField = coerce instance ToJSON a => ToJSON (Semigroup.Min a) where @@ -2166,8 +2166,8 @@ instance ToJSON a => ToJSON (Semigroup.Min a) where instance ToJSON1 Semigroup.Max where - liftToJSON _ t _ (Semigroup.Max x) = t x - liftToEncoding _ t _ (Semigroup.Max x) = t x + liftToJSON _ t _ = coerce t + liftToEncoding _ t _ = coerce t liftOmitField = coerce instance ToJSON a => ToJSON (Semigroup.Max a) where @@ -2176,8 +2176,8 @@ instance ToJSON a => ToJSON (Semigroup.Max a) where omitField = omitField1 instance ToJSON1 Semigroup.First where - liftToJSON _ t _ (Semigroup.First x) = t x - liftToEncoding _ t _ (Semigroup.First x) = t x + liftToJSON _ t _ = coerce t + liftToEncoding _ t _ = coerce t liftOmitField = coerce instance ToJSON a => ToJSON (Semigroup.First a) where @@ -2186,8 +2186,8 @@ instance ToJSON a => ToJSON (Semigroup.First a) where omitField = omitField1 instance ToJSON1 Semigroup.Last where - liftToJSON _ t _ (Semigroup.Last x) = t x - liftToEncoding _ t _ (Semigroup.Last x) = t x + liftToJSON _ t _ = coerce t + liftToEncoding _ t _ = coerce t liftOmitField = coerce instance ToJSON a => ToJSON (Semigroup.Last a) where @@ -2196,8 +2196,8 @@ instance ToJSON a => ToJSON (Semigroup.Last a) where omitField = omitField1 instance ToJSON1 Semigroup.WrappedMonoid where - liftToJSON _ t _ (Semigroup.WrapMonoid x) = t x - liftToEncoding _ t _ (Semigroup.WrapMonoid x) = t x + liftToJSON _ t _ = coerce t + liftToEncoding _ t _ = coerce t liftOmitField = coerce instance ToJSON a => ToJSON (Semigroup.WrappedMonoid a) where