packages feed

aeson-gadt-th 0.1.0.0 → 0.1.1.0

raw patch · 2 files changed

+15/−6 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

aeson-gadt-th.cabal view
@@ -1,9 +1,9 @@ cabal-version: >=1.10 name: aeson-gadt-th-version: 0.1.0.0+version: 0.1.1.0 synopsis: Derivation of Aeson instances for GADTs category: JSON-description: Template Haskell for generating ToJSON and FromJSON instances for GADTs+description: Template Haskell for generating ToJSON and FromJSON instances for GADTs. See <https://github.com/obsidiansystems/aeson-gadt-th/blob/master/README.md README.md> for examples. license: BSD3 license-file: LICENSE author: Obsidian Systems LLC
src/Data/Aeson/GADT/TH.hs view
@@ -127,10 +127,19 @@ conMatchesParseJSON e c = do   let name = conName c       match' = match (litP (StringL (nameBase name)))-  vars <- replicateM (conArity c) (newName "x")-  let forTypes _ = do-        let pat = tupP (map varP vars)-            conApp = foldl appE (conE name) (map varE vars)+  let forTypes types = do+        vars <- forM types $ \typ -> do+          x <- newName "x"+          case typ of+            AppT (ConT tn) (VarT vn) -> do+              -- This may be a nested GADT, so check for special FromJSON instance+              idec <- reifyInstances ''FromJSON [AppT (ConT ''Some) (ConT tn)]+              return $ case idec of+                [] -> (VarP x, VarE x)+                _ -> (ConP 'This [VarP x], VarE x) -- If a FromJSON instance is found for Some f, then we use it.+            _ -> return (VarP x, VarE x)+        let pat = return $ TupP (map fst vars)+            conApp = return $ foldl AppE (ConE name) (map snd vars)             body = doE [ bindS pat [| parseJSON $e |]                        , noBindS [| return (This $conApp) |]                        ]