@@ -87,7 +87,7 @@ import Data.Hashable (Hashable(..))
8787import Data.Int (Int16, Int32, Int64, Int8)
8888import Data.List.NonEmpty (NonEmpty(..))
8989import Data.Maybe (fromMaybe)
90−import Data.Monoid ((<>), Dual(..), First (..), Last (..))
90+import Data.Monoid ((<>))
9191import Data.Proxy (Proxy(..))
9292import Data.Ratio ((%), Ratio)
9393import Data.Scientific (Scientific)
@@ -112,7 +112,9 @@ import qualified Data.HashSet as HashSet
112112import qualified Data.IntMap as IntMap
113113import qualified Data.IntSet as IntSet
114114import qualified Data.Map as M
115+import qualified Data.Monoid as Monoid
115116import qualified Data.Scientific as Scientific
117+import qualified Data.Semigroup as Semigroup
116118import qualified Data.Sequence as Seq
117119import qualified Data.Set as Set
118120import qualified Data.Text as T
@@ -124,6 +126,7 @@ import qualified Data.Vector.Generic as VG
124126import qualified Data.Vector.Primitive as VP
125127import qualified Data.Vector.Storable as VS
126128import qualified Data.Vector.Unboxed as VU
129+
127130import Unsafe.Coerce (unsafeCoerce)
128131
129132#ifndef HAS_COERCIBLE
@@ -1314,6 +1317,8 @@ instance (FromJSON a) => FromJSON (NonEmpty a) where
13141317 parseJSON = parseJSON1
13151318 {-# INLINE parseJSON #-}
13161319
1320+
1321+
13171322-------------------------------------------------------------------------------
13181323-- scientific
13191324-------------------------------------------------------------------------------
@@ -1605,29 +1610,113 @@ instance FromJSON NominalDiffTime where
16051610-- base Monoid/Semigroup
16061611-------------------------------------------------------------------------------
16071612
1608−instance FromJSON1 Dual where
1609− liftParseJSON p _ = fmap Dual . p
1613+instance FromJSON1 Monoid.Dual where
1614+ liftParseJSON p _ = fmap Monoid.Dual . p
1615+ {-# INLINE liftParseJSON #-}
1616+
1617+instance FromJSON a => FromJSON (Monoid.Dual a) where
1618+ parseJSON = parseJSON1
1619+ {-# INLINE parseJSON #-}
1620+
1621+
1622+instance FromJSON1 Monoid.First where
1623+ liftParseJSON p p' = fmap Monoid.First . liftParseJSON p p'
1624+ {-# INLINE liftParseJSON #-}
1625+
1626+instance FromJSON a => FromJSON (Monoid.First a) where
1627+ parseJSON = parseJSON1
1628+ {-# INLINE parseJSON #-}
1629+
1630+
1631+instance FromJSON1 Monoid.Last where
1632+ liftParseJSON p p' = fmap Monoid.Last . liftParseJSON p p'
1633+ {-# INLINE liftParseJSON #-}
1634+
1635+instance FromJSON a => FromJSON (Monoid.Last a) where
1636+ parseJSON = parseJSON1
1637+ {-# INLINE parseJSON #-}
1638+
1639+
1640+instance FromJSON1 Semigroup.Min where
1641+ liftParseJSON p _ a = Semigroup.Min <$> p a
1642+ {-# INLINE liftParseJSON #-}
1643+
1644+ liftParseJSONList _ p a = fmap Semigroup.Min <$> p a
1645+ {-# INLINE liftParseJSONList #-}
1646+
1647+instance (FromJSON a) => FromJSON (Semigroup.Min a) where
1648+ parseJSON = parseJSON1
1649+ {-# INLINE parseJSON #-}
1650+
1651+ parseJSONList = liftParseJSONList parseJSON parseJSONList
1652+ {-# INLINE parseJSONList #-}
1653+
1654+
1655+instance FromJSON1 Semigroup.Max where
1656+ liftParseJSON p _ a = Semigroup.Max <$> p a
16101657 {-# INLINE liftParseJSON #-}
16111658
1612−instance FromJSON a => FromJSON (Dual a) where
1659+ liftParseJSONList _ p a = fmap Semigroup.Max <$> p a
1660+ {-# INLINE liftParseJSONList #-}
1661+
1662+instance (FromJSON a) => FromJSON (Semigroup.Max a) where
1663+ parseJSON = parseJSON1
1664+ {-# INLINE parseJSON #-}
1665+
1666+ parseJSONList = liftParseJSONList parseJSON parseJSONList
1667+ {-# INLINE parseJSONList #-}
1668+
1669+
1670+instance FromJSON1 Semigroup.First where
1671+ liftParseJSON p _ a = Semigroup.First <$> p a
1672+ {-# INLINE liftParseJSON #-}
1673+
1674+ liftParseJSONList _ p a = fmap Semigroup.First <$> p a
1675+ {-# INLINE liftParseJSONList #-}
1676+
1677+instance (FromJSON a) => FromJSON (Semigroup.First a) where
1678+ parseJSON = parseJSON1
1679+ {-# INLINE parseJSON #-}
1680+
1681+ parseJSONList = liftParseJSONList parseJSON parseJSONList
1682+ {-# INLINE parseJSONList #-}
1683+
1684+
1685+instance FromJSON1 Semigroup.Last where
1686+ liftParseJSON p _ a = Semigroup.Last <$> p a
1687+ {-# INLINE liftParseJSON #-}
1688+
1689+ liftParseJSONList _ p a = fmap Semigroup.Last <$> p a
1690+ {-# INLINE liftParseJSONList #-}
1691+
1692+instance (FromJSON a) => FromJSON (Semigroup.Last a) where
16131693 parseJSON = parseJSON1
16141694 {-# INLINE parseJSON #-}
16151695
1696+ parseJSONList = liftParseJSONList parseJSON parseJSONList
1697+ {-# INLINE parseJSONList #-}
16161698
1617−instance FromJSON1 First where
1618− liftParseJSON p p' = fmap First . liftParseJSON p p'
1699+
1700+instance FromJSON1 Semigroup.WrappedMonoid where
1701+ liftParseJSON p _ a = Semigroup.WrapMonoid <$> p a
16191702 {-# INLINE liftParseJSON #-}
16201703
1621−instance FromJSON a => FromJSON (First a) where
1704+ liftParseJSONList _ p a = fmap Semigroup.WrapMonoid <$> p a
1705+ {-# INLINE liftParseJSONList #-}
1706+
1707+instance (FromJSON a) => FromJSON (Semigroup.WrappedMonoid a) where
16221708 parseJSON = parseJSON1
16231709 {-# INLINE parseJSON #-}
16241710
1711+ parseJSONList = liftParseJSONList parseJSON parseJSONList
1712+ {-# INLINE parseJSONList #-}
1713+
16251714
1626−instance FromJSON1 Last where
1627− liftParseJSON p p' = fmap Last . liftParseJSON p p'
1715+instance FromJSON1 Semigroup.Option where
1716+ liftParseJSON p p' = fmap Semigroup.Option . liftParseJSON p p'
16281717 {-# INLINE liftParseJSON #-}
16291718
1630−instance FromJSON a => FromJSON (Last a) where
1719+instance FromJSON a => FromJSON (Semigroup.Option a) where
16311720 parseJSON = parseJSON1
16321721 {-# INLINE parseJSON #-}
16331722