packages feed

recursion-schemes 5.0.2 → 5.0.3

raw patch · 8 files changed

+310/−190 lines, 8 filesdep +th-abstractiondep ~basedep ~base-orphansdep ~semigroups

Dependencies added: th-abstraction

Dependency ranges changed: base, base-orphans, semigroups, template-haskell, transformers

Files

.gitignore view
@@ -19,3 +19,11 @@ codex.tags src/highlight.js src/style.css+*.prof+*.aux+*.hp+*.eventlog+cabal.project.local+cabal.project.local~+.HTF/+.ghc.environment.*
.travis.yml view
@@ -1,91 +1,151 @@-# This file has been generated -- see https://github.com/hvr/multi-ghc-travis+# This Travis job script has been generated by a script via+#+#   runghc make_travis_yml_2.hs '-o' '.travis.yml' '--ghc-head' '--irc-channel=irc.freenode.org#haskell-lens' '--no-no-tests-no-bench' '--no-unconstrained' 'cabal.project'+#+# For more information, see https://github.com/hvr/multi-ghc-travis+# language: c sudo: false +git:+  submodules: false  # whether to recursively clone submodules++notifications:+  irc:+    channels:+      - "irc.freenode.org#haskell-lens"+    skip_join: true+    template:+      - "\x0313recursion-schemes\x03/\x0306%{branch}\x03 \x0314%{commit}\x03 %{build_url} %{message}"+ cache:   directories:-    - $HOME/.cabsnap     - $HOME/.cabal/packages+    - $HOME/.cabal/store  before_cache:   - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log-  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar+  # remove files that are regenerated by 'cabal update'+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx +  - rm -rfv $HOME/.cabal/packages/head.hackage+ matrix:   include:-    - env: CABALVER=1.16 GHCVER=7.4.2-      compiler: ": #GHC 7.4.2"-      addons: {apt: {packages: [cabal-install-1.16,ghc-7.4.2], sources: [hvr-ghc]}}-    - env: CABALVER=1.16 GHCVER=7.6.3-      compiler: ": #GHC 7.6.3"-      addons: {apt: {packages: [cabal-install-1.16,ghc-7.6.3], sources: [hvr-ghc]}}-    - env: CABALVER=1.18 GHCVER=7.8.4-      compiler: ": #GHC 7.8.4"-      addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4], sources: [hvr-ghc]}}-    - env: CABALVER=1.22 GHCVER=7.10.3-      compiler: ": #GHC 7.10.3"-      addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3], sources: [hvr-ghc]}}-    - env: CABALVER=1.24 GHCVER=8.0.2-      compiler: ": #GHC 8.0.2"-      addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.2], sources: [hvr-ghc]}}-    - env: CABALVER=2.0 GHCVER=8.2.1-      compiler: ": #GHC 8.2.1"-      addons: {apt: {packages: [cabal-install-2.0,ghc-8.2.1], sources: [hvr-ghc]}}+    - compiler: "ghc-8.6.1"+      env: GHCHEAD=true+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.6.1], sources: [hvr-ghc]}}+    - compiler: "ghc-8.4.3"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-8.4.3], sources: [hvr-ghc]}}+    - compiler: "ghc-8.2.2"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-8.2.2], sources: [hvr-ghc]}}+    - compiler: "ghc-8.0.2"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-8.0.2], sources: [hvr-ghc]}}+    - compiler: "ghc-7.10.3"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.10.3], sources: [hvr-ghc]}}+    - compiler: "ghc-7.8.4"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.8.4], sources: [hvr-ghc]}}+    - compiler: "ghc-7.6.3"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.6.3], sources: [hvr-ghc]}}+    - compiler: "ghc-7.4.2"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.2,ghc-7.4.2], sources: [hvr-ghc]}}+    - compiler: "ghc-head"+      env: GHCHEAD=true+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-head], sources: [hvr-ghc]}} +  allow_failures:+    - compiler: "ghc-head"+    - compiler: "ghc-8.6.1"+ before_install:- - unset CC- - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH+  - HC=${CC}+  - HCPKG=${HC/ghc/ghc-pkg}+  - unset CC+  - ROOTDIR=$(pwd)+  - mkdir -p $HOME/.local/bin+  - "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH"+  - HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))+  - echo $HCNUMVER  install:- - cabal --version- - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"- - if [ -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz ];-   then-     zcat $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz >-          $HOME/.cabal/packages/hackage.haskell.org/00-index.tar;-   fi- - travis_retry cabal update -v- - sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config- - cabal install --only-dependencies --enable-tests --enable-benchmarks --dry -v > installplan.txt- - sed -i -e '1,/^Resolving /d' installplan.txt; cat installplan.txt+  - cabal --version+  - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"+  - BENCH=${BENCH---enable-benchmarks}+  - TEST=${TEST---enable-tests}+  - HADDOCK=${HADDOCK-true}+  - UNCONSTRAINED=${UNCONSTRAINED-true}+  - NOINSTALLEDCONSTRAINTS=${NOINSTALLEDCONSTRAINTS-false}+  - GHCHEAD=${GHCHEAD-false}+  - travis_retry cabal update -v+  - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"+  - rm -fv cabal.project cabal.project.local+  # Overlay Hackage Package Index for GHC HEAD: https://github.com/hvr/head.hackage+  - |+    if $GHCHEAD; then+      sed -i 's/-- allow-newer: .*/allow-newer: *:base/' ${HOME}/.cabal/config+      for pkg in $($HCPKG list --simple-output); do pkg=$(echo $pkg | sed 's/-[^-]*$//'); sed -i "s/allow-newer: /allow-newer: *:$pkg, /" ${HOME}/.cabal/config; done -# check whether current requested install-plan matches cached package-db snapshot- - if diff -u installplan.txt $HOME/.cabsnap/installplan.txt;-   then-     echo "cabal build-cache HIT";-     rm -rfv .ghc;-     cp -a $HOME/.cabsnap/ghc $HOME/.ghc;-     cp -a $HOME/.cabsnap/lib $HOME/.cabsnap/share $HOME/.cabsnap/bin $HOME/.cabal/;-   else-     echo "cabal build-cache MISS";-     rm -rf $HOME/.cabsnap;-     mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin;-     cabal install -j --only-dependencies --enable-tests --enable-benchmarks;-   fi+      echo 'repository head.hackage'                                                        >> ${HOME}/.cabal/config+      echo '   url: http://head.hackage.haskell.org/'                                       >> ${HOME}/.cabal/config+      echo '   secure: True'                                                                >> ${HOME}/.cabal/config+      echo '   root-keys: 07c59cb65787dedfaef5bd5f987ceb5f7e5ebf88b904bbd4c5cbdeb2ff71b740' >> ${HOME}/.cabal/config+      echo '              2e8555dde16ebd8df076f1a8ef13b8f14c66bad8eafefd7d9e37d0ed711821fb' >> ${HOME}/.cabal/config+      echo '              8f79fd2389ab2967354407ec852cbe73f2e8635793ac446d09461ffb99527f6e' >> ${HOME}/.cabal/config+      echo '   key-threshold: 3'                                                            >> ${HOME}/.cabal.config -# snapshot package-db on cache miss- - if [ ! -d $HOME/.cabsnap ];-   then-      echo "snapshotting package-db to build-cache";-      mkdir $HOME/.cabsnap;-      cp -a $HOME/.ghc $HOME/.cabsnap/ghc;-      cp -a $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin installplan.txt $HOME/.cabsnap/;-   fi+      grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$' +      cabal new-update head.hackage -v+    fi+  - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'+  - "printf 'packages: \".\"\\n' > cabal.project"+  - touch cabal.project.local+  - "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"+  - cat cabal.project || true+  - cat cabal.project.local || true+  - if [ -f "./configure.ac" ]; then+      (cd "." && autoreconf -i);+    fi+  - rm -f cabal.project.freeze+  - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all+  - rm -rf .ghc.environment.* "."/dist+  - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)+ # Here starts the actual work to be performed for the package under test; # any command which exits with a non-zero exit code causes the build to fail. script:- - if [ -f configure.ac ]; then autoreconf -i; fi- - cabal configure --enable-tests --enable-benchmarks -v2  # -v2 provides useful information for debugging- - cabal build   # this builds all libraries and executables (including tests/benchmarks)- - cabal test- - cabal check- - cabal sdist   # tests that a source-distribution can be generated+  # test that source-distributions can be generated+  - (cd "." && cabal sdist)+  - mv "."/dist/recursion-schemes-*.tar.gz ${DISTDIR}/+  - cd ${DISTDIR} || false+  - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;+  - "printf 'packages: recursion-schemes-*/*.cabal\\n' > cabal.project"+  - touch cabal.project.local+  - "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"+  - cat cabal.project || true+  - cat cabal.project.local || true -# Check that the resulting source distribution can be built & installed.-# If there are no other `.tar.gz` files in `dist`, this can be even simpler:-# `cabal install --force-reinstalls dist/*-*.tar.gz`- - SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz &&-   (cd dist && cabal install --force-reinstalls "$SRC_TGZ")+  # build & run tests, build benchmarks+  - cabal new-build -w ${HC} ${TEST} ${BENCH} all+  - if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} ${BENCH} all; fi +  # cabal check+  - (cd recursion-schemes-* && cabal check)++  # haddock+  - rm -rf ./dist-newstyle+  - if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi++# REGENDATA ["-o",".travis.yml","--ghc-head","--irc-channel=irc.freenode.org#haskell-lens","--no-no-tests-no-bench","--no-unconstrained","cabal.project"] # EOF
CHANGELOG.markdown view
@@ -1,3 +1,7 @@+## 5.0.3 [2018.07.01]+* Make the Template Haskell machinery look through type synonyms.+* Avoid incurring some dependencies when using recent GHCs.+ ## 5.0.2 * Support GHC-8.2.1 * Fix Template Haskell derivation with non-default type renamer.
Data/Functor/Base.hs view
@@ -1,5 +1,10 @@ {-# LANGUAGE CPP #-} +-- See Data.Functor.Foldable for explanation+#ifndef MIN_VERSION_transformers_compat+#define MIN_VERSION_transformers_compat(x,y,z) 0+#endif+ #define EXPLICIT_DICT_FUNCTOR_CLASSES (MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,5,0) || (MIN_VERSION_transformers_compat(0,5,0) && !MIN_VERSION_transformers(0,4,0)))  #define HAS_GENERIC (__GLASGOW_HASKELL__ >= 702)
Data/Functor/Foldable.hs view
@@ -4,6 +4,12 @@ -- - base-4.9 -- - transformers >= 0.5 -- - transformes-compat >= 0.5 when transformers aren't 0.4+--+-- We don't always depend on transformers-compat, so we need a shim for its version check.+#ifndef MIN_VERSION_transformers_compat+#define MIN_VERSION_transformers_compat(x,y,z) 0+#endif+ #define EXPLICIT_DICT_FUNCTOR_CLASSES (MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,5,0) || (MIN_VERSION_transformers_compat(0,5,0) && !MIN_VERSION_transformers(0,4,0)))  #define HAS_GENERIC (__GLASGOW_HASKELL__ >= 702)
Data/Functor/Foldable/TH.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE Rank2Types #-}+{-# LANGUAGE CPP, Rank2Types #-} module Data.Functor.Foldable.TH   ( makeBaseFunctor   , makeBaseFunctorWith@@ -10,10 +10,11 @@   ) where  import Control.Applicative as A+import Control.Monad import Data.Traversable as T-import Data.Bifunctor (first) import Data.Functor.Identity import Language.Haskell.TH+import Language.Haskell.TH.Datatype as TH.Abs import Language.Haskell.TH.Syntax (mkNameG_tc, mkNameG_v) import Data.Char (GeneralCategory (..), generalCategory) import Data.Orphans ()@@ -55,7 +56,7 @@ -- instance 'Corecursive' (Expr a) where --     'embed' (LitF x)   = Lit x --     'embed' (AddF x y) = Add x y---     'embed' (x :*$ y)  = x :*$ y+--     'embed' (x :*$ y)  = x :* y -- @ -- -- @@@ -74,10 +75,7 @@  -- | Build base functor with a custom configuration. makeBaseFunctorWith :: BaseRules -> Name -> DecsQ-makeBaseFunctorWith rules name = reify name >>= f-  where-    f (TyConI dec) = makePrimForDec rules dec-    f _            = fail "makeBaseFunctor: Expected type constructor name"+makeBaseFunctorWith rules name = reifyDatatype name >>= makePrimForDI rules  -- | Rules of renaming data names data BaseRules = BaseRules@@ -121,23 +119,31 @@     isInfixName :: String -> Bool     isInfixName = all isSymbolChar -makePrimForDec :: BaseRules -> Dec -> DecsQ-makePrimForDec rules dec = case dec of-#if MIN_VERSION_template_haskell(2,11,0)-  DataD    _ tyName vars _ cons _ ->-    makePrimForDec' rules False tyName vars cons-  NewtypeD _ tyName vars _ con _ ->-    makePrimForDec' rules True tyName vars [con]-#else-  DataD    _ tyName vars cons _ ->-    makePrimForDec' rules False tyName vars cons-  NewtypeD _ tyName vars con _ ->-    makePrimForDec' rules True tyName vars [con]-#endif-  _ -> fail "makeFieldOptics: Expected data type-constructor"+makePrimForDI :: BaseRules -> DatatypeInfo -> DecsQ+makePrimForDI rules+  (DatatypeInfo { datatypeName    = tyName+                , datatypeVars    = vars+                , datatypeCons    = cons+                , datatypeVariant = variant }) = do+    when isDataFamInstance $+      fail "makeBaseFunctor: Data families are currently not supported."+    makePrimForDI' rules (variant == Newtype) tyName+                   (map toTyVarBndr vars) cons+  where+    isDataFamInstance = case variant of+                          DataInstance    -> True+                          NewtypeInstance -> True+                          Datatype        -> False+                          Newtype         -> False -makePrimForDec' :: BaseRules -> Bool -> Name -> [TyVarBndr] -> [Con] -> DecsQ-makePrimForDec' rules isNewtype tyName vars cons = do+    toTyVarBndr :: Type -> TyVarBndr+    toTyVarBndr (VarT n)          = PlainTV n+    toTyVarBndr (SigT (VarT n) k) = KindedTV n k+    toTyVarBndr _                 = error "toTyVarBndr"++makePrimForDI' :: BaseRules -> Bool -> Name -> [TyVarBndr]+               -> [ConstructorInfo] -> DecsQ+makePrimForDI' rules isNewtype tyName vars cons = do     -- variable parameters     let vars' = map VarT (typeVars vars)     -- Name of base functor@@ -149,13 +155,15 @@     let r = VarT rName     -- Vars     let varsF = vars ++ [PlainTV rName]-    let fieldCons = map normalizeConstructor cons +    -- #33+    cons' <- traverse (conTypeTraversal resolveTypeSynonyms) cons     let consF-          = conNameMap (_baseRulesCon rules)+          = toCon+          . conNameMap (_baseRulesCon rules)           . conFieldNameMap (_baseRulesField rules)           . conTypeMap (substType s r)-          <$> cons+          <$> cons'      -- Data definition     let dataDec = case consF of@@ -173,7 +181,7 @@           where             deriveds = #if MIN_VERSION_template_haskell(2,12,0)-              [DerivClause Nothing +              [DerivClause Nothing                 [ ConT functorTypeName                 , ConT foldableTypeName                 , ConT traversableTypeName ]]@@ -193,9 +201,7 @@ #endif      -- instance Recursive-    args <- (traverse . traverse . traverse) (\_ -> newName "x") fieldCons--    let projDec = FunD projectValName (mkMorphism id (_baseRulesCon rules) args)+    projDec <- FunD projectValName <$> mkMorphism id (_baseRulesCon rules) cons' #if MIN_VERSION_template_haskell(2,11,0)     let recursiveDec = InstanceD Nothing [] (ConT recursiveTypeName `AppT` s) [projDec] #else@@ -203,7 +209,7 @@ #endif      -- instance Corecursive-    let embedDec = FunD embedValName (mkMorphism (_baseRulesCon rules) id args)+    embedDec <- FunD embedValName <$> mkMorphism (_baseRulesCon rules) id cons' #if MIN_VERSION_template_haskell(2,11,0)     let corecursiveDec = InstanceD Nothing [] (ConT corecursiveTypeName `AppT` s) [embedDec] #else@@ -211,113 +217,72 @@ #endif      -- Combine-    pure [dataDec, baseDec, recursiveDec, corecursiveDec]+    A.pure [dataDec, baseDec, recursiveDec, corecursiveDec]  -- | makes clauses to rename constructors mkMorphism     :: (Name -> Name)     -> (Name -> Name)-    -> [(Name, [Name])]-    -> [Clause]-mkMorphism nFrom nTo args = flip map args $ \(n, fs) -> Clause-    [ConP (nFrom n) (map VarP fs)]                      -- patterns-    (NormalB $ foldl AppE (ConE $ nTo n) (map VarE fs)) -- body-    [] -- where dec---- | Normalized the Con type into a uniform positional representation,--- eliminating the variance between records, infix constructors, and normal--- constructors.-normalizeConstructor-  :: Con-  -> (Name, [(Maybe Name, Type)]) -- ^ constructor name, field name, field type--normalizeConstructor (RecC n xs) =-  (n, [ (Just fieldName, ty) | (fieldName,_,ty) <- xs])--normalizeConstructor (NormalC n xs) =-  (n, [ (Nothing, ty) | (_,ty) <- xs])--normalizeConstructor (InfixC (_,ty1) n (_,ty2)) =-  (n, [ (Nothing, ty1), (Nothing, ty2) ])--normalizeConstructor (ForallC _ _ con) =-  (fmap . fmap . first) (const Nothing) (normalizeConstructor con)--#if MIN_VERSION_template_haskell(2,11,0)-normalizeConstructor (GadtC ns xs _) =-  (head ns, [ (Nothing, ty) | (_,ty) <- xs])--normalizeConstructor (RecGadtC ns xs _) =-  (head ns, [ (Just fieldName, ty) | (fieldName,_,ty) <- xs])-#endif+    -> [ConstructorInfo]+    -> Q [Clause]+mkMorphism nFrom nTo args = for args $ \ci -> do+    let n = constructorName ci+    fs <- replicateM (length (constructorFields ci)) (newName "x")+    pure $ Clause [ConP (nFrom n) (map VarP fs)]                      -- patterns+                  (NormalB $ foldl AppE (ConE $ nTo n) (map VarE fs)) -- body+                  [] -- where dec  ------------------------------------------------------------------------------- -- Traversals ------------------------------------------------------------------------------- -conNameTraversal :: Applicative f => (Name -> f Name) -> Con -> f Con-conNameTraversal f (NormalC n xs)       = NormalC <$> f n <*> A.pure xs-conNameTraversal f (RecC n xs)          = RecC <$> f n <*> pure xs-conNameTraversal f (InfixC l n r)       = InfixC l <$> f n <*> pure r-conNameTraversal f (ForallC xs ctx con) = ForallC xs ctx <$> conNameTraversal f con-#if MIN_VERSION_template_haskell(2,11,0)-conNameTraversal f (GadtC ns xs t)      = GadtC <$> T.traverse f ns <*> pure xs <*> pure t-conNameTraversal f (RecGadtC ns xs t)   = RecGadtC <$> traverse f ns <*> pure xs <*> pure t-#endif+conNameTraversal :: Traversal' ConstructorInfo Name+conNameTraversal = lens constructorName (\s v -> s { constructorName = v }) -conFieldNameTraversal :: Applicative f => (Name -> f Name) -> Con -> f Con-conFieldNameTraversal f (RecC n xs)          = RecC n <$> (traverse . tripleFst) f xs-conFieldNameTraversal f (ForallC xs ctx con) = ForallC xs ctx <$> conFieldNameTraversal f con-#if MIN_VERSION_template_haskell(2,11,0)-conFieldNameTraversal f (RecGadtC ns xs t)   = RecGadtC ns <$> (traverse . tripleFst) f xs <*> pure t-#endif-conFieldNameTraversal _ x = pure x+conFieldNameTraversal :: Traversal' ConstructorInfo Name+conFieldNameTraversal = lens constructorVariant (\s v -> s { constructorVariant = v })+                      . conVariantTraversal+  where+    conVariantTraversal :: Traversal' ConstructorVariant Name+    conVariantTraversal _ NormalConstructor      = pure NormalConstructor+    conVariantTraversal _ InfixConstructor       = pure InfixConstructor+    conVariantTraversal f (RecordConstructor fs) = RecordConstructor <$> traverse f fs -conTypeTraversal :: Applicative f => (Type -> f Type) -> Con -> f Con-conTypeTraversal f (NormalC n xs)       = NormalC n <$> (traverse . pairSnd) f xs-conTypeTraversal f (RecC n xs)          = RecC n <$> (traverse . tripleTrd) f xs-conTypeTraversal f (InfixC l n r)       = InfixC <$> pairSnd f l <*> pure n <*> pairSnd f r-conTypeTraversal f (ForallC xs ctx con) = ForallC xs ctx <$> conTypeTraversal f con-#if MIN_VERSION_template_haskell(2,11,0)-conTypeTraversal f (GadtC ns xs t)      = GadtC ns <$> (traverse . pairSnd) f xs <*> pure t-conTypeTraversal f (RecGadtC ns xs t)   = RecGadtC ns <$> (traverse . tripleTrd) f xs <*> pure t-#endif+conTypeTraversal :: Traversal' ConstructorInfo Type+conTypeTraversal = lens constructorFields (\s v -> s { constructorFields = v })+                 . traverse -conNameMap :: (Name -> Name) -> Con -> Con-conNameMap f = runIdentity . conNameTraversal (Identity . f)+conNameMap :: (Name -> Name) -> ConstructorInfo -> ConstructorInfo+conNameMap = over conNameTraversal -conFieldNameMap :: (Name -> Name) -> Con -> Con-conFieldNameMap f = runIdentity . conFieldNameTraversal (Identity . f)+conFieldNameMap :: (Name -> Name) -> ConstructorInfo -> ConstructorInfo+conFieldNameMap = over conFieldNameTraversal -conTypeMap :: (Type -> Type) -> Con -> Con-conTypeMap f = runIdentity . conTypeTraversal (Identity . f)+conTypeMap :: (Type -> Type) -> ConstructorInfo -> ConstructorInfo+conTypeMap = over conTypeTraversal  ---------------------------------------------------------------------------------- Monomorphic tuple lenses+-- Lenses ------------------------------------------------------------------------------- -type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s--pairSnd :: Lens' (a, b) b-pairSnd f (a, b) = (,) a <$> f b+type Lens'      s a = forall f. Functor     f => (a -> f a) -> s -> f s+type Traversal' s a = forall f. Applicative f => (a -> f a) -> s -> f s -tripleTrd :: Lens' (a, b, c) c-tripleTrd f (a,b,c) = (,,) a b <$> f c+lens :: (s -> a) -> (s -> a -> s) -> Lens' s a+lens sa sas afa s = sas s <$> afa (sa s)+{-# INLINE lens #-} -tripleFst :: Lens' (a, b, c) a-tripleFst f (a,b,c) = (\a' -> (a', b, c)) <$> f a+over :: Traversal' s a -> (a -> a) -> s -> s+over l f = runIdentity . l (Identity . f)+{-# INLINE over #-}  ------------------------------------------------------------------------------- -- Type mangling ------------------------------------------------------------------------------- --- | Extraty type variables+-- | Extract type variables typeVars :: [TyVarBndr] -> [Name]-typeVars = map varBindName--varBindName :: TyVarBndr -> Name-varBindName (PlainTV n)    = n-varBindName (KindedTV n _) = n+typeVars = map tvName  -- | Apply arguments to a type constructor. conAppsT :: Name -> [Type] -> Type@@ -344,6 +309,48 @@ #endif     -- Rest are unchanged     go x = x++toCon :: ConstructorInfo -> Con+toCon (ConstructorInfo { constructorName       = name+                       , constructorVars       = vars+                       , constructorContext    = ctxt+                       , constructorFields     = ftys+                       , constructorStrictness = fstricts+                       , constructorVariant    = variant })+  | not (null vars && null ctxt)+  = error "makeBaseFunctor: GADTs are not currently supported."+  | otherwise+  = let bangs = map toBang fstricts+     in case variant of+          NormalConstructor        -> NormalC name $ zip bangs ftys+          RecordConstructor fnames -> RecC name $ zip3 fnames bangs ftys+          InfixConstructor         -> let [bang1, bang2] = bangs+                                          [fty1,  fty2]  = ftys+                                       in InfixC (bang1, fty1) name (bang2, fty2)+  where+#if MIN_VERSION_template_haskell(2,11,0)+    toBang (FieldStrictness upkd strct) = Bang (toSourceUnpackedness upkd)+                                               (toSourceStrictness strct)+      where+        toSourceUnpackedness :: Unpackedness -> SourceUnpackedness+        toSourceUnpackedness UnspecifiedUnpackedness = NoSourceUnpackedness+        toSourceUnpackedness NoUnpack                = SourceNoUnpack+        toSourceUnpackedness Unpack                  = SourceUnpack++        toSourceStrictness :: Strictness -> SourceStrictness+        toSourceStrictness UnspecifiedStrictness = NoSourceStrictness+        toSourceStrictness Lazy                  = SourceLazy+        toSourceStrictness TH.Abs.Strict         = SourceStrict+#else+    -- On old versions of Template Haskell, there isn't as rich of strictness+    -- information available, so the conversion is somewhat lossy. We try our+    -- best to recognize certain common combinations, and fall back to NotStrict+    -- in the event there's an exotic combination.+    toBang (FieldStrictness UnspecifiedUnpackedness Strict)                = IsStrict+    toBang (FieldStrictness UnspecifiedUnpackedness UnspecifiedStrictness) = NotStrict+    toBang (FieldStrictness Unpack Strict)                                 = Unpacked+    toBang FieldStrictness{}                                               = NotStrict+#endif  ------------------------------------------------------------------------------- -- Compat from base-4.9
examples/Expr.hs view
@@ -44,6 +44,13 @@ nil :: L a nil = L Nothing +-- Test #33+data Tree a = Node {rootLabel :: a, subForest :: Forest a}+  deriving (Show)+type Forest a = [Tree a]++makeBaseFunctor ''Tree+ main :: IO () main = do     let expr2 = ana divCoalg 55 :: Expr Int@@ -56,6 +63,9 @@      let expr3 = Add2 (Lit2 21) $ Add2 (Lit2 11) (Lit2 10)     42 @=? cata evalAlg2 expr3++    let expr4 = Node 5 [Node 6 [Node 7 []], Node 8 [Node 9 []]]+    35 @=? cata treeAlg expr4   where     -- Type signatures to test name generation     evalAlg :: ExprF Int Int -> Int@@ -79,3 +89,6 @@      lCoalg []       = LF { getLF = Nothing } -- to test field renamer     lCoalg (x : xs) = LF { getLF = Just (x, xs) }++    treeAlg :: TreeF Int Int -> Int+    treeAlg (NodeF r f) = r + sum f
recursion-schemes.cabal view
@@ -1,6 +1,6 @@ name:          recursion-schemes category:      Control, Recursion-version:       5.0.2+version:       5.0.3 license:       BSD3 cabal-version: >= 1.8 license-file:  LICENSE@@ -16,7 +16,7 @@   "Generalized bananas, lenses and barbed wire"   by Erik Meijer, Maarten Fokkinga and Ross Paterson. -tested-with:   GHC==7.4.2, GHC==7.6.3, GHC==7.8.4, GHC==7.10.3, GHC==8.0.2, GHC==8.2.1+tested-with:   GHC==7.4.2, GHC==7.6.3, GHC==7.8.4, GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.3, GHC==8.6.1  build-type:    Simple extra-source-files: .travis.yml CHANGELOG.markdown .gitignore README.markdown@@ -31,8 +31,8 @@   default: True  library-  extensions: CPP   other-extensions:+    CPP     TypeFamilies     Rank2Types     FlexibleContexts@@ -42,26 +42,43 @@     UndecidableInstances    build-depends:-    base                 >= 4       && < 5,-    bifunctors           >= 4       && < 6,+    base                 >= 4.5     && < 5,     comonad              >= 4       && < 6,-    free                 >= 4       && < 5,-    semigroups           >= 0.8.3.1 && < 1,-    transformers         >= 0.2     && < 1,-    transformers-compat  >= 0.3     && < 1+    free                 >= 4       && < 6,+    transformers         >= 0.3.0.0 && < 1 +  if !impl(ghc >= 8.2)+    build-depends: bifunctors >= 4 && < 6++  if !impl(ghc >= 8.0)+    build-depends: semigroups >= 0.10 && < 1+   if impl(ghc < 7.5)     build-depends: ghc-prim -  if impl(ghc < 7.10)-    build-depends: nats+  -- Following two conditionals aren't inverses (there are other compilers than GHC)+  --+  -- We enforce the fact that with GHC-7.10+  -- we have at least transformers-0.4.2.0 (the bundled one)+  -- which has 'Data.Functor.Classes' module. (transformers-0.3 doesn't have)+  if impl(ghc >= 7.10)+    build-depends:+      transformers         >= 0.4.2.0 +  if !impl(ghc >= 7.10)+    build-depends:+      nats,+      transformers-compat  >= 0.3     && < 1+   exposed-modules:     Data.Functor.Base     Data.Functor.Foldable    if flag(template-haskell)-    build-depends: template-haskell >= 2.5.0.0 && < 2.13, base-orphans >= 0.5.4 && <0.7+    build-depends:+      template-haskell >= 2.5.0.0 && < 2.14,+      base-orphans     >= 0.5.4   && < 0.8,+      th-abstraction   >= 0.2.4   && < 1     exposed-modules:       Data.Functor.Foldable.TH @@ -79,5 +96,5 @@     base,     HUnit <1.7,     recursion-schemes,-    template-haskell >= 2.5.0.0 && < 2.13,+    template-haskell >= 2.5.0.0 && < 2.14,     transformers     >= 0.2     && < 1