derive 2.5.18 → 2.5.19
raw patch · 15 files changed
+34/−18 lines, 15 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Language.Haskell: isIdent :: [Char] -> Bool
- Data.Derive.DSL.HSE: coerce :: (Typeable a1, Typeable a) => a1 -> a
+ Data.Derive.DSL.HSE: coerce :: (Typeable * a1, Typeable * a) => a1 -> a
- Data.Derive.UniplateTypeable: custom :: (t, Decl) -> [Decl] -> [Decl]
+ Data.Derive.UniplateTypeable: custom :: (t, DataDecl) -> [Decl] -> [Decl]
- Language.Haskell.TH.FixedPpr: ppr_sig :: (Ppr a, Ppr a1) => a -> a1 -> Doc
+ Language.Haskell.TH.FixedPpr: ppr_sig :: (Ppr a1, Ppr a) => a -> a1 -> Doc
Files
- CHANGES.txt +2/−0
- Data/Derive/Fold.hs +2/−1
- Data/Derive/From.hs +2/−1
- Data/Derive/Has.hs +1/−1
- Data/Derive/Is.hs +1/−1
- Data/Derive/LazySet.hs +1/−1
- Data/Derive/Lens.hs +1/−1
- Data/Derive/Ref.hs +1/−1
- Data/DeriveTH.hs +8/−1
- Derive/Test.hs +6/−4
- Language/Haskell.hs +1/−0
- Language/Haskell/Convert.hs +2/−0
- Language/Haskell/TH/FixedPpr.hs +3/−3
- README.md +1/−1
- derive.cabal +2/−2
CHANGES.txt view
@@ -1,5 +1,7 @@ Changelog for Derive +2.5.19+ Support GHC 7.10 2.5.18 #4, fix the read instance for nullary constructors 2.5.17
Data/Derive/Fold.hs view
@@ -47,7 +47,8 @@ mkFold :: DataDecl -> [Decl]-mkFold d = [TypeSig sl [name n] (foldType d), FunBind $ zipWith f [0..] $ dataDeclCtors d]+mkFold d | isIdent $ dataDeclName d = [TypeSig sl [name n] (foldType d), FunBind $ zipWith f [0..] $ dataDeclCtors d]+ | otherwise = [] where n = "fold" ++ title (dataDeclName d) f i c = Match sl (name n) pat Nothing (UnGuardedRhs bod) (BDecls [])
Data/Derive/From.hs view
@@ -37,7 +37,8 @@ makeFromCtor :: DataDecl -> CtorDecl -> [Decl]-makeFromCtor d c = [TypeSig sl [name from] typ, FunBind $ match : [defMatch | length (dataDeclCtors d) > 1]]+makeFromCtor d c | isIdent n = [TypeSig sl [name from] typ, FunBind $ match : [defMatch | length (dataDeclCtors d) > 1]]+ | otherwise = [] where n = ctorDeclName c from = "from" ++ n
Data/Derive/Has.hs view
@@ -29,7 +29,7 @@ makeHasField :: DataDecl -> String -> [Decl]-makeHasField d field = [TypeSig sl [name has] typ, binds has ms]+makeHasField d field = if isIdent field then [TypeSig sl [name has] typ, binds has ms] else [] where has = "has" ++ title field typ = TyFun (dataDeclType d) (tyCon "Bool")
Data/Derive/Is.hs view
@@ -23,7 +23,7 @@ makeIsCtor :: DataDecl -> CtorDecl -> [Decl]-makeIsCtor d c =+makeIsCtor d c = if not $ isIdent $ ctorDeclName c then [] else [TypeSig sl [name nam] (dataDeclType d `TyFun` tyCon "Bool") ,FunBind $ match : [defMatch | length (dataDeclCtors d) > 1]] where
Data/Derive/LazySet.hs view
@@ -28,7 +28,7 @@ makeLazySetField :: DataDecl -> String -> [Decl]-makeLazySetField d field = [TypeSig sl [name fun] typ, bind fun [pVar "v",pVar "x"] bod]+makeLazySetField d field = if isIdent field then [TypeSig sl [name fun] typ, bind fun [pVar "v",pVar "x"] bod] else [] where fun = "set" ++ title field typ = t `TyFun` (dataDeclType d `TyFun` dataDeclType d)
Data/Derive/Lens.hs view
@@ -30,7 +30,7 @@ makeLensField :: DataDecl -> String -> [Decl]-makeLensField d field = [TypeSig sl [name ref] typ, bind ref [] bod]+makeLensField d field = if isIdent field then [TypeSig sl [name ref] typ, bind ref [] bod] else [] where ref = "lens" ++ title field typ = tyApps (tyCon "Lens") [dataDeclType d, t]
Data/Derive/Ref.hs view
@@ -30,7 +30,7 @@ makeRefField :: DataDecl -> String -> [Decl]-makeRefField d field = [TypeSig sl [name ref] typ, bind ref [] bod]+makeRefField d field = if isIdent field then [TypeSig sl [name ref] typ, bind ref [] bod] else [] where ref = "ref" ++ title field typ = TyApp (tyCon "Ref") (dataDeclType d)
Data/DeriveTH.hs view
@@ -14,7 +14,9 @@ import Language.Haskell.TH.All as TH hiding (Derivation(..),toName) import Language.Haskell as HS import Language.Haskell.Convert+import Data.Generics + -- | Derive an instance of some class. @derive@ only derives instances -- for the type of the argument. derive :: Derivation -> TH.Name -> Q [Dec]@@ -33,12 +35,17 @@ -- for the type of the argument. deriveFromDec :: Derivation -> Dec -> Q [Dec] deriveFromDec d x = do- x <- liftM normData $ expandData x+ x <- fmap unkind $ liftM normData $ expandData x let unsup x = error $ "Derivation of " ++ derivationName d ++ " does not yet support Template Haskell, requires info for " ++ x case derivationOp d (tyCon $ derivationName d) unsup $ toFullDataDecl x of Left y -> runIO (putStrLn $ "Warning, couldn't derive: " ++ y) >> return [] Right v -> return $ convert v +unkind :: Dec -> Dec+unkind = everywhere (mkT f)+ where+ f (KindedTV x _) = PlainTV x+ f x = x toFullDataDecl :: Dec -> FullDataDecl toFullDataDecl x = (ModuleName "Todo", convert x)
Derive/Test.hs view
@@ -21,10 +21,11 @@ -- REASONS: -- UniplateDirect: Doesn't work through Template Haskell-exclude = ["ArbitraryOld","UniplateDirect","Ref","Serial","Binary"]+-- Typeable cannot be separately derived in GHC 7.8+exclude = ["ArbitraryOld","UniplateDirect","Ref","Serial","Binary","Typeable"] -- These must be first and in every set-priority = ["Eq","Typeable"]+priority = ["Eq"] listType :: Decl@@ -82,14 +83,15 @@ autoTest :: String -> [DataDecl] -> [(Derivation,Src)] -> IO () autoTest name ts ds = writeFile (name++".hs") $ unlines $- ["{-# LANGUAGE TemplateHaskell,FlexibleInstances,MultiParamTypeClasses,TypeOperators #-}"+ ["{-# LANGUAGE TemplateHaskell,FlexibleInstances,MultiParamTypeClasses,TypeOperators,DeriveDataTypeable #-}" ,"{-# OPTIONS_GHC -Wall -fno-warn-missing-fields -fno-warn-unused-imports #-}" ,"module " ++ name ++ " where" ,"import Prelude" ,"import Data.DeriveTH"+ ,"import Data.Typeable" ,"import Derive.TestInstances()"] ++ [prettyPrint i | (_,s) <- ds, i <- srcImportStd s] ++- [prettyPrint t | t <- ts2] +++ [prettyPrint t ++ "\n deriving Typeable" | t <- ts2] ++ ["$(derives [make" ++ derivationName d ++ "] " ++ types ++ ")" | (d,_) <- ds] where types = "[" ++ intercalate "," ["''" ++ dataDeclName t | t <- ts2] ++ "]"
Language/Haskell.hs view
@@ -182,6 +182,7 @@ noSl mr = transformBi (const sl) mr +isIdent (x:xs) = isAlpha x || x == '_' title (x:xs) = toUpper x : xs qname = UnQual . name
Language/Haskell/Convert.hs view
@@ -24,6 +24,7 @@ +appT :: TH.Type -> [TH.Type] -> TH.Type appT = foldl AppT c mr = convert mr@@ -38,6 +39,7 @@ DataD cxt n vs con ds -> f DataType cxt n vs con ds NewtypeD cxt n vs con ds -> f NewType cxt n vs [con] ds where+ f :: DataOrNew -> Cxt -> TH.Name -> [TyVarBndr] -> [Con] -> [TH.Name] -> HS.Decl f t cxt n vs con ds = DataDecl sl t (c cxt) (c n) (c vs) (c con) [] instance Convert TH.Name HS.TyVarBind where
Language/Haskell/TH/FixedPpr.hs view
@@ -78,9 +78,9 @@ ppr (TyConI d) = ppr d ppr (PrimTyConI name arity is_unlifted) = text "Primitive"- <+> (if is_unlifted then text "unlifted" else empty)- <+> text "type construtor" <+> quotes (ppr name)- <+> parens (text "arity" <+> int arity)+ <+> (if is_unlifted then text "unlifted" else empty)+ <+> text "type construtor" <+> quotes (ppr name)+ <+> parens (text "arity" <+> int arity) ppr (ClassOpI v ty cls fix) = text "Class op from" <+> ppr cls <> colon <+> vcat [ppr_sig v ty, pprFixity v fix]
README.md view
@@ -1,4 +1,4 @@-# Derive [](http://hackage.haskell.org/package/derive) [](https://travis-ci.org/ndmitchell/derive)+# Derive [](https://hackage.haskell.org/package/derive) [](https://travis-ci.org/ndmitchell/derive) Data.Derive is a library and a tool for deriving instances for Haskell programs. It is designed to work with custom derivations, SYB and Template Haskell mechanisms. The tool requires GHC, but the generated code is portable to all compilers. We see this tool as a competitor to <a href="http://repetae.net/~john/computer/haskell/DrIFT/">DrIFT</a>.
derive.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.6 build-type: Default name: derive-version: 2.5.18+version: 2.5.19 build-type: Simple copyright: Neil Mitchell 2006-2014 author: Neil Mitchell <ndmitchell@gmail.com>@@ -20,7 +20,7 @@ extra-source-files: README.md CHANGES.txt-tested-with: GHC==7.8.2, GHC==7.6.3, GHC==7.4.2+tested-with: GHC==7.10.1, GHC==7.8.3, GHC==7.6.3, GHC==7.4.2 source-repository head type: git