Skip to content

Commit e1ba32f

Browse files
committed
Allow dlist-1.0, add DNonEmpty instances
Note: DNonEmpty module is available only with GHC >= 8.0
1 parent c6498c9 commit e1ba32f

File tree

7 files changed

+46
-17
lines changed

7 files changed

+46
-17
lines changed

.travis.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ install:
120120
- if [ $HCNUMVER -ge 80200 ] ; then echo 'package aeson-examples' >> cabal.project ; fi
121121
- "if [ $HCNUMVER -ge 80200 ] ; then echo ' ghc-options: -Werror=missing-methods' >> cabal.project ; fi"
122122
- |
123-
echo "packages:" >> cabal.project
124-
echo " https://hackage.haskell.org/package/quickcheck-instances-0.3.24/candidate/quickcheck-instances-0.3.24.tar.gz" >> cabal.project
125-
echo "" >> cabal.project
126-
echo "packages:" >> cabal.project
127-
echo " https://hackage.haskell.org/package/strict-0.4/candidate/strict-0.4.tar.gz" >> cabal.project
128123
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(aeson|aeson-examples|attoparsec-iso8601)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
129124
- cat cabal.project || true
130125
- cat cabal.project.local || true
@@ -162,11 +157,6 @@ script:
162157
- if [ $HCNUMVER -ge 80200 ] ; then echo 'package aeson-examples' >> cabal.project ; fi
163158
- "if [ $HCNUMVER -ge 80200 ] ; then echo ' ghc-options: -Werror=missing-methods' >> cabal.project ; fi"
164159
- |
165-
echo "packages:" >> cabal.project
166-
echo " https://hackage.haskell.org/package/quickcheck-instances-0.3.24/candidate/quickcheck-instances-0.3.24.tar.gz" >> cabal.project
167-
echo "" >> cabal.project
168-
echo "packages:" >> cabal.project
169-
echo " https://hackage.haskell.org/package/strict-0.4/candidate/strict-0.4.tar.gz" >> cabal.project
170160
- "for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/-[^-]*$//' | (grep -vE -- '^(aeson|aeson-examples|attoparsec-iso8601)$' || true) | sed 's/^/constraints: /' | sed 's/$/ installed/' >> cabal.project.local; done"
171161
- cat cabal.project || true
172162
- cat cabal.project.local || true

Data/Aeson/Types/FromJSON.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ import qualified Data.Aeson.Parser.Time as Time
123123
import qualified Data.Attoparsec.ByteString.Char8 as A (endOfInput, parseOnly, scientific)
124124
import qualified Data.ByteString.Lazy as L
125125
import qualified Data.DList as DList
126+
#if MIN_VERSION_dlist(1,0,0) && __GLASGOW_HASKELL__ >=800
127+
import qualified Data.DList.DNonEmpty as DNE
128+
#endif
126129
import qualified Data.Fix as F
127130
import qualified Data.HashMap.Strict as H
128131
import qualified Data.HashSet as HashSet
@@ -1755,8 +1758,24 @@ instance (FromJSON a) => FromJSON (DList.DList a) where
17551758
parseJSON = parseJSON1
17561759
{-# INLINE parseJSON #-}
17571760

1761+
#if MIN_VERSION_dlist(1,0,0) && __GLASGOW_HASKELL__ >=800
1762+
-- | @since 1.5.3.0
1763+
instance FromJSON1 DNE.DNonEmpty where
1764+
liftParseJSON p _ = withArray "DNonEmpty" $
1765+
(>>= ne) . Tr.sequence . zipWith (parseIndexedJSON p) [0..] . V.toList
1766+
where
1767+
ne [] = fail "parsing DNonEmpty failed, unexpected empty list"
1768+
ne (x:xs) = pure (DNE.fromNonEmpty (x :| xs))
1769+
{-# INLINE liftParseJSON #-}
1770+
1771+
-- | @since 1.5.3.0
1772+
instance (FromJSON a) => FromJSON (DNE.DNonEmpty a) where
1773+
parseJSON = parseJSON1
1774+
{-# INLINE parseJSON #-}
1775+
#endif
1776+
17581777
-------------------------------------------------------------------------------
1759-
-- tranformers - Functors
1778+
-- transformers - Functors
17601779
-------------------------------------------------------------------------------
17611780

17621781
instance FromJSON1 Identity where

Data/Aeson/Types/ToJSON.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ import qualified Data.Aeson.Encoding as E
103103
import qualified Data.Aeson.Encoding.Internal as E (InArray, comma, econcat, retagEncoding)
104104
import qualified Data.ByteString.Lazy as L
105105
import qualified Data.DList as DList
106+
#if MIN_VERSION_dlist(1,0,0) && __GLASGOW_HASKELL__ >=800
107+
import qualified Data.DList.DNonEmpty as DNE
108+
#endif
106109
import qualified Data.Fix as F
107110
import qualified Data.HashMap.Strict as H
108111
import qualified Data.HashSet as HashSet
@@ -1614,6 +1617,24 @@ instance (ToJSON a) => ToJSON (DList.DList a) where
16141617
toEncoding = toEncoding1
16151618
{-# INLINE toEncoding #-}
16161619

1620+
#if MIN_VERSION_dlist(1,0,0) && __GLASGOW_HASKELL__ >=800
1621+
-- | @since 1.5.3.0
1622+
instance ToJSON1 DNE.DNonEmpty where
1623+
liftToJSON t _ = listValue t . DNE.toList
1624+
{-# INLINE liftToJSON #-}
1625+
1626+
liftToEncoding t _ = listEncoding t . DNE.toList
1627+
{-# INLINE liftToEncoding #-}
1628+
1629+
-- | @since 1.5.3.0
1630+
instance (ToJSON a) => ToJSON (DNE.DNonEmpty a) where
1631+
toJSON = toJSON1
1632+
{-# INLINE toJSON #-}
1633+
1634+
toEncoding = toEncoding1
1635+
{-# INLINE toEncoding #-}
1636+
#endif
1637+
16171638
-------------------------------------------------------------------------------
16181639
-- transformers - Functors
16191640
-------------------------------------------------------------------------------

aeson.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ library
137137
build-depends:
138138
attoparsec >= 0.13.2.2 && < 0.14,
139139
data-fix >= 0.3 && < 0.4,
140-
dlist >= 0.8.0.4 && < 0.9,
140+
dlist >= 0.8.0.4 && < 1.1,
141141
hashable >= 1.2.7.0 && < 1.4,
142142
primitive >= 0.7.0.1 && < 0.8,
143143
scientific >= 0.3.6.2 && < 0.4,

benchmarks/aeson-benchmarks.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ library
99
c-sources: ../cbits/unescape_string.c
1010
build-depends:
1111
attoparsec
12+
, data-fix
1213
, base
1314
, base-compat-batteries
1415
, bytestring >=0.10.4
@@ -21,6 +22,7 @@ library
2122
, primitive
2223
, scientific
2324
, syb
25+
, strict
2426
, tagged
2527
, template-haskell
2628
, text

cabal.bench.project

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ packages: benchmarks/
33
packages: criterion-compare-txt/
44
tests: false
55

6-
packages: https://oleg.fi/these-1.1.tar.gz
7-
packages: https://oleg.fi/quickcheck-instances-0.3.23.tar.gz
6+
packages: https://hackage.haskell.org/package/quickcheck-instances-0.3.24/candidate/quickcheck-instances-0.3.24.tar.gz
7+
packages: https://hackage.haskell.org/package/strict-0.4/candidate/strict-0.4.tar.gz

cabal.project

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ packages: .
33
packages: attoparsec-iso8601
44
packages: examples
55
tests: true
6-
7-
packages: https://hackage.haskell.org/package/quickcheck-instances-0.3.24/candidate/quickcheck-instances-0.3.24.tar.gz
8-
packages: https://hackage.haskell.org/package/strict-0.4/candidate/strict-0.4.tar.gz

0 commit comments

Comments
 (0)