Skip to content

Commit

Permalink
Reduce duplication, simplify CPP macros
Browse files Browse the repository at this point in the history
  • Loading branch information
bos committed Mar 11, 2014
1 parent 19682fe commit b000e67
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Data/Aeson/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ deriveToJSON opts name =
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 []
Expand Down Expand Up @@ -376,11 +372,7 @@ deriveFromJSON opts name =
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 []
Expand Down Expand Up @@ -880,3 +872,12 @@ valueConName (String _) = "String"
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

0 comments on commit b000e67

Please sign in to comment.