@@ -408,8 +408,8 @@ encStr opts = appE [|E.text|] . conTxt opts
408
408
409
409
-- | If constructor is nullary.
410
410
isNullary :: ConstructorInfo -> Bool
411
- isNullary ( ConstructorInfo { constructorVariant = NormalConstructor
412
- , constructorFields = tys }) = null tys
411
+ isNullary ConstructorInfo { constructorVariant = NormalConstructor
412
+ , constructorFields = tys } = null tys
413
413
isNullary _ = False
414
414
415
415
sumToValue :: Options -> Bool -> Bool -> Name -> Q Exp -> Q Exp
@@ -436,9 +436,9 @@ argsToValue :: JSONClass -> TyVarMap -> Options -> Bool -> ConstructorInfo -> Q
436
436
437
437
-- Polyadic constructors with special case for unary constructors.
438
438
argsToValue jc tvMap opts multiCons
439
- ( ConstructorInfo { constructorName = conName
440
- , constructorVariant = NormalConstructor
441
- , constructorFields = argTys }) = do
439
+ ConstructorInfo { constructorName = conName
440
+ , constructorVariant = NormalConstructor
441
+ , constructorFields = argTys } = do
442
442
argTys' <- mapM resolveTypeSynonyms argTys
443
443
let len = length argTys'
444
444
args <- newNameList " arg" len
@@ -471,9 +471,9 @@ argsToValue jc tvMap opts multiCons
471
471
472
472
-- Records.
473
473
argsToValue jc tvMap opts multiCons
474
- info@ ( ConstructorInfo { constructorName = conName
475
- , constructorVariant = RecordConstructor fields
476
- , constructorFields = argTys }) =
474
+ info@ ConstructorInfo { constructorName = conName
475
+ , constructorVariant = RecordConstructor fields
476
+ , constructorFields = argTys } =
477
477
case (unwrapUnaryRecords opts, not multiCons, argTys) of
478
478
(True ,True ,[_]) -> argsToValue jc tvMap opts multiCons
479
479
(info{constructorVariant = NormalConstructor })
@@ -533,9 +533,9 @@ argsToValue jc tvMap opts multiCons
533
533
534
534
-- Infix constructors.
535
535
argsToValue jc tvMap opts multiCons
536
- ( ConstructorInfo { constructorName = conName
537
- , constructorVariant = InfixConstructor
538
- , constructorFields = argTys }) = do
536
+ ConstructorInfo { constructorName = conName
537
+ , constructorVariant = InfixConstructor
538
+ , constructorFields = argTys } = do
539
539
[alTy, arTy] <- mapM resolveTypeSynonyms argTys
540
540
al <- newName " argL"
541
541
ar <- newName " argR"
@@ -595,12 +595,11 @@ argsToEncoding :: JSONClass -> TyVarMap -> Options -> Bool -> ConstructorInfo ->
595
595
596
596
-- Polyadic constructors with special case for unary constructors.
597
597
argsToEncoding jc tvMap opts multiCons
598
- ( ConstructorInfo { constructorName = conName
599
- , constructorVariant = NormalConstructor
600
- , constructorFields = argTys }) = do
598
+ ConstructorInfo { constructorName = conName
599
+ , constructorVariant = NormalConstructor
600
+ , constructorFields = argTys } = do
601
601
argTys' <- mapM resolveTypeSynonyms argTys
602
- let len = length argTys'
603
- args <- newNameList " arg" len
602
+ args <- newNameList " arg" $ length argTys'
604
603
js <- case zip args argTys' of
605
604
-- Nullary constructors are converted to an empty array.
606
605
[] -> return [| E. emptyArray_ | ]
@@ -620,9 +619,9 @@ argsToEncoding jc tvMap opts multiCons
620
619
621
620
-- Records.
622
621
argsToEncoding jc tvMap opts multiCons
623
- info@ ( ConstructorInfo { constructorName = conName
624
- , constructorVariant = RecordConstructor fields
625
- , constructorFields = argTys }) = do
622
+ info@ ConstructorInfo { constructorName = conName
623
+ , constructorVariant = RecordConstructor fields
624
+ , constructorFields = argTys } =
626
625
case (unwrapUnaryRecords opts, not multiCons, argTys) of
627
626
(True ,True ,[_]) -> argsToEncoding jc tvMap opts multiCons
628
627
(info{constructorVariant = NormalConstructor })
@@ -684,9 +683,9 @@ argsToEncoding jc tvMap opts multiCons
684
683
685
684
-- Infix constructors.
686
685
argsToEncoding jc tvMap opts multiCons
687
- ( ConstructorInfo { constructorName = conName
688
- , constructorVariant = InfixConstructor
689
- , constructorFields = argTys }) = do
686
+ ConstructorInfo { constructorName = conName
687
+ , constructorVariant = InfixConstructor
688
+ , constructorFields = argTys } = do
690
689
al <- newName " argL"
691
690
ar <- newName " argR"
692
691
[alTy,arTy] <- mapM resolveTypeSynonyms argTys
@@ -910,9 +909,9 @@ consFromJSON jc tName opts vars cons = do
910
909
(map (\ x -> parseValue tvMap x conVal) cons')
911
910
912
911
parseValue _tvMap
913
- ( ConstructorInfo { constructorName = conName
914
- , constructorVariant = NormalConstructor
915
- , constructorFields = [] })
912
+ ConstructorInfo { constructorName = conName
913
+ , constructorVariant = NormalConstructor
914
+ , constructorFields = [] }
916
915
conVal = do
917
916
str <- newName " str"
918
917
caseE (varE conVal)
@@ -1093,49 +1092,49 @@ parseArgs :: JSONClass -- ^ The FromJSON variant being derived.
1093
1092
-> Q Exp
1094
1093
-- Nullary constructors.
1095
1094
parseArgs _ _ _ _
1096
- ( ConstructorInfo { constructorName = conName
1097
- , constructorVariant = NormalConstructor
1098
- , constructorFields = [] })
1095
+ ConstructorInfo { constructorName = conName
1096
+ , constructorVariant = NormalConstructor
1097
+ , constructorFields = [] }
1099
1098
(Left _) =
1100
1099
[| pure | ] `appE` conE conName
1101
1100
parseArgs _ _ tName _
1102
- ( ConstructorInfo { constructorName = conName
1103
- , constructorVariant = NormalConstructor
1104
- , constructorFields = [] })
1101
+ ConstructorInfo { constructorName = conName
1102
+ , constructorVariant = NormalConstructor
1103
+ , constructorFields = [] }
1105
1104
(Right valName) =
1106
1105
caseE (varE valName) $ parseNullaryMatches tName conName
1107
1106
1108
1107
-- Unary constructors.
1109
1108
parseArgs jc tvMap _ _
1110
- ( ConstructorInfo { constructorName = conName
1111
- , constructorVariant = NormalConstructor
1112
- , constructorFields = [argTy] })
1109
+ ConstructorInfo { constructorName = conName
1110
+ , constructorVariant = NormalConstructor
1111
+ , constructorFields = [argTy] }
1113
1112
contents = do
1114
1113
argTy' <- resolveTypeSynonyms argTy
1115
1114
matchCases contents $ parseUnaryMatches jc tvMap argTy' conName
1116
1115
1117
1116
-- Polyadic constructors.
1118
1117
parseArgs jc tvMap tName _
1119
- ( ConstructorInfo { constructorName = conName
1120
- , constructorVariant = NormalConstructor
1121
- , constructorFields = argTys })
1118
+ ConstructorInfo { constructorName = conName
1119
+ , constructorVariant = NormalConstructor
1120
+ , constructorFields = argTys }
1122
1121
contents = do
1123
1122
argTys' <- mapM resolveTypeSynonyms argTys
1124
1123
let len = genericLength argTys'
1125
1124
matchCases contents $ parseProduct jc tvMap argTys' tName conName len
1126
1125
1127
1126
-- Records.
1128
1127
parseArgs jc tvMap tName opts
1129
- ( ConstructorInfo { constructorName = conName
1130
- , constructorVariant = RecordConstructor fields
1131
- , constructorFields = argTys })
1128
+ ConstructorInfo { constructorName = conName
1129
+ , constructorVariant = RecordConstructor fields
1130
+ , constructorFields = argTys }
1132
1131
(Left (_, obj)) = do
1133
1132
argTys' <- mapM resolveTypeSynonyms argTys
1134
1133
parseRecord jc tvMap argTys' opts tName conName fields obj
1135
1134
parseArgs jc tvMap tName opts
1136
- info@ ( ConstructorInfo { constructorName = conName
1137
- , constructorVariant = RecordConstructor fields
1138
- , constructorFields = argTys })
1135
+ info@ ConstructorInfo { constructorName = conName
1136
+ , constructorVariant = RecordConstructor fields
1137
+ , constructorFields = argTys }
1139
1138
(Right valName) =
1140
1139
case (unwrapUnaryRecords opts,argTys) of
1141
1140
(True ,[_])-> parseArgs jc tvMap tName opts
@@ -1153,9 +1152,9 @@ parseArgs jc tvMap tName opts
1153
1152
-- Infix constructors. Apart from syntax these are the same as
1154
1153
-- polyadic constructors.
1155
1154
parseArgs jc tvMap tName _
1156
- ( ConstructorInfo { constructorName = conName
1157
- , constructorVariant = InfixConstructor
1158
- , constructorFields = argTys })
1155
+ ConstructorInfo { constructorName = conName
1156
+ , constructorVariant = InfixConstructor
1157
+ , constructorFields = argTys }
1159
1158
contents = do
1160
1159
argTys' <- mapM resolveTypeSynonyms argTys
1161
1160
matchCases contents $ parseProduct jc tvMap argTys' tName conName 2
0 commit comments