packages feed

classyplate 0.2.0.0 → 0.2.1.0

raw patch · 2 files changed

+10/−7 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

classyplate.cabal view
@@ -1,5 +1,5 @@ name:                classyplate
-version:             0.2.0.0
+version:             0.2.1.0
 synopsis:            Fuseable type-class based generics
 -- description:         
 license:             BSD3
src/Data/Generics/ClassyPlate/TH.hs view
@@ -16,12 +16,15 @@ makeClassyPlate :: [Name] -> Name -> Q [Dec]
 makeClassyPlate primitives dataType 
   = do inf <- reify dataType
-       case inf of (TyConI (DataD _ name tvs _ cons _)) 
-                     -> let headType = foldl AppT (ConT name) (map (VarT . getTVName) tvs)
-                         in return $ [ makeNormalCPForDataType name headType tvs (map (getConRep primitives) cons)
-                                     , makeAutoCPForDataType name headType tvs (map (getConRep primitives) cons)
-                                     , makeIgnoredFieldsTF headType primitives
-                                     ]
+       case inf of (TyConI (DataD _ name tvs _ cons _)) -> createClassyPlate name tvs cons
+                   (TyConI (NewtypeD _ name tvs _ con _)) -> createClassyPlate name tvs [con]
+                   _ -> error $ "Cannot create classyplate for " ++ show dataType ++ " only data and newtype declarations are supported."
+  where createClassyPlate name tvs cons 
+          = let headType = foldl AppT (ConT name) (map (VarT . getTVName) tvs)
+             in return $ [ makeNormalCPForDataType name headType tvs (map (getConRep primitives) cons)
+                         , makeAutoCPForDataType name headType tvs (map (getConRep primitives) cons)
+                         , makeIgnoredFieldsTF headType primitives
+                         ]
 
 makeNormalCPForDataType :: Name -> Type -> [TyVarBndr] -> [ConRep] -> Dec
 makeNormalCPForDataType name headType tvs cons