Source

aeson / Data / Aeson / TH.hs

The default branch has multiple heads

Diff from to

File Data/Aeson/TH.hs

   where
     fromCons :: [TyVarBndr] -> [Con] -> Q Dec
     fromCons tvbs cons =
-#if __GLASGOW_HASKELL__ >= 709
-        instanceD (return $ map (\t -> AppT (ConT ''ToJSON) (VarT t)) typeNames)
-#else
-        instanceD (return $ map (\t -> ClassP ''ToJSON [VarT t]) typeNames)
-#endif
+        instanceD (applyCon ''ToJSON typeNames)
                   (classType `appT` instanceType)
                   [ funD 'toJSON
                          [ clause []
   where
     fromCons :: [TyVarBndr] -> [Con] -> Q Dec
     fromCons tvbs cons =
-#if __GLASGOW_HASKELL__ >= 709
-        instanceD (return $ map (\t -> AppT (ConT ''FromJSON) (VarT t)) typeNames)
-#else
-        instanceD (return $ map (\t -> ClassP ''FromJSON [VarT t]) typeNames)
-#endif
+        instanceD (applyCon ''FromJSON typeNames)
                   (classType `appT` instanceType)
                   [ funD 'parseJSON
                          [ clause []
 valueConName (Number _) = "Number"
 valueConName (Bool   _) = "Boolean"
 valueConName Null       = "Null"
+
+applyCon :: Name -> [Name] -> Q [Pred]
+applyCon con typeNames = return (map apply typeNames)
+  where apply t =
+#if __GLASGOW_HASKELL__ >= 709
+          AppT (ConT con) (VarT t)
+#else
+          ClassP con [VarT t]
+#endif