@@ -10,16 +10,14 @@
10-- Portability: portable
10-- Portability: portable
12-- Tuple instances
12-- Tuple instances
13−module Data.Aeson.Types.Instances.Tuple (tuple, (>*<)) where
13+module Data.Aeson.Types.Instances.Tuple () where
15−import Data.Aeson.Encode.Functions (builder)
15+import Data.Aeson.Encoding.Internal (tuple, (>*<))
16import Data.Aeson.Types.Class
16import Data.Aeson.Types.Class
17import Data.Aeson.Types.Internal
17import Data.Aeson.Types.Internal
18−import Data.Monoid ((<>))
20import qualified Data.Vector as V
19import qualified Data.Vector as V
21import qualified Data.Vector.Mutable as VM (unsafeNew, unsafeWrite)
20import qualified Data.Vector.Mutable as VM (unsafeNew, unsafeWrite)
22−import qualified Data.ByteString.Builder as B
24#if MIN_VERSION_base(4,8,0)
22#if MIN_VERSION_base(4,8,0)
@@ -29,15 +27,6 @@ import Control.Applicative ((<$>), (<*>))
29parseJSONElemAtIndex :: (Value -> Parser a) -> Int -> V.Vector Value -> Parser a
27parseJSONElemAtIndex :: (Value -> Parser a) -> Int -> V.Vector Value -> Parser a
30parseJSONElemAtIndex p idx ary = p (V.unsafeIndex ary idx) <?> Index idx
28parseJSONElemAtIndex p idx ary = p (V.unsafeIndex ary idx) <?> Index idx
32−(>*<) :: B.Builder -> B.Builder -> B.Builder
33−a >*< b = a <> B.char7 ',' <> b
37−tuple :: B.Builder -> Encoding
38−tuple b = Encoding (B.char7 '[' <> b <> B.char7 ']')
41-- Local copy of withArray
30-- Local copy of withArray
42withArray :: String -> (Array -> Parser a) -> Value -> Parser a
31withArray :: String -> (Array -> Parser a) -> Value -> Parser a
43withArray _ f (Array arr) = f arr
32withArray _ f (Array arr) = f arr
@@ -57,8 +46,8 @@ instance ToJSON2 ((,) ) where
57 {-# INLINE liftToJSON2 #-}
46 {-# INLINE liftToJSON2 #-}
59 liftToEncoding2 toA _ toB _ (a, b) = tuple $
48 liftToEncoding2 toA _ toB _ (a, b) = tuple $
60− fromEncoding (toA a) >*<
49+ toA a >*<
61− fromEncoding (toB b)
50+ toB b
62 {-# INLINE liftToEncoding2 #-}
51 {-# INLINE liftToEncoding2 #-}
64instance (ToJSON a) => ToJSON1 ((,) a) where
53instance (ToJSON a) => ToJSON1 ((,) a) where
@@ -102,9 +91,9 @@ instance (ToJSON a) => ToJSON2 ((,,) a) where
102 {-# INLINE liftToJSON2 #-}
91 {-# INLINE liftToJSON2 #-}
104 liftToEncoding2 toB _ toC _ (a, b, c) = tuple $
93 liftToEncoding2 toB _ toC _ (a, b, c) = tuple $
105− builder a >*<
94+ toEncoding a >*<
106− fromEncoding (toB b) >*<
95+ toB b >*<
107− fromEncoding (toC c)
96+ toC c
108 {-# INLINE liftToEncoding2 #-}
97 {-# INLINE liftToEncoding2 #-}
110instance (ToJSON a, ToJSON b) => ToJSON1 ((,,) a b) where
99instance (ToJSON a, ToJSON b) => ToJSON1 ((,,) a b) where
@@ -150,10 +139,10 @@ instance (ToJSON a, ToJSON b) => ToJSON2 ((,,,) a b) where
150 {-# INLINE liftToJSON2 #-}
139 {-# INLINE liftToJSON2 #-}
152 liftToEncoding2 toC _ toD _ (a, b, c, d) = tuple $
141 liftToEncoding2 toC _ toD _ (a, b, c, d) = tuple $
153− builder a >*<
142+ toEncoding a >*<
154− builder b >*<
143+ toEncoding b >*<
155− fromEncoding (toC c) >*<
144+ toC c >*<
156− fromEncoding (toD d)
145+ toD d
157 {-# INLINE liftToEncoding2 #-}
146 {-# INLINE liftToEncoding2 #-}
159instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON1 ((,,,) a b c) where
148instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON1 ((,,,) a b c) where
@@ -201,11 +190,11 @@ instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON2 ((,,,,) a b c) where
201 {-# INLINE liftToJSON2 #-}
190 {-# INLINE liftToJSON2 #-}
203 liftToEncoding2 toD _ toE _ (a, b, c, d, e) = tuple $
192 liftToEncoding2 toD _ toE _ (a, b, c, d, e) = tuple $
204− builder a >*<
193+ toEncoding a >*<
205− builder b >*<
194+ toEncoding b >*<
206− builder c >*<
195+ toEncoding c >*<
207− fromEncoding (toD d) >*<
196+ toD d >*<
208− fromEncoding (toE e)
197+ toE e
209 {-# INLINE liftToEncoding2 #-}
198 {-# INLINE liftToEncoding2 #-}
211instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON1 ((,,,,) a b c d) where
200instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON1 ((,,,,) a b c d) where
@@ -255,12 +244,12 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON2 ((,,,,,) a b c d) w
255 {-# INLINE liftToJSON2 #-}
244 {-# INLINE liftToJSON2 #-}
257 liftToEncoding2 toE _ toF _ (a, b, c, d, e, f) = tuple $
246 liftToEncoding2 toE _ toF _ (a, b, c, d, e, f) = tuple $
258− builder a >*<
247+ toEncoding a >*<
259− builder b >*<
248+ toEncoding b >*<
260− builder c >*<
249+ toEncoding c >*<
261− builder d >*<
250+ toEncoding d >*<
262− fromEncoding (toE e) >*<
251+ toE e >*<
263− fromEncoding (toF f)
252+ toF f
264 {-# INLINE liftToEncoding2 #-}
253 {-# INLINE liftToEncoding2 #-}
266instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON1 ((,,,,,) a b c d e) where
255instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON1 ((,,,,,) a b c d e) where
@@ -312,13 +301,13 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON2 ((,,,,,,)
312 {-# INLINE liftToJSON2 #-}
301 {-# INLINE liftToJSON2 #-}
314 liftToEncoding2 toF _ toG _ (a, b, c, d, e, f, g) = tuple $
303 liftToEncoding2 toF _ toG _ (a, b, c, d, e, f, g) = tuple $
315− builder a >*<
304+ toEncoding a >*<
316− builder b >*<
305+ toEncoding b >*<
317− builder c >*<
306+ toEncoding c >*<
318− builder d >*<
307+ toEncoding d >*<
319− builder e >*<
308+ toEncoding e >*<
320− fromEncoding (toF f) >*<
309+ toF f >*<
321− fromEncoding (toG g)
310+ toG g
322 {-# INLINE liftToEncoding2 #-}
311 {-# INLINE liftToEncoding2 #-}
324instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON1 ((,,,,,,) a b c d e f) where
313instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON1 ((,,,,,,) a b c d e f) where
@@ -372,14 +361,14 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON2
372 {-# INLINE liftToJSON2 #-}
361 {-# INLINE liftToJSON2 #-}
374 liftToEncoding2 toG _ toH _ (a, b, c, d, e, f, g, h) = tuple $
363 liftToEncoding2 toG _ toH _ (a, b, c, d, e, f, g, h) = tuple $
375− builder a >*<
364+ toEncoding a >*<
376− builder b >*<
365+ toEncoding b >*<
377− builder c >*<
366+ toEncoding c >*<
378− builder d >*<
367+ toEncoding d >*<
379− builder e >*<
368+ toEncoding e >*<
380− builder f >*<
369+ toEncoding f >*<
381− fromEncoding (toG g) >*<
370+ toG g >*<
382− fromEncoding (toH h)
371+ toH h
383 {-# INLINE liftToEncoding2 #-}
372 {-# INLINE liftToEncoding2 #-}
385instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON1 ((,,,,,,,) a b c d e f g) where
374instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON1 ((,,,,,,,) a b c d e f g) where
@@ -435,15 +424,15 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g)
435 {-# INLINE liftToJSON2 #-}
424 {-# INLINE liftToJSON2 #-}
437 liftToEncoding2 toH _ toI _ (a, b, c, d, e, f, g, h, i) = tuple $
426 liftToEncoding2 toH _ toI _ (a, b, c, d, e, f, g, h, i) = tuple $
438− builder a >*<
427+ toEncoding a >*<
439− builder b >*<
428+ toEncoding b >*<
440− builder c >*<
429+ toEncoding c >*<
441− builder d >*<
430+ toEncoding d >*<
442− builder e >*<
431+ toEncoding e >*<
443− builder f >*<
432+ toEncoding f >*<
444− builder g >*<
433+ toEncoding g >*<
445− fromEncoding (toH h) >*<
434+ toH h >*<
446− fromEncoding (toI i)
435+ toI i
447 {-# INLINE liftToEncoding2 #-}
436 {-# INLINE liftToEncoding2 #-}
449instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON1 ((,,,,,,,,) a b c d e f g h) where
438instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON1 ((,,,,,,,,) a b c d e f g h) where
@@ -501,16 +490,16 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
501 {-# INLINE liftToJSON2 #-}
490 {-# INLINE liftToJSON2 #-}
503 liftToEncoding2 toI _ toJ _ (a, b, c, d, e, f, g, h, i, j) = tuple $
492 liftToEncoding2 toI _ toJ _ (a, b, c, d, e, f, g, h, i, j) = tuple $
504− builder a >*<
493+ toEncoding a >*<
505− builder b >*<
494+ toEncoding b >*<
506− builder c >*<
495+ toEncoding c >*<
507− builder d >*<
496+ toEncoding d >*<
508− builder e >*<
497+ toEncoding e >*<
509− builder f >*<
498+ toEncoding f >*<
510− builder g >*<
499+ toEncoding g >*<
511− builder h >*<
500+ toEncoding h >*<
512− fromEncoding (toI i) >*<
501+ toI i >*<
513− fromEncoding (toJ j)
502+ toJ j
514 {-# INLINE liftToEncoding2 #-}
503 {-# INLINE liftToEncoding2 #-}
516instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON1 ((,,,,,,,,,) a b c d e f g h i) where
505instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON1 ((,,,,,,,,,) a b c d e f g h i) where
@@ -570,17 +559,17 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
570 {-# INLINE liftToJSON2 #-}
559 {-# INLINE liftToJSON2 #-}
572 liftToEncoding2 toJ _ toK _ (a, b, c, d, e, f, g, h, i, j, k) = tuple $
561 liftToEncoding2 toJ _ toK _ (a, b, c, d, e, f, g, h, i, j, k) = tuple $
573− builder a >*<
562+ toEncoding a >*<
574− builder b >*<
563+ toEncoding b >*<
575− builder c >*<
564+ toEncoding c >*<
576− builder d >*<
565+ toEncoding d >*<
577− builder e >*<
566+ toEncoding e >*<
578− builder f >*<
567+ toEncoding f >*<
579− builder g >*<
568+ toEncoding g >*<
580− builder h >*<
569+ toEncoding h >*<
581− builder i >*<
570+ toEncoding i >*<
582− fromEncoding (toJ j) >*<
571+ toJ j >*<
583− fromEncoding (toK k)
572+ toK k
584 {-# INLINE liftToEncoding2 #-}
573 {-# INLINE liftToEncoding2 #-}
586instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON1 ((,,,,,,,,,,) a b c d e f g h i j) where
575instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON1 ((,,,,,,,,,,) a b c d e f g h i j) where
@@ -642,18 +631,18 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
642 {-# INLINE liftToJSON2 #-}
631 {-# INLINE liftToJSON2 #-}
644 liftToEncoding2 toK _ toL _ (a, b, c, d, e, f, g, h, i, j, k, l) = tuple $
633 liftToEncoding2 toK _ toL _ (a, b, c, d, e, f, g, h, i, j, k, l) = tuple $
645− builder a >*<
634+ toEncoding a >*<
646− builder b >*<
635+ toEncoding b >*<
647− builder c >*<
636+ toEncoding c >*<
648− builder d >*<
637+ toEncoding d >*<
649− builder e >*<
638+ toEncoding e >*<
650− builder f >*<
639+ toEncoding f >*<
651− builder g >*<
640+ toEncoding g >*<
652− builder h >*<
641+ toEncoding h >*<
653− builder i >*<
642+ toEncoding i >*<
654− builder j >*<
643+ toEncoding j >*<
655− fromEncoding (toK k) >*<
644+ toK k >*<
656− fromEncoding (toL l)
645+ toL l
657 {-# INLINE liftToEncoding2 #-}
646 {-# INLINE liftToEncoding2 #-}
659instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON1 ((,,,,,,,,,,,) a b c d e f g h i j k) where
648instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON1 ((,,,,,,,,,,,) a b c d e f g h i j k) where
@@ -717,19 +706,19 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
717 {-# INLINE liftToJSON2 #-}
706 {-# INLINE liftToJSON2 #-}
719 liftToEncoding2 toL _ toM _ (a, b, c, d, e, f, g, h, i, j, k, l, m) = tuple $
708 liftToEncoding2 toL _ toM _ (a, b, c, d, e, f, g, h, i, j, k, l, m) = tuple $
720− builder a >*<
709+ toEncoding a >*<
721− builder b >*<
710+ toEncoding b >*<
722− builder c >*<
711+ toEncoding c >*<
723− builder d >*<
712+ toEncoding d >*<
724− builder e >*<
713+ toEncoding e >*<
725− builder f >*<
714+ toEncoding f >*<
726− builder g >*<
715+ toEncoding g >*<
727− builder h >*<
716+ toEncoding h >*<
728− builder i >*<
717+ toEncoding i >*<
729− builder j >*<
718+ toEncoding j >*<
730− builder k >*<
719+ toEncoding k >*<
731− fromEncoding (toL l) >*<
720+ toL l >*<
732− fromEncoding (toM m)
721+ toM m
733 {-# INLINE liftToEncoding2 #-}
722 {-# INLINE liftToEncoding2 #-}
735instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) where
724instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) where
@@ -795,20 +784,20 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
795 {-# INLINE liftToJSON2 #-}
784 {-# INLINE liftToJSON2 #-}
797 liftToEncoding2 toM _ toN _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n) = tuple $
786 liftToEncoding2 toM _ toN _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n) = tuple $
798− builder a >*<
787+ toEncoding a >*<
799− builder b >*<
788+ toEncoding b >*<
800− builder c >*<
789+ toEncoding c >*<
801− builder d >*<
790+ toEncoding d >*<
802− builder e >*<
791+ toEncoding e >*<
803− builder f >*<
792+ toEncoding f >*<
804− builder g >*<
793+ toEncoding g >*<
805− builder h >*<
794+ toEncoding h >*<
806− builder i >*<
795+ toEncoding i >*<
807− builder j >*<
796+ toEncoding j >*<
808− builder k >*<
797+ toEncoding k >*<
809− builder l >*<
798+ toEncoding l >*<
810− fromEncoding (toM m) >*<
799+ toM m >*<
811− fromEncoding (toN n)
800+ toN n
812 {-# INLINE liftToEncoding2 #-}
801 {-# INLINE liftToEncoding2 #-}
814instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) where
803instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) where
@@ -876,21 +865,21 @@ instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g,
876 {-# INLINE liftToJSON2 #-}
865 {-# INLINE liftToJSON2 #-}
878 liftToEncoding2 toN _ toO _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) = tuple $
867 liftToEncoding2 toN _ toO _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) = tuple $
879− builder a >*<
868+ toEncoding a >*<
880− builder b >*<
869+ toEncoding b >*<
881− builder c >*<
870+ toEncoding c >*<
882− builder d >*<
871+ toEncoding d >*<
883− builder e >*<
872+ toEncoding e >*<
884− builder f >*<
873+ toEncoding f >*<
885− builder g >*<
874+ toEncoding g >*<
886− builder h >*<
875+ toEncoding h >*<
887− builder i >*<
876+ toEncoding i >*<
888− builder j >*<
877+ toEncoding j >*<
889− builder k >*<
878+ toEncoding k >*<
890− builder l >*<
879+ toEncoding l >*<
891− builder m >*<
880+ toEncoding m >*<
892− fromEncoding (toN n) >*<
881+ toN n >*<
893− fromEncoding (toO o)
882+ toO o
894 {-# INLINE liftToEncoding2 #-}
883 {-# INLINE liftToEncoding2 #-}
896instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n) => ToJSON1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) where
885instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n) => ToJSON1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) where
@@ -935,5 +924,3 @@ instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f
935instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m, FromJSON n, FromJSON o) => FromJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where
924instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m, FromJSON n, FromJSON o) => FromJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where
936 parseJSON = parseJSON2
925 parseJSON = parseJSON2
937 {-# INLINE parseJSON #-}
926 {-# INLINE parseJSON #-}