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