on master help sign in
Unary and Binary tuple instances
commit48e61c1abab0df67a15215eff215f5bec49ff9df authorOleg Grenrus <oleg.grenrus@iki.fi> dateTue 29 Mar 2016, 12:00 (11 years ago) parent81f4e35
4 files changed+1073−663
Data/Aeson/Types/Instances.hs+9−663 Data/Aeson/Types/Instances/Tuple.hs+937 aeson.cabal+1 tuple-instances.hs+126
Data/Aeson/Types/Instances.hs+9−663
@@ -76,6 +76,8 @@ module Data.Aeson.Types.Instances
7676 , typeMismatch
7777 ) where
7878
79+import Data.Aeson.Types.Instances.Tuple (tuple, (>*<))
80+
7981import Control.Applicative (Const(..))
8082import Data.Aeson.Encode.Functions (brackets, builder, encode, foldable, foldable', list')
8183import Data.Aeson.Functions (hashMapKey, mapHashKeyVal, mapKey, mapKeyVal)
@@ -129,10 +131,10 @@ import qualified Data.Text.Lazy.Builder.Int as LTBI
129131import qualified Data.Tree as Tree
130132import qualified Data.Vector as V
131133import qualified Data.Vector.Generic as VG
132−import qualified Data.Vector.Mutable as VM (unsafeNew, unsafeWrite)
133134import qualified Data.Vector.Primitive as VP
134135import qualified Data.Vector.Storable as VS
135136import qualified Data.Vector.Unboxed as VU
137+import qualified Data.Vector.Mutable as VM
136138
137139import Unsafe.Coerce (unsafeCoerce)
138140
@@ -953,6 +955,12 @@ stringEncoding :: (ToJSON a) => a -> Value
953955stringEncoding = String . T.dropAround (== '"') . T.decodeLatin1 . L.toStrict . encode
954956{-# INLINE stringEncoding #-}
955957
958+parseJSONElemAtIndex :: FromJSON a => Int -> Vector Value -> Parser a
959+parseJSONElemAtIndex = parseJSONElemAtIndex' parseJSON
960+
961+parseJSONElemAtIndex' :: (Value -> Parser a) -> Int -> Vector Value -> Parser a
962+parseJSONElemAtIndex' p idx ary = p (V.unsafeIndex ary idx) <?> Index idx
963+
956964instance FromJSON UTCTime where
957965 parseJSON = withText "UTCTime" (Time.run Time.utcTime)
958966
@@ -971,668 +979,6 @@ instance FromJSON NominalDiffTime where
971979 parseJSON = withScientific "NominalDiffTime" $ pure . realToFrac
972980 {-# INLINE parseJSON #-}
973981
974−parseJSONElemAtIndex :: FromJSON a => Int -> Vector Value -> Parser a
975−parseJSONElemAtIndex = parseJSONElemAtIndex' parseJSON
976−
977−parseJSONElemAtIndex' :: (Value -> Parser a) -> Int -> Vector Value -> Parser a
978−parseJSONElemAtIndex' p idx ary = p (V.unsafeIndex ary idx) <?> Index idx
979−
980−tuple :: B.Builder -> Encoding
981−tuple b = Encoding (B.char7 '[' <> b <> B.char7 ']')
982−{-# INLINE tuple #-}
983−
984−(>*<) :: B.Builder -> B.Builder -> B.Builder
985−a >*< b = a <> B.char7 ',' <> b
986−{-# INLINE (>*<) #-}
987−infixr 6 >*<
988−
989−instance (ToJSON a, ToJSON b) => ToJSON (a,b) where
990− toJSON (a,b) = Array $ V.create $ do
991− mv <- VM.unsafeNew 2
992− VM.unsafeWrite mv 0 (toJSON a)
993− VM.unsafeWrite mv 1 (toJSON b)
994− return mv
995− {-# INLINE toJSON #-}
996−
997− toEncoding (a,b) = tuple $
998− builder a >*< builder b
999− {-# INLINE toEncoding #-}
1000−
1001−instance (FromJSON a, FromJSON b) => FromJSON (a,b) where
1002− parseJSON = withArray "(a,b)" $ \ab ->
1003− let n = V.length ab
1004− in if n == 2
1005− then (,) <$> parseJSONElemAtIndex 0 ab
1006− <*> parseJSONElemAtIndex 1 ab
1007− else fail $ "cannot unpack array of length " ++
1008− show n ++ " into a pair"
1009− {-# INLINE parseJSON #-}
1010−
1011−instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON (a,b,c) where
1012− toJSON (a,b,c) = Array $ V.create $ do
1013− mv <- VM.unsafeNew 3
1014− VM.unsafeWrite mv 0 (toJSON a)
1015− VM.unsafeWrite mv 1 (toJSON b)
1016− VM.unsafeWrite mv 2 (toJSON c)
1017− return mv
1018− {-# INLINE toJSON #-}
1019−
1020− toEncoding (a,b,c) = tuple $
1021− builder a >*<
1022− builder b >*<
1023− builder c
1024− {-# INLINE toEncoding #-}
1025−
1026−instance (FromJSON a, FromJSON b, FromJSON c) => FromJSON (a,b,c) where
1027− parseJSON = withArray "(a,b,c)" $ \abc ->
1028− let n = V.length abc
1029− in if n == 3
1030− then (,,) <$> parseJSONElemAtIndex 0 abc
1031− <*> parseJSONElemAtIndex 1 abc
1032− <*> parseJSONElemAtIndex 2 abc
1033− else fail $ "cannot unpack array of length " ++
1034− show n ++ " into a 3-tuple"
1035− {-# INLINE parseJSON #-}
1036−
1037−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON (a,b,c,d) where
1038− toJSON (a,b,c,d) = Array $ V.create $ do
1039− mv <- VM.unsafeNew 4
1040− VM.unsafeWrite mv 0 (toJSON a)
1041− VM.unsafeWrite mv 1 (toJSON b)
1042− VM.unsafeWrite mv 2 (toJSON c)
1043− VM.unsafeWrite mv 3 (toJSON d)
1044− return mv
1045− {-# INLINE toJSON #-}
1046−
1047− toEncoding (a,b,c,d) = tuple $
1048− builder a >*<
1049− builder b >*<
1050− builder c >*<
1051− builder d
1052− {-# INLINE toEncoding #-}
1053−
1054−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d) =>
1055− FromJSON (a,b,c,d) where
1056− parseJSON = withArray "(a,b,c,d)" $ \abcd ->
1057− let n = V.length abcd
1058− in if n == 4
1059− then (,,,) <$> parseJSONElemAtIndex 0 abcd
1060− <*> parseJSONElemAtIndex 1 abcd
1061− <*> parseJSONElemAtIndex 2 abcd
1062− <*> parseJSONElemAtIndex 3 abcd
1063− else fail $ "cannot unpack array of length " ++
1064− show n ++ " into a 4-tuple"
1065− {-# INLINE parseJSON #-}
1066−
1067−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) =>
1068− ToJSON (a,b,c,d,e) where
1069− toJSON (a,b,c,d,e) = Array $ V.create $ do
1070− mv <- VM.unsafeNew 5
1071− VM.unsafeWrite mv 0 (toJSON a)
1072− VM.unsafeWrite mv 1 (toJSON b)
1073− VM.unsafeWrite mv 2 (toJSON c)
1074− VM.unsafeWrite mv 3 (toJSON d)
1075− VM.unsafeWrite mv 4 (toJSON e)
1076− return mv
1077− {-# INLINE toJSON #-}
1078−
1079− toEncoding (a,b,c,d,e) = tuple $
1080− builder a >*<
1081− builder b >*<
1082− builder c >*<
1083− builder d >*<
1084− builder e
1085− {-# INLINE toEncoding #-}
1086−
1087−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e) =>
1088− FromJSON (a,b,c,d,e) where
1089− parseJSON = withArray "(a,b,c,d,e)" $ \abcde ->
1090− let n = V.length abcde
1091− in if n == 5
1092− then (,,,,) <$> parseJSONElemAtIndex 0 abcde
1093− <*> parseJSONElemAtIndex 1 abcde
1094− <*> parseJSONElemAtIndex 2 abcde
1095− <*> parseJSONElemAtIndex 3 abcde
1096− <*> parseJSONElemAtIndex 4 abcde
1097− else fail $ "cannot unpack array of length " ++
1098− show n ++ " into a 5-tuple"
1099− {-# INLINE parseJSON #-}
1100−
1101−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) =>
1102− ToJSON (a,b,c,d,e,f) where
1103− toJSON (a,b,c,d,e,f) = Array $ V.create $ do
1104− mv <- VM.unsafeNew 6
1105− VM.unsafeWrite mv 0 (toJSON a)
1106− VM.unsafeWrite mv 1 (toJSON b)
1107− VM.unsafeWrite mv 2 (toJSON c)
1108− VM.unsafeWrite mv 3 (toJSON d)
1109− VM.unsafeWrite mv 4 (toJSON e)
1110− VM.unsafeWrite mv 5 (toJSON f)
1111− return mv
1112− {-# INLINE toJSON #-}
1113−
1114− toEncoding (a,b,c,d,e,f) = tuple $
1115− builder a >*<
1116− builder b >*<
1117− builder c >*<
1118− builder d >*<
1119− builder e >*<
1120− builder f
1121− {-# INLINE toEncoding #-}
1122−
1123−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1124− FromJSON f) => FromJSON (a,b,c,d,e,f) where
1125− parseJSON = withArray "(a,b,c,d,e,f)" $ \abcdef ->
1126− let n = V.length abcdef
1127− in if n == 6
1128− then (,,,,,) <$> parseJSONElemAtIndex 0 abcdef
1129− <*> parseJSONElemAtIndex 1 abcdef
1130− <*> parseJSONElemAtIndex 2 abcdef
1131− <*> parseJSONElemAtIndex 3 abcdef
1132− <*> parseJSONElemAtIndex 4 abcdef
1133− <*> parseJSONElemAtIndex 5 abcdef
1134− else fail $ "cannot unpack array of length " ++
1135− show n ++ " into a 6-tuple"
1136− {-# INLINE parseJSON #-}
1137−
1138−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f,
1139− ToJSON g) => ToJSON (a,b,c,d,e,f,g) where
1140− toJSON (a,b,c,d,e,f,g) = Array $ V.create $ do
1141− mv <- VM.unsafeNew 7
1142− VM.unsafeWrite mv 0 (toJSON a)
1143− VM.unsafeWrite mv 1 (toJSON b)
1144− VM.unsafeWrite mv 2 (toJSON c)
1145− VM.unsafeWrite mv 3 (toJSON d)
1146− VM.unsafeWrite mv 4 (toJSON e)
1147− VM.unsafeWrite mv 5 (toJSON f)
1148− VM.unsafeWrite mv 6 (toJSON g)
1149− return mv
1150− {-# INLINE toJSON #-}
1151−
1152− toEncoding (a,b,c,d,e,f,g) = tuple $
1153− builder a >*<
1154− builder b >*<
1155− builder c >*<
1156− builder d >*<
1157− builder e >*<
1158− builder f >*<
1159− builder g
1160− {-# INLINE toEncoding #-}
1161−
1162−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1163− FromJSON f, FromJSON g) => FromJSON (a,b,c,d,e,f,g) where
1164− parseJSON = withArray "(a,b,c,d,e,f,g)" $ \abcdefg ->
1165− let n = V.length abcdefg
1166− in if n == 7
1167− then (,,,,,,) <$> parseJSONElemAtIndex 0 abcdefg
1168− <*> parseJSONElemAtIndex 1 abcdefg
1169− <*> parseJSONElemAtIndex 2 abcdefg
1170− <*> parseJSONElemAtIndex 3 abcdefg
1171− <*> parseJSONElemAtIndex 4 abcdefg
1172− <*> parseJSONElemAtIndex 5 abcdefg
1173− <*> parseJSONElemAtIndex 6 abcdefg
1174− else fail $ "cannot unpack array of length " ++
1175− show n ++ " into a 7-tuple"
1176− {-# INLINE parseJSON #-}
1177−
1178−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f,
1179− ToJSON g, ToJSON h) => ToJSON (a,b,c,d,e,f,g,h) where
1180− toJSON (a,b,c,d,e,f,g,h) = Array $ V.create $ do
1181− mv <- VM.unsafeNew 8
1182− VM.unsafeWrite mv 0 (toJSON a)
1183− VM.unsafeWrite mv 1 (toJSON b)
1184− VM.unsafeWrite mv 2 (toJSON c)
1185− VM.unsafeWrite mv 3 (toJSON d)
1186− VM.unsafeWrite mv 4 (toJSON e)
1187− VM.unsafeWrite mv 5 (toJSON f)
1188− VM.unsafeWrite mv 6 (toJSON g)
1189− VM.unsafeWrite mv 7 (toJSON h)
1190− return mv
1191− {-# INLINE toJSON #-}
1192−
1193− toEncoding (a,b,c,d,e,f,g,h) = tuple $
1194− builder a >*<
1195− builder b >*<
1196− builder c >*<
1197− builder d >*<
1198− builder e >*<
1199− builder f >*<
1200− builder g >*<
1201− builder h
1202− {-# INLINE toEncoding #-}
1203−
1204−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1205− FromJSON f, FromJSON g, FromJSON h) =>
1206− FromJSON (a,b,c,d,e,f,g,h) where
1207− parseJSON = withArray "(a,b,c,d,e,f,g,h)" $ \ary ->
1208− let n = V.length ary
1209− in if n /= 8
1210− then fail $ "cannot unpack array of length " ++
1211− show n ++ " into an 8-tuple"
1212− else (,,,,,,,)
1213− <$> parseJSONElemAtIndex 0 ary
1214− <*> parseJSONElemAtIndex 1 ary
1215− <*> parseJSONElemAtIndex 2 ary
1216− <*> parseJSONElemAtIndex 3 ary
1217− <*> parseJSONElemAtIndex 4 ary
1218− <*> parseJSONElemAtIndex 5 ary
1219− <*> parseJSONElemAtIndex 6 ary
1220− <*> parseJSONElemAtIndex 7 ary
1221− {-# INLINE parseJSON #-}
1222−
1223−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f,
1224− ToJSON g, ToJSON h, ToJSON i) => ToJSON (a,b,c,d,e,f,g,h,i) where
1225− toJSON (a,b,c,d,e,f,g,h,i) = Array $ V.create $ do
1226− mv <- VM.unsafeNew 9
1227− VM.unsafeWrite mv 0 (toJSON a)
1228− VM.unsafeWrite mv 1 (toJSON b)
1229− VM.unsafeWrite mv 2 (toJSON c)
1230− VM.unsafeWrite mv 3 (toJSON d)
1231− VM.unsafeWrite mv 4 (toJSON e)
1232− VM.unsafeWrite mv 5 (toJSON f)
1233− VM.unsafeWrite mv 6 (toJSON g)
1234− VM.unsafeWrite mv 7 (toJSON h)
1235− VM.unsafeWrite mv 8 (toJSON i)
1236− return mv
1237− {-# INLINE toJSON #-}
1238−
1239− toEncoding (a,b,c,d,e,f,g,h,i) = tuple $
1240− builder a >*<
1241− builder b >*<
1242− builder c >*<
1243− builder d >*<
1244− builder e >*<
1245− builder f >*<
1246− builder g >*<
1247− builder h >*<
1248− builder i
1249− {-# INLINE toEncoding #-}
1250−
1251−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1252− FromJSON f, FromJSON g, FromJSON h, FromJSON i) =>
1253− FromJSON (a,b,c,d,e,f,g,h,i) where
1254− parseJSON = withArray "(a,b,c,d,e,f,g,h,i)" $ \ary ->
1255− let n = V.length ary
1256− in if n /= 9
1257− then fail $ "cannot unpack array of length " ++
1258− show n ++ " into a 9-tuple"
1259− else (,,,,,,,,)
1260− <$> parseJSONElemAtIndex 0 ary
1261− <*> parseJSONElemAtIndex 1 ary
1262− <*> parseJSONElemAtIndex 2 ary
1263− <*> parseJSONElemAtIndex 3 ary
1264− <*> parseJSONElemAtIndex 4 ary
1265− <*> parseJSONElemAtIndex 5 ary
1266− <*> parseJSONElemAtIndex 6 ary
1267− <*> parseJSONElemAtIndex 7 ary
1268− <*> parseJSONElemAtIndex 8 ary
1269− {-# INLINE parseJSON #-}
1270−
1271−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f,
1272− ToJSON g, ToJSON h, ToJSON i, ToJSON j) =>
1273− ToJSON (a,b,c,d,e,f,g,h,i,j) where
1274− toJSON (a,b,c,d,e,f,g,h,i,j) = Array $ V.create $ do
1275− mv <- VM.unsafeNew 10
1276− VM.unsafeWrite mv 0 (toJSON a)
1277− VM.unsafeWrite mv 1 (toJSON b)
1278− VM.unsafeWrite mv 2 (toJSON c)
1279− VM.unsafeWrite mv 3 (toJSON d)
1280− VM.unsafeWrite mv 4 (toJSON e)
1281− VM.unsafeWrite mv 5 (toJSON f)
1282− VM.unsafeWrite mv 6 (toJSON g)
1283− VM.unsafeWrite mv 7 (toJSON h)
1284− VM.unsafeWrite mv 8 (toJSON i)
1285− VM.unsafeWrite mv 9 (toJSON j)
1286− return mv
1287− {-# INLINE toJSON #-}
1288−
1289− toEncoding (a,b,c,d,e,f,g,h,i,j) = tuple $
1290− builder a >*<
1291− builder b >*<
1292− builder c >*<
1293− builder d >*<
1294− builder e >*<
1295− builder f >*<
1296− builder g >*<
1297− builder h >*<
1298− builder i >*<
1299− builder j
1300− {-# INLINE toEncoding #-}
1301−
1302−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1303− FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j) =>
1304− FromJSON (a,b,c,d,e,f,g,h,i,j) where
1305− parseJSON = withArray "(a,b,c,d,e,f,g,h,i,j)" $ \ary ->
1306− let n = V.length ary
1307− in if n /= 10
1308− then fail $ "cannot unpack array of length " ++
1309− show n ++ " into a 10-tuple"
1310− else (,,,,,,,,,)
1311− <$> parseJSONElemAtIndex 0 ary
1312− <*> parseJSONElemAtIndex 1 ary
1313− <*> parseJSONElemAtIndex 2 ary
1314− <*> parseJSONElemAtIndex 3 ary
1315− <*> parseJSONElemAtIndex 4 ary
1316− <*> parseJSONElemAtIndex 5 ary
1317− <*> parseJSONElemAtIndex 6 ary
1318− <*> parseJSONElemAtIndex 7 ary
1319− <*> parseJSONElemAtIndex 8 ary
1320− <*> parseJSONElemAtIndex 9 ary
1321− {-# INLINE parseJSON #-}
1322−
1323−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f,
1324− ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) =>
1325− ToJSON (a,b,c,d,e,f,g,h,i,j,k) where
1326− toJSON (a,b,c,d,e,f,g,h,i,j,k) = Array $ V.create $ do
1327− mv <- VM.unsafeNew 11
1328− VM.unsafeWrite mv 0 (toJSON a)
1329− VM.unsafeWrite mv 1 (toJSON b)
1330− VM.unsafeWrite mv 2 (toJSON c)
1331− VM.unsafeWrite mv 3 (toJSON d)
1332− VM.unsafeWrite mv 4 (toJSON e)
1333− VM.unsafeWrite mv 5 (toJSON f)
1334− VM.unsafeWrite mv 6 (toJSON g)
1335− VM.unsafeWrite mv 7 (toJSON h)
1336− VM.unsafeWrite mv 8 (toJSON i)
1337− VM.unsafeWrite mv 9 (toJSON j)
1338− VM.unsafeWrite mv 10 (toJSON k)
1339− return mv
1340− {-# INLINE toJSON #-}
1341−
1342− toEncoding (a,b,c,d,e,f,g,h,i,j,k) = tuple $
1343− builder a >*<
1344− builder b >*<
1345− builder c >*<
1346− builder d >*<
1347− builder e >*<
1348− builder f >*<
1349− builder g >*<
1350− builder h >*<
1351− builder i >*<
1352− builder j >*<
1353− builder k
1354− {-# INLINE toEncoding #-}
1355−
1356−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1357− FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j,
1358− FromJSON k) =>
1359− FromJSON (a,b,c,d,e,f,g,h,i,j,k) where
1360− parseJSON = withArray "(a,b,c,d,e,f,g,h,i,j,k)" $ \ary ->
1361− let n = V.length ary
1362− in if n /= 11
1363− then fail $ "cannot unpack array of length " ++
1364− show n ++ " into an 11-tuple"
1365− else (,,,,,,,,,,)
1366− <$> parseJSONElemAtIndex 0 ary
1367− <*> parseJSONElemAtIndex 1 ary
1368− <*> parseJSONElemAtIndex 2 ary
1369− <*> parseJSONElemAtIndex 3 ary
1370− <*> parseJSONElemAtIndex 4 ary
1371− <*> parseJSONElemAtIndex 5 ary
1372− <*> parseJSONElemAtIndex 6 ary
1373− <*> parseJSONElemAtIndex 7 ary
1374− <*> parseJSONElemAtIndex 8 ary
1375− <*> parseJSONElemAtIndex 9 ary
1376− <*> parseJSONElemAtIndex 10 ary
1377− {-# INLINE parseJSON #-}
1378−
1379−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f,
1380− ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) =>
1381− ToJSON (a,b,c,d,e,f,g,h,i,j,k,l) where
1382− toJSON (a,b,c,d,e,f,g,h,i,j,k,l) = Array $ V.create $ do
1383− mv <- VM.unsafeNew 12
1384− VM.unsafeWrite mv 0 (toJSON a)
1385− VM.unsafeWrite mv 1 (toJSON b)
1386− VM.unsafeWrite mv 2 (toJSON c)
1387− VM.unsafeWrite mv 3 (toJSON d)
1388− VM.unsafeWrite mv 4 (toJSON e)
1389− VM.unsafeWrite mv 5 (toJSON f)
1390− VM.unsafeWrite mv 6 (toJSON g)
1391− VM.unsafeWrite mv 7 (toJSON h)
1392− VM.unsafeWrite mv 8 (toJSON i)
1393− VM.unsafeWrite mv 9 (toJSON j)
1394− VM.unsafeWrite mv 10 (toJSON k)
1395− VM.unsafeWrite mv 11 (toJSON l)
1396− return mv
1397− {-# INLINE toJSON #-}
1398−
1399− toEncoding (a,b,c,d,e,f,g,h,i,j,k,l) = tuple $
1400− builder a >*<
1401− builder b >*<
1402− builder c >*<
1403− builder d >*<
1404− builder e >*<
1405− builder f >*<
1406− builder g >*<
1407− builder h >*<
1408− builder i >*<
1409− builder j >*<
1410− builder k >*<
1411− builder l
1412− {-# INLINE toEncoding #-}
1413−
1414−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1415− FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j,
1416− FromJSON k, FromJSON l) =>
1417− FromJSON (a,b,c,d,e,f,g,h,i,j,k,l) where
1418− parseJSON = withArray "(a,b,c,d,e,f,g,h,i,j,k,l)" $ \ary ->
1419− let n = V.length ary
1420− in if n /= 12
1421− then fail $ "cannot unpack array of length " ++
1422− show n ++ " into a 12-tuple"
1423− else (,,,,,,,,,,,)
1424− <$> parseJSONElemAtIndex 0 ary
1425− <*> parseJSONElemAtIndex 1 ary
1426− <*> parseJSONElemAtIndex 2 ary
1427− <*> parseJSONElemAtIndex 3 ary
1428− <*> parseJSONElemAtIndex 4 ary
1429− <*> parseJSONElemAtIndex 5 ary
1430− <*> parseJSONElemAtIndex 6 ary
1431− <*> parseJSONElemAtIndex 7 ary
1432− <*> parseJSONElemAtIndex 8 ary
1433− <*> parseJSONElemAtIndex 9 ary
1434− <*> parseJSONElemAtIndex 10 ary
1435− <*> parseJSONElemAtIndex 11 ary
1436− {-# INLINE parseJSON #-}
1437−
1438−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f,
1439− ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l,
1440− ToJSON m) =>
1441− ToJSON (a,b,c,d,e,f,g,h,i,j,k,l,m) where
1442− toJSON (a,b,c,d,e,f,g,h,i,j,k,l,m) = Array $ V.create $ do
1443− mv <- VM.unsafeNew 13
1444− VM.unsafeWrite mv 0 (toJSON a)
1445− VM.unsafeWrite mv 1 (toJSON b)
1446− VM.unsafeWrite mv 2 (toJSON c)
1447− VM.unsafeWrite mv 3 (toJSON d)
1448− VM.unsafeWrite mv 4 (toJSON e)
1449− VM.unsafeWrite mv 5 (toJSON f)
1450− VM.unsafeWrite mv 6 (toJSON g)
1451− VM.unsafeWrite mv 7 (toJSON h)
1452− VM.unsafeWrite mv 8 (toJSON i)
1453− VM.unsafeWrite mv 9 (toJSON j)
1454− VM.unsafeWrite mv 10 (toJSON k)
1455− VM.unsafeWrite mv 11 (toJSON l)
1456− VM.unsafeWrite mv 12 (toJSON m)
1457− return mv
1458− {-# INLINE toJSON #-}
1459−
1460− toEncoding (a,b,c,d,e,f,g,h,i,j,k,l,m) = tuple $
1461− builder a >*<
1462− builder b >*<
1463− builder c >*<
1464− builder d >*<
1465− builder e >*<
1466− builder f >*<
1467− builder g >*<
1468− builder h >*<
1469− builder i >*<
1470− builder j >*<
1471− builder k >*<
1472− builder l >*<
1473− builder m
1474− {-# INLINE toEncoding #-}
1475−
1476−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1477− FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j,
1478− FromJSON k, FromJSON l, FromJSON m) =>
1479− FromJSON (a,b,c,d,e,f,g,h,i,j,k,l,m) where
1480− parseJSON = withArray "(a,b,c,d,e,f,g,h,i,j,k,l,m)" $ \ary ->
1481− let n = V.length ary
1482− in if n /= 13
1483− then fail $ "cannot unpack array of length " ++
1484− show n ++ " into a 13-tuple"
1485− else (,,,,,,,,,,,,)
1486− <$> parseJSONElemAtIndex 0 ary
1487− <*> parseJSONElemAtIndex 1 ary
1488− <*> parseJSONElemAtIndex 2 ary
1489− <*> parseJSONElemAtIndex 3 ary
1490− <*> parseJSONElemAtIndex 4 ary
1491− <*> parseJSONElemAtIndex 5 ary
1492− <*> parseJSONElemAtIndex 6 ary
1493− <*> parseJSONElemAtIndex 7 ary
1494− <*> parseJSONElemAtIndex 8 ary
1495− <*> parseJSONElemAtIndex 9 ary
1496− <*> parseJSONElemAtIndex 10 ary
1497− <*> parseJSONElemAtIndex 11 ary
1498− <*> parseJSONElemAtIndex 12 ary
1499− {-# INLINE parseJSON #-}
1500−
1501−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f,
1502− ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l,
1503− ToJSON m, ToJSON n) =>
1504− ToJSON (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where
1505− toJSON (a,b,c,d,e,f,g,h,i,j,k,l,m,n) = Array $ V.create $ do
1506− mv <- VM.unsafeNew 14
1507− VM.unsafeWrite mv 0 (toJSON a)
1508− VM.unsafeWrite mv 1 (toJSON b)
1509− VM.unsafeWrite mv 2 (toJSON c)
1510− VM.unsafeWrite mv 3 (toJSON d)
1511− VM.unsafeWrite mv 4 (toJSON e)
1512− VM.unsafeWrite mv 5 (toJSON f)
1513− VM.unsafeWrite mv 6 (toJSON g)
1514− VM.unsafeWrite mv 7 (toJSON h)
1515− VM.unsafeWrite mv 8 (toJSON i)
1516− VM.unsafeWrite mv 9 (toJSON j)
1517− VM.unsafeWrite mv 10 (toJSON k)
1518− VM.unsafeWrite mv 11 (toJSON l)
1519− VM.unsafeWrite mv 12 (toJSON m)
1520− VM.unsafeWrite mv 13 (toJSON n)
1521− return mv
1522− {-# INLINE toJSON #-}
1523−
1524− toEncoding (a,b,c,d,e,f,g,h,i,j,k,l,m,n) = tuple $
1525− builder a >*<
1526− builder b >*<
1527− builder c >*<
1528− builder d >*<
1529− builder e >*<
1530− builder f >*<
1531− builder g >*<
1532− builder h >*<
1533− builder i >*<
1534− builder j >*<
1535− builder k >*<
1536− builder l >*<
1537− builder m >*<
1538− builder n
1539− {-# INLINE toEncoding #-}
1540−
1541−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1542− FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j,
1543− FromJSON k, FromJSON l, FromJSON m, FromJSON n) =>
1544− FromJSON (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where
1545− parseJSON = withArray "(a,b,c,d,e,f,g,h,i,j,k,l,m,n)" $ \ary ->
1546− let n = V.length ary
1547− in if n /= 14
1548− then fail $ "cannot unpack array of length " ++
1549− show n ++ " into a 14-tuple"
1550− else (,,,,,,,,,,,,,)
1551− <$> parseJSONElemAtIndex 0 ary
1552− <*> parseJSONElemAtIndex 1 ary
1553− <*> parseJSONElemAtIndex 2 ary
1554− <*> parseJSONElemAtIndex 3 ary
1555− <*> parseJSONElemAtIndex 4 ary
1556− <*> parseJSONElemAtIndex 5 ary
1557− <*> parseJSONElemAtIndex 6 ary
1558− <*> parseJSONElemAtIndex 7 ary
1559− <*> parseJSONElemAtIndex 8 ary
1560− <*> parseJSONElemAtIndex 9 ary
1561− <*> parseJSONElemAtIndex 10 ary
1562− <*> parseJSONElemAtIndex 11 ary
1563− <*> parseJSONElemAtIndex 12 ary
1564− <*> parseJSONElemAtIndex 13 ary
1565− {-# INLINE parseJSON #-}
1566−
1567−instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f,
1568− ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l,
1569− ToJSON m, ToJSON n, ToJSON o) =>
1570− ToJSON (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where
1571− toJSON (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) = Array $ V.create $ do
1572− mv <- VM.unsafeNew 15
1573− VM.unsafeWrite mv 0 (toJSON a)
1574− VM.unsafeWrite mv 1 (toJSON b)
1575− VM.unsafeWrite mv 2 (toJSON c)
1576− VM.unsafeWrite mv 3 (toJSON d)
1577− VM.unsafeWrite mv 4 (toJSON e)
1578− VM.unsafeWrite mv 5 (toJSON f)
1579− VM.unsafeWrite mv 6 (toJSON g)
1580− VM.unsafeWrite mv 7 (toJSON h)
1581− VM.unsafeWrite mv 8 (toJSON i)
1582− VM.unsafeWrite mv 9 (toJSON j)
1583− VM.unsafeWrite mv 10 (toJSON k)
1584− VM.unsafeWrite mv 11 (toJSON l)
1585− VM.unsafeWrite mv 12 (toJSON m)
1586− VM.unsafeWrite mv 13 (toJSON n)
1587− VM.unsafeWrite mv 14 (toJSON o)
1588− return mv
1589− {-# INLINE toJSON #-}
1590−
1591− toEncoding (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) = tuple $
1592− builder a >*<
1593− builder b >*<
1594− builder c >*<
1595− builder d >*<
1596− builder e >*<
1597− builder f >*<
1598− builder g >*<
1599− builder h >*<
1600− builder i >*<
1601− builder j >*<
1602− builder k >*<
1603− builder l >*<
1604− builder m >*<
1605− builder n >*<
1606− builder o
1607− {-# INLINE toEncoding #-}
1608−
1609−instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e,
1610− FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j,
1611− FromJSON k, FromJSON l, FromJSON m, FromJSON n, FromJSON o) =>
1612− FromJSON (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where
1613− parseJSON = withArray "(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)" $ \ary ->
1614− let n = V.length ary
1615− in if n /= 15
1616− then fail $ "cannot unpack array of length " ++
1617− show n ++ " into a 15-tuple"
1618− else (,,,,,,,,,,,,,,)
1619− <$> parseJSONElemAtIndex 0 ary
1620− <*> parseJSONElemAtIndex 1 ary
1621− <*> parseJSONElemAtIndex 2 ary
1622− <*> parseJSONElemAtIndex 3 ary
1623− <*> parseJSONElemAtIndex 4 ary
1624− <*> parseJSONElemAtIndex 5 ary
1625− <*> parseJSONElemAtIndex 6 ary
1626− <*> parseJSONElemAtIndex 7 ary
1627− <*> parseJSONElemAtIndex 8 ary
1628− <*> parseJSONElemAtIndex 9 ary
1629− <*> parseJSONElemAtIndex 10 ary
1630− <*> parseJSONElemAtIndex 11 ary
1631− <*> parseJSONElemAtIndex 12 ary
1632− <*> parseJSONElemAtIndex 13 ary
1633− <*> parseJSONElemAtIndex 14 ary
1634− {-# INLINE parseJSON #-}
1635−
1636982instance ToJSON1 Dual where
1637983 liftToJSON to = to . getDual
1638984 {-# INLINE liftToJSON #-}
Data/Aeson/Types/Instances/Tuple.hsnew file+937
@@ -0,0 +1,937 @@
1+{-# LANGUAGE CPP #-}
2+{-# OPTIONS_GHC -fno-warn-orphans #-}
3+-- |
4+-- Module: Data.Aeson.Types.Instances
5+-- Copyright: (c) 2011-2016 Bryan O'Sullivan
6+-- (c) 2011 MailRank, Inc.
7+-- License: BSD3
8+-- Maintainer: Bryan O'Sullivan <bos@serpentine.com>
9+-- Stability: experimental
10+-- Portability: portable
11+--
12+-- Tuple instances
13+module Data.Aeson.Types.Instances.Tuple (tuple, (>*<)) where
14+
15+import Data.Aeson.Encode.Functions (builder)
16+import Data.Aeson.Types.Class
17+import Data.Aeson.Types.Internal
18+import Data.Monoid ((<>))
19+
20+import qualified Data.Vector as V
21+import qualified Data.Vector.Mutable as VM (unsafeNew, unsafeWrite)
22+import qualified Data.ByteString.Builder as B
23+
24+#if MIN_VERSION_base(4,8,0)
25+#else
26+import Control.Applicative ((<$>), (<*>))
27+#endif
28+
29+parseJSONElemAtIndex :: (Value -> Parser a) -> Int -> V.Vector Value -> Parser a
30+parseJSONElemAtIndex p idx ary = p (V.unsafeIndex ary idx) <?> Index idx
31+
32+(>*<) :: B.Builder -> B.Builder -> B.Builder
33+a >*< b = a <> B.char7 ',' <> b
34+{-# INLINE (>*<) #-}
35+infixr 6 >*<
36+
37+tuple :: B.Builder -> Encoding
38+tuple b = Encoding (B.char7 '[' <> b <> B.char7 ']')
39+{-# INLINE tuple #-}
40+
41+-- Local copy of withArray
42+withArray :: String -> (Array -> Parser a) -> Value -> Parser a
43+withArray _ f (Array arr) = f arr
44+withArray expected _ v = typeMismatch expected v
45+{-# INLINE withArray #-}
46+
47+-------------------------------------------------------------------------------
48+-- Generated, see tuple-instances.hs
49+-------------------------------------------------------------------------------
50+
51+instance ToJSON2 ((,) ) where
52+ liftToJSON2 toA toB (a, b) = Array $ V.create $ do
53+ mv <- VM.unsafeNew 2
54+ VM.unsafeWrite mv 0 (toA a)
55+ VM.unsafeWrite mv 1 (toB b)
56+ return mv
57+ {-# INLINE liftToJSON2 #-}
58+
59+ liftToEncoding2 toA toB (a, b) = tuple $
60+ fromEncoding (toA a) >*<
61+ fromEncoding (toB b)
62+ {-# INLINE liftToEncoding2 #-}
63+
64+instance (ToJSON a) => ToJSON1 ((,) a) where
65+ liftToJSON = liftToJSON2 toJSON
66+ {-# INLINE liftToJSON #-}
67+ liftToEncoding = liftToEncoding2 toEncoding
68+ {-# INLINE liftToEncoding #-}
69+
70+instance (ToJSON a, ToJSON b) => ToJSON (a, b) where
71+ toJSON = toJSON2
72+ {-# INLINE toJSON #-}
73+ toEncoding = toEncoding2
74+ {-# INLINE toEncoding #-}
75+
76+instance FromJSON2 ((,) ) where
77+ liftParseJSON2 pA pB = withArray "(a, b)" $ \t ->
78+ let n = V.length t
79+ in if n == 2
80+ then (,)
81+ <$> parseJSONElemAtIndex pA 0 t
82+ <*> parseJSONElemAtIndex pB 1 t
83+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 2"
84+ {-# INLINE liftParseJSON2 #-}
85+
86+instance (FromJSON a) => FromJSON1 ((,) a) where
87+ liftParseJSON = liftParseJSON2 parseJSON
88+ {-# INLINE liftParseJSON #-}
89+
90+instance (FromJSON a, FromJSON b) => FromJSON (a, b) where
91+ parseJSON = parseJSON2
92+ {-# INLINE parseJSON #-}
93+
94+
95+instance (ToJSON a) => ToJSON2 ((,,) a) where
96+ liftToJSON2 toB toC (a, b, c) = Array $ V.create $ do
97+ mv <- VM.unsafeNew 3
98+ VM.unsafeWrite mv 0 (toJSON a)
99+ VM.unsafeWrite mv 1 (toB b)
100+ VM.unsafeWrite mv 2 (toC c)
101+ return mv
102+ {-# INLINE liftToJSON2 #-}
103+
104+ liftToEncoding2 toB toC (a, b, c) = tuple $
105+ builder a >*<
106+ fromEncoding (toB b) >*<
107+ fromEncoding (toC c)
108+ {-# INLINE liftToEncoding2 #-}
109+
110+instance (ToJSON a, ToJSON b) => ToJSON1 ((,,) a b) where
111+ liftToJSON = liftToJSON2 toJSON
112+ {-# INLINE liftToJSON #-}
113+ liftToEncoding = liftToEncoding2 toEncoding
114+ {-# INLINE liftToEncoding #-}
115+
116+instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON (a, b, c) where
117+ toJSON = toJSON2
118+ {-# INLINE toJSON #-}
119+ toEncoding = toEncoding2
120+ {-# INLINE toEncoding #-}
121+
122+instance (FromJSON a) => FromJSON2 ((,,) a) where
123+ liftParseJSON2 pB pC = withArray "(a, b, c)" $ \t ->
124+ let n = V.length t
125+ in if n == 3
126+ then (,,)
127+ <$> parseJSONElemAtIndex parseJSON 0 t
128+ <*> parseJSONElemAtIndex pB 1 t
129+ <*> parseJSONElemAtIndex pC 2 t
130+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 3"
131+ {-# INLINE liftParseJSON2 #-}
132+
133+instance (FromJSON a, FromJSON b) => FromJSON1 ((,,) a b) where
134+ liftParseJSON = liftParseJSON2 parseJSON
135+ {-# INLINE liftParseJSON #-}
136+
137+instance (FromJSON a, FromJSON b, FromJSON c) => FromJSON (a, b, c) where
138+ parseJSON = parseJSON2
139+ {-# INLINE parseJSON #-}
140+
141+
142+instance (ToJSON a, ToJSON b) => ToJSON2 ((,,,) a b) where
143+ liftToJSON2 toC toD (a, b, c, d) = Array $ V.create $ do
144+ mv <- VM.unsafeNew 4
145+ VM.unsafeWrite mv 0 (toJSON a)
146+ VM.unsafeWrite mv 1 (toJSON b)
147+ VM.unsafeWrite mv 2 (toC c)
148+ VM.unsafeWrite mv 3 (toD d)
149+ return mv
150+ {-# INLINE liftToJSON2 #-}
151+
152+ liftToEncoding2 toC toD (a, b, c, d) = tuple $
153+ builder a >*<
154+ builder b >*<
155+ fromEncoding (toC c) >*<
156+ fromEncoding (toD d)
157+ {-# INLINE liftToEncoding2 #-}
158+
159+instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON1 ((,,,) a b c) where
160+ liftToJSON = liftToJSON2 toJSON
161+ {-# INLINE liftToJSON #-}
162+ liftToEncoding = liftToEncoding2 toEncoding
163+ {-# INLINE liftToEncoding #-}
164+
165+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON (a, b, c, d) where
166+ toJSON = toJSON2
167+ {-# INLINE toJSON #-}
168+ toEncoding = toEncoding2
169+ {-# INLINE toEncoding #-}
170+
171+instance (FromJSON a, FromJSON b) => FromJSON2 ((,,,) a b) where
172+ liftParseJSON2 pC pD = withArray "(a, b, c, d)" $ \t ->
173+ let n = V.length t
174+ in if n == 4
175+ then (,,,)
176+ <$> parseJSONElemAtIndex parseJSON 0 t
177+ <*> parseJSONElemAtIndex parseJSON 1 t
178+ <*> parseJSONElemAtIndex pC 2 t
179+ <*> parseJSONElemAtIndex pD 3 t
180+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 4"
181+ {-# INLINE liftParseJSON2 #-}
182+
183+instance (FromJSON a, FromJSON b, FromJSON c) => FromJSON1 ((,,,) a b c) where
184+ liftParseJSON = liftParseJSON2 parseJSON
185+ {-# INLINE liftParseJSON #-}
186+
187+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON (a, b, c, d) where
188+ parseJSON = parseJSON2
189+ {-# INLINE parseJSON #-}
190+
191+
192+instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON2 ((,,,,) a b c) where
193+ liftToJSON2 toD toE (a, b, c, d, e) = Array $ V.create $ do
194+ mv <- VM.unsafeNew 5
195+ VM.unsafeWrite mv 0 (toJSON a)
196+ VM.unsafeWrite mv 1 (toJSON b)
197+ VM.unsafeWrite mv 2 (toJSON c)
198+ VM.unsafeWrite mv 3 (toD d)
199+ VM.unsafeWrite mv 4 (toE e)
200+ return mv
201+ {-# INLINE liftToJSON2 #-}
202+
203+ liftToEncoding2 toD toE (a, b, c, d, e) = tuple $
204+ builder a >*<
205+ builder b >*<
206+ builder c >*<
207+ fromEncoding (toD d) >*<
208+ fromEncoding (toE e)
209+ {-# INLINE liftToEncoding2 #-}
210+
211+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON1 ((,,,,) a b c d) where
212+ liftToJSON = liftToJSON2 toJSON
213+ {-# INLINE liftToJSON #-}
214+ liftToEncoding = liftToEncoding2 toEncoding
215+ {-# INLINE liftToEncoding #-}
216+
217+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON (a, b, c, d, e) where
218+ toJSON = toJSON2
219+ {-# INLINE toJSON #-}
220+ toEncoding = toEncoding2
221+ {-# INLINE toEncoding #-}
222+
223+instance (FromJSON a, FromJSON b, FromJSON c) => FromJSON2 ((,,,,) a b c) where
224+ liftParseJSON2 pD pE = withArray "(a, b, c, d, e)" $ \t ->
225+ let n = V.length t
226+ in if n == 5
227+ then (,,,,)
228+ <$> parseJSONElemAtIndex parseJSON 0 t
229+ <*> parseJSONElemAtIndex parseJSON 1 t
230+ <*> parseJSONElemAtIndex parseJSON 2 t
231+ <*> parseJSONElemAtIndex pD 3 t
232+ <*> parseJSONElemAtIndex pE 4 t
233+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 5"
234+ {-# INLINE liftParseJSON2 #-}
235+
236+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON1 ((,,,,) a b c d) where
237+ liftParseJSON = liftParseJSON2 parseJSON
238+ {-# INLINE liftParseJSON #-}
239+
240+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e) => FromJSON (a, b, c, d, e) where
241+ parseJSON = parseJSON2
242+ {-# INLINE parseJSON #-}
243+
244+
245+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON2 ((,,,,,) a b c d) where
246+ liftToJSON2 toE toF (a, b, c, d, e, f) = Array $ V.create $ do
247+ mv <- VM.unsafeNew 6
248+ VM.unsafeWrite mv 0 (toJSON a)
249+ VM.unsafeWrite mv 1 (toJSON b)
250+ VM.unsafeWrite mv 2 (toJSON c)
251+ VM.unsafeWrite mv 3 (toJSON d)
252+ VM.unsafeWrite mv 4 (toE e)
253+ VM.unsafeWrite mv 5 (toF f)
254+ return mv
255+ {-# INLINE liftToJSON2 #-}
256+
257+ liftToEncoding2 toE toF (a, b, c, d, e, f) = tuple $
258+ builder a >*<
259+ builder b >*<
260+ builder c >*<
261+ builder d >*<
262+ fromEncoding (toE e) >*<
263+ fromEncoding (toF f)
264+ {-# INLINE liftToEncoding2 #-}
265+
266+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON1 ((,,,,,) a b c d e) where
267+ liftToJSON = liftToJSON2 toJSON
268+ {-# INLINE liftToJSON #-}
269+ liftToEncoding = liftToEncoding2 toEncoding
270+ {-# INLINE liftToEncoding #-}
271+
272+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON (a, b, c, d, e, f) where
273+ toJSON = toJSON2
274+ {-# INLINE toJSON #-}
275+ toEncoding = toEncoding2
276+ {-# INLINE toEncoding #-}
277+
278+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON2 ((,,,,,) a b c d) where
279+ liftParseJSON2 pE pF = withArray "(a, b, c, d, e, f)" $ \t ->
280+ let n = V.length t
281+ in if n == 6
282+ then (,,,,,)
283+ <$> parseJSONElemAtIndex parseJSON 0 t
284+ <*> parseJSONElemAtIndex parseJSON 1 t
285+ <*> parseJSONElemAtIndex parseJSON 2 t
286+ <*> parseJSONElemAtIndex parseJSON 3 t
287+ <*> parseJSONElemAtIndex pE 4 t
288+ <*> parseJSONElemAtIndex pF 5 t
289+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 6"
290+ {-# INLINE liftParseJSON2 #-}
291+
292+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e) => FromJSON1 ((,,,,,) a b c d e) where
293+ liftParseJSON = liftParseJSON2 parseJSON
294+ {-# INLINE liftParseJSON #-}
295+
296+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f) => FromJSON (a, b, c, d, e, f) where
297+ parseJSON = parseJSON2
298+ {-# INLINE parseJSON #-}
299+
300+
301+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON2 ((,,,,,,) a b c d e) where
302+ liftToJSON2 toF toG (a, b, c, d, e, f, g) = Array $ V.create $ do
303+ mv <- VM.unsafeNew 7
304+ VM.unsafeWrite mv 0 (toJSON a)
305+ VM.unsafeWrite mv 1 (toJSON b)
306+ VM.unsafeWrite mv 2 (toJSON c)
307+ VM.unsafeWrite mv 3 (toJSON d)
308+ VM.unsafeWrite mv 4 (toJSON e)
309+ VM.unsafeWrite mv 5 (toF f)
310+ VM.unsafeWrite mv 6 (toG g)
311+ return mv
312+ {-# INLINE liftToJSON2 #-}
313+
314+ liftToEncoding2 toF toG (a, b, c, d, e, f, g) = tuple $
315+ builder a >*<
316+ builder b >*<
317+ builder c >*<
318+ builder d >*<
319+ builder e >*<
320+ fromEncoding (toF f) >*<
321+ fromEncoding (toG g)
322+ {-# INLINE liftToEncoding2 #-}
323+
324+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON1 ((,,,,,,) a b c d e f) where
325+ liftToJSON = liftToJSON2 toJSON
326+ {-# INLINE liftToJSON #-}
327+ liftToEncoding = liftToEncoding2 toEncoding
328+ {-# INLINE liftToEncoding #-}
329+
330+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON (a, b, c, d, e, f, g) where
331+ toJSON = toJSON2
332+ {-# INLINE toJSON #-}
333+ toEncoding = toEncoding2
334+ {-# INLINE toEncoding #-}
335+
336+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e) => FromJSON2 ((,,,,,,) a b c d e) where
337+ liftParseJSON2 pF pG = withArray "(a, b, c, d, e, f, g)" $ \t ->
338+ let n = V.length t
339+ in if n == 7
340+ then (,,,,,,)
341+ <$> parseJSONElemAtIndex parseJSON 0 t
342+ <*> parseJSONElemAtIndex parseJSON 1 t
343+ <*> parseJSONElemAtIndex parseJSON 2 t
344+ <*> parseJSONElemAtIndex parseJSON 3 t
345+ <*> parseJSONElemAtIndex parseJSON 4 t
346+ <*> parseJSONElemAtIndex pF 5 t
347+ <*> parseJSONElemAtIndex pG 6 t
348+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 7"
349+ {-# INLINE liftParseJSON2 #-}
350+
351+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f) => FromJSON1 ((,,,,,,) a b c d e f) where
352+ liftParseJSON = liftParseJSON2 parseJSON
353+ {-# INLINE liftParseJSON #-}
354+
355+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g) => FromJSON (a, b, c, d, e, f, g) where
356+ parseJSON = parseJSON2
357+ {-# INLINE parseJSON #-}
358+
359+
360+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON2 ((,,,,,,,) a b c d e f) where
361+ liftToJSON2 toG toH (a, b, c, d, e, f, g, h) = Array $ V.create $ do
362+ mv <- VM.unsafeNew 8
363+ VM.unsafeWrite mv 0 (toJSON a)
364+ VM.unsafeWrite mv 1 (toJSON b)
365+ VM.unsafeWrite mv 2 (toJSON c)
366+ VM.unsafeWrite mv 3 (toJSON d)
367+ VM.unsafeWrite mv 4 (toJSON e)
368+ VM.unsafeWrite mv 5 (toJSON f)
369+ VM.unsafeWrite mv 6 (toG g)
370+ VM.unsafeWrite mv 7 (toH h)
371+ return mv
372+ {-# INLINE liftToJSON2 #-}
373+
374+ liftToEncoding2 toG toH (a, b, c, d, e, f, g, h) = tuple $
375+ builder a >*<
376+ builder b >*<
377+ builder c >*<
378+ builder d >*<
379+ builder e >*<
380+ builder f >*<
381+ fromEncoding (toG g) >*<
382+ fromEncoding (toH h)
383+ {-# INLINE liftToEncoding2 #-}
384+
385+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON1 ((,,,,,,,) a b c d e f g) where
386+ liftToJSON = liftToJSON2 toJSON
387+ {-# INLINE liftToJSON #-}
388+ liftToEncoding = liftToEncoding2 toEncoding
389+ {-# INLINE liftToEncoding #-}
390+
391+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON (a, b, c, d, e, f, g, h) where
392+ toJSON = toJSON2
393+ {-# INLINE toJSON #-}
394+ toEncoding = toEncoding2
395+ {-# INLINE toEncoding #-}
396+
397+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f) => FromJSON2 ((,,,,,,,) a b c d e f) where
398+ liftParseJSON2 pG pH = withArray "(a, b, c, d, e, f, g, h)" $ \t ->
399+ let n = V.length t
400+ in if n == 8
401+ then (,,,,,,,)
402+ <$> parseJSONElemAtIndex parseJSON 0 t
403+ <*> parseJSONElemAtIndex parseJSON 1 t
404+ <*> parseJSONElemAtIndex parseJSON 2 t
405+ <*> parseJSONElemAtIndex parseJSON 3 t
406+ <*> parseJSONElemAtIndex parseJSON 4 t
407+ <*> parseJSONElemAtIndex parseJSON 5 t
408+ <*> parseJSONElemAtIndex pG 6 t
409+ <*> parseJSONElemAtIndex pH 7 t
410+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 8"
411+ {-# INLINE liftParseJSON2 #-}
412+
413+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g) => FromJSON1 ((,,,,,,,) a b c d e f g) where
414+ liftParseJSON = liftParseJSON2 parseJSON
415+ {-# INLINE liftParseJSON #-}
416+
417+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h) => FromJSON (a, b, c, d, e, f, g, h) where
418+ parseJSON = parseJSON2
419+ {-# INLINE parseJSON #-}
420+
421+
422+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON2 ((,,,,,,,,) a b c d e f g) where
423+ liftToJSON2 toH toI (a, b, c, d, e, f, g, h, i) = Array $ V.create $ do
424+ mv <- VM.unsafeNew 9
425+ VM.unsafeWrite mv 0 (toJSON a)
426+ VM.unsafeWrite mv 1 (toJSON b)
427+ VM.unsafeWrite mv 2 (toJSON c)
428+ VM.unsafeWrite mv 3 (toJSON d)
429+ VM.unsafeWrite mv 4 (toJSON e)
430+ VM.unsafeWrite mv 5 (toJSON f)
431+ VM.unsafeWrite mv 6 (toJSON g)
432+ VM.unsafeWrite mv 7 (toH h)
433+ VM.unsafeWrite mv 8 (toI i)
434+ return mv
435+ {-# INLINE liftToJSON2 #-}
436+
437+ liftToEncoding2 toH toI (a, b, c, d, e, f, g, h, i) = tuple $
438+ builder a >*<
439+ builder b >*<
440+ builder c >*<
441+ builder d >*<
442+ builder e >*<
443+ builder f >*<
444+ builder g >*<
445+ fromEncoding (toH h) >*<
446+ fromEncoding (toI i)
447+ {-# INLINE liftToEncoding2 #-}
448+
449+instance (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
450+ liftToJSON = liftToJSON2 toJSON
451+ {-# INLINE liftToJSON #-}
452+ liftToEncoding = liftToEncoding2 toEncoding
453+ {-# INLINE liftToEncoding #-}
454+
455+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON (a, b, c, d, e, f, g, h, i) where
456+ toJSON = toJSON2
457+ {-# INLINE toJSON #-}
458+ toEncoding = toEncoding2
459+ {-# INLINE toEncoding #-}
460+
461+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g) => FromJSON2 ((,,,,,,,,) a b c d e f g) where
462+ liftParseJSON2 pH pI = withArray "(a, b, c, d, e, f, g, h, i)" $ \t ->
463+ let n = V.length t
464+ in if n == 9
465+ then (,,,,,,,,)
466+ <$> parseJSONElemAtIndex parseJSON 0 t
467+ <*> parseJSONElemAtIndex parseJSON 1 t
468+ <*> parseJSONElemAtIndex parseJSON 2 t
469+ <*> parseJSONElemAtIndex parseJSON 3 t
470+ <*> parseJSONElemAtIndex parseJSON 4 t
471+ <*> parseJSONElemAtIndex parseJSON 5 t
472+ <*> parseJSONElemAtIndex parseJSON 6 t
473+ <*> parseJSONElemAtIndex pH 7 t
474+ <*> parseJSONElemAtIndex pI 8 t
475+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 9"
476+ {-# INLINE liftParseJSON2 #-}
477+
478+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h) => FromJSON1 ((,,,,,,,,) a b c d e f g h) where
479+ liftParseJSON = liftParseJSON2 parseJSON
480+ {-# INLINE liftParseJSON #-}
481+
482+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i) => FromJSON (a, b, c, d, e, f, g, h, i) where
483+ parseJSON = parseJSON2
484+ {-# INLINE parseJSON #-}
485+
486+
487+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON2 ((,,,,,,,,,) a b c d e f g h) where
488+ liftToJSON2 toI toJ (a, b, c, d, e, f, g, h, i, j) = Array $ V.create $ do
489+ mv <- VM.unsafeNew 10
490+ VM.unsafeWrite mv 0 (toJSON a)
491+ VM.unsafeWrite mv 1 (toJSON b)
492+ VM.unsafeWrite mv 2 (toJSON c)
493+ VM.unsafeWrite mv 3 (toJSON d)
494+ VM.unsafeWrite mv 4 (toJSON e)
495+ VM.unsafeWrite mv 5 (toJSON f)
496+ VM.unsafeWrite mv 6 (toJSON g)
497+ VM.unsafeWrite mv 7 (toJSON h)
498+ VM.unsafeWrite mv 8 (toI i)
499+ VM.unsafeWrite mv 9 (toJ j)
500+ return mv
501+ {-# INLINE liftToJSON2 #-}
502+
503+ liftToEncoding2 toI toJ (a, b, c, d, e, f, g, h, i, j) = tuple $
504+ builder a >*<
505+ builder b >*<
506+ builder c >*<
507+ builder d >*<
508+ builder e >*<
509+ builder f >*<
510+ builder g >*<
511+ builder h >*<
512+ fromEncoding (toI i) >*<
513+ fromEncoding (toJ j)
514+ {-# INLINE liftToEncoding2 #-}
515+
516+instance (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
517+ liftToJSON = liftToJSON2 toJSON
518+ {-# INLINE liftToJSON #-}
519+ liftToEncoding = liftToEncoding2 toEncoding
520+ {-# INLINE liftToEncoding #-}
521+
522+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON (a, b, c, d, e, f, g, h, i, j) where
523+ toJSON = toJSON2
524+ {-# INLINE toJSON #-}
525+ toEncoding = toEncoding2
526+ {-# INLINE toEncoding #-}
527+
528+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h) => FromJSON2 ((,,,,,,,,,) a b c d e f g h) where
529+ liftParseJSON2 pI pJ = withArray "(a, b, c, d, e, f, g, h, i, j)" $ \t ->
530+ let n = V.length t
531+ in if n == 10
532+ then (,,,,,,,,,)
533+ <$> parseJSONElemAtIndex parseJSON 0 t
534+ <*> parseJSONElemAtIndex parseJSON 1 t
535+ <*> parseJSONElemAtIndex parseJSON 2 t
536+ <*> parseJSONElemAtIndex parseJSON 3 t
537+ <*> parseJSONElemAtIndex parseJSON 4 t
538+ <*> parseJSONElemAtIndex parseJSON 5 t
539+ <*> parseJSONElemAtIndex parseJSON 6 t
540+ <*> parseJSONElemAtIndex parseJSON 7 t
541+ <*> parseJSONElemAtIndex pI 8 t
542+ <*> parseJSONElemAtIndex pJ 9 t
543+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 10"
544+ {-# INLINE liftParseJSON2 #-}
545+
546+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i) => FromJSON1 ((,,,,,,,,,) a b c d e f g h i) where
547+ liftParseJSON = liftParseJSON2 parseJSON
548+ {-# INLINE liftParseJSON #-}
549+
550+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j) => FromJSON (a, b, c, d, e, f, g, h, i, j) where
551+ parseJSON = parseJSON2
552+ {-# INLINE parseJSON #-}
553+
554+
555+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON2 ((,,,,,,,,,,) a b c d e f g h i) where
556+ liftToJSON2 toJ toK (a, b, c, d, e, f, g, h, i, j, k) = Array $ V.create $ do
557+ mv <- VM.unsafeNew 11
558+ VM.unsafeWrite mv 0 (toJSON a)
559+ VM.unsafeWrite mv 1 (toJSON b)
560+ VM.unsafeWrite mv 2 (toJSON c)
561+ VM.unsafeWrite mv 3 (toJSON d)
562+ VM.unsafeWrite mv 4 (toJSON e)
563+ VM.unsafeWrite mv 5 (toJSON f)
564+ VM.unsafeWrite mv 6 (toJSON g)
565+ VM.unsafeWrite mv 7 (toJSON h)
566+ VM.unsafeWrite mv 8 (toJSON i)
567+ VM.unsafeWrite mv 9 (toJ j)
568+ VM.unsafeWrite mv 10 (toK k)
569+ return mv
570+ {-# INLINE liftToJSON2 #-}
571+
572+ liftToEncoding2 toJ toK (a, b, c, d, e, f, g, h, i, j, k) = tuple $
573+ builder a >*<
574+ builder b >*<
575+ builder c >*<
576+ builder d >*<
577+ builder e >*<
578+ builder f >*<
579+ builder g >*<
580+ builder h >*<
581+ builder i >*<
582+ fromEncoding (toJ j) >*<
583+ fromEncoding (toK k)
584+ {-# INLINE liftToEncoding2 #-}
585+
586+instance (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
587+ liftToJSON = liftToJSON2 toJSON
588+ {-# INLINE liftToJSON #-}
589+ liftToEncoding = liftToEncoding2 toEncoding
590+ {-# INLINE liftToEncoding #-}
591+
592+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON (a, b, c, d, e, f, g, h, i, j, k) where
593+ toJSON = toJSON2
594+ {-# INLINE toJSON #-}
595+ toEncoding = toEncoding2
596+ {-# INLINE toEncoding #-}
597+
598+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i) => FromJSON2 ((,,,,,,,,,,) a b c d e f g h i) where
599+ liftParseJSON2 pJ pK = withArray "(a, b, c, d, e, f, g, h, i, j, k)" $ \t ->
600+ let n = V.length t
601+ in if n == 11
602+ then (,,,,,,,,,,)
603+ <$> parseJSONElemAtIndex parseJSON 0 t
604+ <*> parseJSONElemAtIndex parseJSON 1 t
605+ <*> parseJSONElemAtIndex parseJSON 2 t
606+ <*> parseJSONElemAtIndex parseJSON 3 t
607+ <*> parseJSONElemAtIndex parseJSON 4 t
608+ <*> parseJSONElemAtIndex parseJSON 5 t
609+ <*> parseJSONElemAtIndex parseJSON 6 t
610+ <*> parseJSONElemAtIndex parseJSON 7 t
611+ <*> parseJSONElemAtIndex parseJSON 8 t
612+ <*> parseJSONElemAtIndex pJ 9 t
613+ <*> parseJSONElemAtIndex pK 10 t
614+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 11"
615+ {-# INLINE liftParseJSON2 #-}
616+
617+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j) => FromJSON1 ((,,,,,,,,,,) a b c d e f g h i j) where
618+ liftParseJSON = liftParseJSON2 parseJSON
619+ {-# INLINE liftParseJSON #-}
620+
621+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k) => FromJSON (a, b, c, d, e, f, g, h, i, j, k) where
622+ parseJSON = parseJSON2
623+ {-# INLINE parseJSON #-}
624+
625+
626+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON2 ((,,,,,,,,,,,) a b c d e f g h i j) where
627+ liftToJSON2 toK toL (a, b, c, d, e, f, g, h, i, j, k, l) = Array $ V.create $ do
628+ mv <- VM.unsafeNew 12
629+ VM.unsafeWrite mv 0 (toJSON a)
630+ VM.unsafeWrite mv 1 (toJSON b)
631+ VM.unsafeWrite mv 2 (toJSON c)
632+ VM.unsafeWrite mv 3 (toJSON d)
633+ VM.unsafeWrite mv 4 (toJSON e)
634+ VM.unsafeWrite mv 5 (toJSON f)
635+ VM.unsafeWrite mv 6 (toJSON g)
636+ VM.unsafeWrite mv 7 (toJSON h)
637+ VM.unsafeWrite mv 8 (toJSON i)
638+ VM.unsafeWrite mv 9 (toJSON j)
639+ VM.unsafeWrite mv 10 (toK k)
640+ VM.unsafeWrite mv 11 (toL l)
641+ return mv
642+ {-# INLINE liftToJSON2 #-}
643+
644+ liftToEncoding2 toK toL (a, b, c, d, e, f, g, h, i, j, k, l) = tuple $
645+ builder a >*<
646+ builder b >*<
647+ builder c >*<
648+ builder d >*<
649+ builder e >*<
650+ builder f >*<
651+ builder g >*<
652+ builder h >*<
653+ builder i >*<
654+ builder j >*<
655+ fromEncoding (toK k) >*<
656+ fromEncoding (toL l)
657+ {-# INLINE liftToEncoding2 #-}
658+
659+instance (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
660+ liftToJSON = liftToJSON2 toJSON
661+ {-# INLINE liftToJSON #-}
662+ liftToEncoding = liftToEncoding2 toEncoding
663+ {-# INLINE liftToEncoding #-}
664+
665+instance (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 (a, b, c, d, e, f, g, h, i, j, k, l) where
666+ toJSON = toJSON2
667+ {-# INLINE toJSON #-}
668+ toEncoding = toEncoding2
669+ {-# INLINE toEncoding #-}
670+
671+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j) => FromJSON2 ((,,,,,,,,,,,) a b c d e f g h i j) where
672+ liftParseJSON2 pK pL = withArray "(a, b, c, d, e, f, g, h, i, j, k, l)" $ \t ->
673+ let n = V.length t
674+ in if n == 12
675+ then (,,,,,,,,,,,)
676+ <$> parseJSONElemAtIndex parseJSON 0 t
677+ <*> parseJSONElemAtIndex parseJSON 1 t
678+ <*> parseJSONElemAtIndex parseJSON 2 t
679+ <*> parseJSONElemAtIndex parseJSON 3 t
680+ <*> parseJSONElemAtIndex parseJSON 4 t
681+ <*> parseJSONElemAtIndex parseJSON 5 t
682+ <*> parseJSONElemAtIndex parseJSON 6 t
683+ <*> parseJSONElemAtIndex parseJSON 7 t
684+ <*> parseJSONElemAtIndex parseJSON 8 t
685+ <*> parseJSONElemAtIndex parseJSON 9 t
686+ <*> parseJSONElemAtIndex pK 10 t
687+ <*> parseJSONElemAtIndex pL 11 t
688+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 12"
689+ {-# INLINE liftParseJSON2 #-}
690+
691+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k) => FromJSON1 ((,,,,,,,,,,,) a b c d e f g h i j k) where
692+ liftParseJSON = liftParseJSON2 parseJSON
693+ {-# INLINE liftParseJSON #-}
694+
695+instance (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 (a, b, c, d, e, f, g, h, i, j, k, l) where
696+ parseJSON = parseJSON2
697+ {-# INLINE parseJSON #-}
698+
699+
700+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON2 ((,,,,,,,,,,,,) a b c d e f g h i j k) where
701+ liftToJSON2 toL toM (a, b, c, d, e, f, g, h, i, j, k, l, m) = Array $ V.create $ do
702+ mv <- VM.unsafeNew 13
703+ VM.unsafeWrite mv 0 (toJSON a)
704+ VM.unsafeWrite mv 1 (toJSON b)
705+ VM.unsafeWrite mv 2 (toJSON c)
706+ VM.unsafeWrite mv 3 (toJSON d)
707+ VM.unsafeWrite mv 4 (toJSON e)
708+ VM.unsafeWrite mv 5 (toJSON f)
709+ VM.unsafeWrite mv 6 (toJSON g)
710+ VM.unsafeWrite mv 7 (toJSON h)
711+ VM.unsafeWrite mv 8 (toJSON i)
712+ VM.unsafeWrite mv 9 (toJSON j)
713+ VM.unsafeWrite mv 10 (toJSON k)
714+ VM.unsafeWrite mv 11 (toL l)
715+ VM.unsafeWrite mv 12 (toM m)
716+ return mv
717+ {-# INLINE liftToJSON2 #-}
718+
719+ liftToEncoding2 toL toM (a, b, c, d, e, f, g, h, i, j, k, l, m) = tuple $
720+ builder a >*<
721+ builder b >*<
722+ builder c >*<
723+ builder d >*<
724+ builder e >*<
725+ builder f >*<
726+ builder g >*<
727+ builder h >*<
728+ builder i >*<
729+ builder j >*<
730+ builder k >*<
731+ fromEncoding (toL l) >*<
732+ fromEncoding (toM m)
733+ {-# INLINE liftToEncoding2 #-}
734+
735+instance (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
736+ liftToJSON = liftToJSON2 toJSON
737+ {-# INLINE liftToJSON #-}
738+ liftToEncoding = liftToEncoding2 toEncoding
739+ {-# INLINE liftToEncoding #-}
740+
741+instance (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 (a, b, c, d, e, f, g, h, i, j, k, l, m) where
742+ toJSON = toJSON2
743+ {-# INLINE toJSON #-}
744+ toEncoding = toEncoding2
745+ {-# INLINE toEncoding #-}
746+
747+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k) => FromJSON2 ((,,,,,,,,,,,,) a b c d e f g h i j k) where
748+ liftParseJSON2 pL pM = withArray "(a, b, c, d, e, f, g, h, i, j, k, l, m)" $ \t ->
749+ let n = V.length t
750+ in if n == 13
751+ then (,,,,,,,,,,,,)
752+ <$> parseJSONElemAtIndex parseJSON 0 t
753+ <*> parseJSONElemAtIndex parseJSON 1 t
754+ <*> parseJSONElemAtIndex parseJSON 2 t
755+ <*> parseJSONElemAtIndex parseJSON 3 t
756+ <*> parseJSONElemAtIndex parseJSON 4 t
757+ <*> parseJSONElemAtIndex parseJSON 5 t
758+ <*> parseJSONElemAtIndex parseJSON 6 t
759+ <*> parseJSONElemAtIndex parseJSON 7 t
760+ <*> parseJSONElemAtIndex parseJSON 8 t
761+ <*> parseJSONElemAtIndex parseJSON 9 t
762+ <*> parseJSONElemAtIndex parseJSON 10 t
763+ <*> parseJSONElemAtIndex pL 11 t
764+ <*> parseJSONElemAtIndex pM 12 t
765+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 13"
766+ {-# INLINE liftParseJSON2 #-}
767+
768+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l) => FromJSON1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) where
769+ liftParseJSON = liftParseJSON2 parseJSON
770+ {-# INLINE liftParseJSON #-}
771+
772+instance (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 (a, b, c, d, e, f, g, h, i, j, k, l, m) where
773+ parseJSON = parseJSON2
774+ {-# INLINE parseJSON #-}
775+
776+
777+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON2 ((,,,,,,,,,,,,,) a b c d e f g h i j k l) where
778+ liftToJSON2 toM toN (a, b, c, d, e, f, g, h, i, j, k, l, m, n) = Array $ V.create $ do
779+ mv <- VM.unsafeNew 14
780+ VM.unsafeWrite mv 0 (toJSON a)
781+ VM.unsafeWrite mv 1 (toJSON b)
782+ VM.unsafeWrite mv 2 (toJSON c)
783+ VM.unsafeWrite mv 3 (toJSON d)
784+ VM.unsafeWrite mv 4 (toJSON e)
785+ VM.unsafeWrite mv 5 (toJSON f)
786+ VM.unsafeWrite mv 6 (toJSON g)
787+ VM.unsafeWrite mv 7 (toJSON h)
788+ VM.unsafeWrite mv 8 (toJSON i)
789+ VM.unsafeWrite mv 9 (toJSON j)
790+ VM.unsafeWrite mv 10 (toJSON k)
791+ VM.unsafeWrite mv 11 (toJSON l)
792+ VM.unsafeWrite mv 12 (toM m)
793+ VM.unsafeWrite mv 13 (toN n)
794+ return mv
795+ {-# INLINE liftToJSON2 #-}
796+
797+ liftToEncoding2 toM toN (a, b, c, d, e, f, g, h, i, j, k, l, m, n) = tuple $
798+ builder a >*<
799+ builder b >*<
800+ builder c >*<
801+ builder d >*<
802+ builder e >*<
803+ builder f >*<
804+ builder g >*<
805+ builder h >*<
806+ builder i >*<
807+ builder j >*<
808+ builder k >*<
809+ builder l >*<
810+ fromEncoding (toM m) >*<
811+ fromEncoding (toN n)
812+ {-# INLINE liftToEncoding2 #-}
813+
814+instance (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
815+ liftToJSON = liftToJSON2 toJSON
816+ {-# INLINE liftToJSON #-}
817+ liftToEncoding = liftToEncoding2 toEncoding
818+ {-# INLINE liftToEncoding #-}
819+
820+instance (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) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where
821+ toJSON = toJSON2
822+ {-# INLINE toJSON #-}
823+ toEncoding = toEncoding2
824+ {-# INLINE toEncoding #-}
825+
826+instance (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l) => FromJSON2 ((,,,,,,,,,,,,,) a b c d e f g h i j k l) where
827+ liftParseJSON2 pM pN = withArray "(a, b, c, d, e, f, g, h, i, j, k, l, m, n)" $ \t ->
828+ let n = V.length t
829+ in if n == 14
830+ then (,,,,,,,,,,,,,)
831+ <$> parseJSONElemAtIndex parseJSON 0 t
832+ <*> parseJSONElemAtIndex parseJSON 1 t
833+ <*> parseJSONElemAtIndex parseJSON 2 t
834+ <*> parseJSONElemAtIndex parseJSON 3 t
835+ <*> parseJSONElemAtIndex parseJSON 4 t
836+ <*> parseJSONElemAtIndex parseJSON 5 t
837+ <*> parseJSONElemAtIndex parseJSON 6 t
838+ <*> parseJSONElemAtIndex parseJSON 7 t
839+ <*> parseJSONElemAtIndex parseJSON 8 t
840+ <*> parseJSONElemAtIndex parseJSON 9 t
841+ <*> parseJSONElemAtIndex parseJSON 10 t
842+ <*> parseJSONElemAtIndex parseJSON 11 t
843+ <*> parseJSONElemAtIndex pM 12 t
844+ <*> parseJSONElemAtIndex pN 13 t
845+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 14"
846+ {-# INLINE liftParseJSON2 #-}
847+
848+instance (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) => FromJSON1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) where
849+ liftParseJSON = liftParseJSON2 parseJSON
850+ {-# INLINE liftParseJSON #-}
851+
852+instance (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 (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where
853+ parseJSON = parseJSON2
854+ {-# INLINE parseJSON #-}
855+
856+
857+instance (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) => ToJSON2 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m) where
858+ liftToJSON2 toN toO (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) = Array $ V.create $ do
859+ mv <- VM.unsafeNew 15
860+ VM.unsafeWrite mv 0 (toJSON a)
861+ VM.unsafeWrite mv 1 (toJSON b)
862+ VM.unsafeWrite mv 2 (toJSON c)
863+ VM.unsafeWrite mv 3 (toJSON d)
864+ VM.unsafeWrite mv 4 (toJSON e)
865+ VM.unsafeWrite mv 5 (toJSON f)
866+ VM.unsafeWrite mv 6 (toJSON g)
867+ VM.unsafeWrite mv 7 (toJSON h)
868+ VM.unsafeWrite mv 8 (toJSON i)
869+ VM.unsafeWrite mv 9 (toJSON j)
870+ VM.unsafeWrite mv 10 (toJSON k)
871+ VM.unsafeWrite mv 11 (toJSON l)
872+ VM.unsafeWrite mv 12 (toJSON m)
873+ VM.unsafeWrite mv 13 (toN n)
874+ VM.unsafeWrite mv 14 (toO o)
875+ return mv
876+ {-# INLINE liftToJSON2 #-}
877+
878+ liftToEncoding2 toN toO (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) = tuple $
879+ builder a >*<
880+ builder b >*<
881+ builder c >*<
882+ builder d >*<
883+ builder e >*<
884+ builder f >*<
885+ builder g >*<
886+ builder h >*<
887+ builder i >*<
888+ builder j >*<
889+ builder k >*<
890+ builder l >*<
891+ builder m >*<
892+ fromEncoding (toN n) >*<
893+ fromEncoding (toO o)
894+ {-# INLINE liftToEncoding2 #-}
895+
896+instance (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
897+ liftToJSON = liftToJSON2 toJSON
898+ {-# INLINE liftToJSON #-}
899+ liftToEncoding = liftToEncoding2 toEncoding
900+ {-# INLINE liftToEncoding #-}
901+
902+instance (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, ToJSON o) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where
903+ toJSON = toJSON2
904+ {-# INLINE toJSON #-}
905+ toEncoding = toEncoding2
906+ {-# INLINE toEncoding #-}
907+
908+instance (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) => FromJSON2 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m) where
909+ liftParseJSON2 pN pO = withArray "(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)" $ \t ->
910+ let n = V.length t
911+ in if n == 15
912+ then (,,,,,,,,,,,,,,)
913+ <$> parseJSONElemAtIndex parseJSON 0 t
914+ <*> parseJSONElemAtIndex parseJSON 1 t
915+ <*> parseJSONElemAtIndex parseJSON 2 t
916+ <*> parseJSONElemAtIndex parseJSON 3 t
917+ <*> parseJSONElemAtIndex parseJSON 4 t
918+ <*> parseJSONElemAtIndex parseJSON 5 t
919+ <*> parseJSONElemAtIndex parseJSON 6 t
920+ <*> parseJSONElemAtIndex parseJSON 7 t
921+ <*> parseJSONElemAtIndex parseJSON 8 t
922+ <*> parseJSONElemAtIndex parseJSON 9 t
923+ <*> parseJSONElemAtIndex parseJSON 10 t
924+ <*> parseJSONElemAtIndex parseJSON 11 t
925+ <*> parseJSONElemAtIndex parseJSON 12 t
926+ <*> parseJSONElemAtIndex pN 13 t
927+ <*> parseJSONElemAtIndex pO 14 t
928+ else fail $ "cannot unpack array of length " ++ show n ++ " into a tuple of length 15"
929+ {-# INLINE liftParseJSON2 #-}
930+
931+instance (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) => FromJSON1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) where
932+ liftParseJSON = liftParseJSON2 parseJSON
933+ {-# INLINE liftParseJSON #-}
934+
935+instance (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
937+ {-# INLINE parseJSON #-}
aeson.cabal+1
@@ -85,6 +85,7 @@ library
8585 Data.Aeson.Types.Class
8686 Data.Aeson.Types.Generic
8787 Data.Aeson.Types.Instances
88+ Data.Aeson.Types.Instances.Tuple
8889 Data.Aeson.Types.Internal
8990
9091 build-depends:
tuple-instances.hsnew file+126
@@ -0,0 +1,126 @@
1+#!/usr/bin/env stack
2+{- stack --resolver=lts-5.9 runghc
3+ --package mtl
4+ --package dlist
5+-}
6+
7+import Control.Monad (forM_)
8+import Control.Monad.State.Strict
9+import Control.Monad.Writer (MonadWriter (..))
10+import Data.Char (toUpper)
11+import Data.Foldable (fold, traverse_)
12+import Data.List (intercalate)
13+import Data.Semigroup ((<>))
14+
15+import qualified Data.DList as DList
16+
17+variables :: [String]
18+variables = map (:[]) $ ['a'..'z']
19+
20+t :: [String] -> State (DList.DList String) ()
21+t xs = traverse_ f xs *> f "\n"
22+ where
23+ f :: String -> State (DList.DList String) ()
24+ f x = state (\s -> ((), mappend s $ DList.singleton x))
25+
26+commaSep :: [String] -> String
27+commaSep vs = "(" <> intercalate ", " vs <> ")"
28+
29+tuple :: Int -> String
30+tuple n = fold $ flip execState DList.empty $ do
31+ -- ToJSON2
32+ t ["instance ", toJsonContext2, "ToJSON2 (", tupleConstr, " ", vs2, ") where" ]
33+ t [" liftToJSON2 ", toPrev, " ", toLast, " ", vs', " = Array $ V.create $ do" ]
34+ t [" mv <- VM.unsafeNew ", show n ]
35+ forM_ (zip [0..] vs) $ \(i, v) ->
36+ let to = case i of
37+ _ | i == n - 1 -> toLast
38+ | i == n - 2 -> toPrev
39+ | otherwise -> "toJSON"
40+ in t [ " VM.unsafeWrite mv ", show i, " (", to, " ", v, ")" ]
41+ t [" return mv" ]
42+ t [" {-# INLINE liftToJSON2 #-}" ]
43+ t []
44+
45+ t [" liftToEncoding2 ", toPrev, " ", toLast, " ", vs', " = tuple $" ]
46+ forM_ (zip [0..] vs) $ \(i, v) -> t . (" " :) $ case i of
47+
48+ _ | i == n - 1 -> [ "fromEncoding (", toLast, " ", v, ")" ]
49+ _ | i == n - 2 -> [ "fromEncoding (", toPrev, " ", v, ") >*<" ]
50+ _ | otherwise -> [ "builder ", v, " >*<" ]
51+ t [" {-# INLINE liftToEncoding2 #-}" ]
52+ t []
53+
54+ -- ToJSON1
55+ t ["instance ", toJsonContext1, "ToJSON1 (", tupleConstr, " ", vs1, ") where" ]
56+ t [" liftToJSON = liftToJSON2 toJSON" ]
57+ t [" {-# INLINE liftToJSON #-}" ]
58+ t [" liftToEncoding = liftToEncoding2 toEncoding" ]
59+ t [" {-# INLINE liftToEncoding #-}" ]
60+ t []
61+
62+ -- ToJSON
63+ t [ "instance ", toJsonContext, " => ToJSON ", vs', " where" ]
64+ t [ " toJSON = toJSON2" ]
65+ t [ " {-# INLINE toJSON #-}" ]
66+ t [ " toEncoding = toEncoding2" ]
67+ t [ " {-# INLINE toEncoding #-}" ]
68+ t []
69+
70+ -- FromJSON2
71+ t ["instance ", fromJsonContext2, "FromJSON2 (", tupleConstr, " ", vs2, ") where" ]
72+ t [" liftParseJSON2 ", pPrev, " ", pLast, " = withArray \"", vs', "\" $ \\t -> " ]
73+ t [" let n = V.length t" ]
74+ t [" in if n == ", show n ]
75+ t [" then ", tupleConstr ]
76+ forM_ (zip [0..] vs) $ \(i, v) -> do
77+ let op = if i == 0 then "<$>" else "<*>"
78+ let p = case i of
79+ _ | i == n - 1 -> pLast
80+ | i == n - 2 -> pPrev
81+ | otherwise -> "parseJSON"
82+ t [" ", op, " parseJSONElemAtIndex ", p, " ", show i, " t" ]
83+ t [" else fail $ \"cannot unpack array of length \" ++ show n ++ \" into a tuple of length ", show n, "\"" ]
84+ t [" {-# INLINE liftParseJSON2 #-}" ]
85+ t []
86+
87+ -- FromJSON1
88+ t ["instance ", fromJsonContext1, "FromJSON1 (", tupleConstr, " ", vs1, ") where" ]
89+ t [" liftParseJSON = liftParseJSON2 parseJSON" ]
90+ t [" {-# INLINE liftParseJSON #-}" ]
91+ t []
92+
93+ -- FeomJSON
94+ t [ "instance ", fromJsonContext, " => FromJSON ", vs', " where" ]
95+ t [ " parseJSON = parseJSON2" ]
96+ t [ " {-# INLINE parseJSON #-}" ]
97+ t []
98+
99+ t []
100+ where
101+ vs = take n variables
102+ vs' = commaSep vs
103+ toJsonContext = commaSep $ map ("ToJSON " <>) vs
104+ fromJsonContext = commaSep $ map ("FromJSON " <>) vs
105+
106+ toJsonContext2
107+ | n <= 2 = ""
108+ | otherwise = (commaSep $ map ("ToJSON " <>) $ take (n - 2) vs) <> " => "
109+ fromJsonContext2
110+ | n <= 2 = ""
111+ | otherwise = (commaSep $ map ("FromJSON " <>) $ take (n - 2) vs) <> " => "
112+ vs2 = intercalate " " $ take (n - 2) vs
113+
114+ toJsonContext1 = (commaSep $ map ("ToJSON " <>) $ take (n - 1) vs) <> " => "
115+ fromJsonContext1 = (commaSep $ map ("FromJSON " <>) $ take (n - 1) vs) <> " => "
116+ vs1 = intercalate " " $ take (n - 1) vs
117+
118+ toLast = "to" <> map toUpper (vs !! (n - 1))
119+ toPrev = "to" <> map toUpper (vs !! (n - 2))
120+ pLast = "p" <> map toUpper (vs !! (n - 1))
121+ pPrev = "p" <> map toUpper (vs !! (n - 2))
122+
123+ tupleConstr = "(" <> intercalate "," (replicate n "") <> ")"
124+
125+main :: IO ()
126+main = forM_ [2..15] $ putStr . tuple