packages feed

recursion-schemes 5.0.1 → 5.0.2

raw patch · 6 files changed

+84/−25 lines, 6 filesdep +natsdep ~HUnitdep ~base-orphansdep ~freenew-uploaderPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: nats

Dependency ranges changed: HUnit, base-orphans, free, template-haskell

API changes (from Hackage documentation)

- Data.Functor.Base: instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Data.Functor.Base.NonEmptyF a b)
- Data.Functor.Base: instance (GHC.Classes.Ord a, GHC.Classes.Ord b) => GHC.Classes.Ord (Data.Functor.Base.NonEmptyF a b)
- Data.Functor.Base: instance (GHC.Read.Read a, GHC.Read.Read b) => GHC.Read.Read (Data.Functor.Base.NonEmptyF a b)
- Data.Functor.Base: instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (Data.Functor.Base.NonEmptyF a b)
- Data.Functor.Foldable: instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Data.Functor.Foldable.ListF a b)
- Data.Functor.Foldable: instance (GHC.Classes.Ord a, GHC.Classes.Ord b) => GHC.Classes.Ord (Data.Functor.Foldable.ListF a b)
- Data.Functor.Foldable: instance (GHC.Read.Read a, GHC.Read.Read b) => GHC.Read.Read (Data.Functor.Foldable.ListF a b)
- Data.Functor.Foldable: instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (Data.Functor.Foldable.ListF a b)
+ Data.Functor.Base: instance (GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.Functor.Base.NonEmptyF a b)
+ Data.Functor.Base: instance (GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Data.Functor.Base.NonEmptyF a b)
+ Data.Functor.Base: instance (GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Data.Functor.Base.NonEmptyF a b)
+ Data.Functor.Base: instance (GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Data.Functor.Base.NonEmptyF a b)
+ Data.Functor.Foldable: instance (GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Data.Functor.Foldable.ListF a b)
+ Data.Functor.Foldable: instance (GHC.Classes.Ord b, GHC.Classes.Ord a) => GHC.Classes.Ord (Data.Functor.Foldable.ListF a b)
+ Data.Functor.Foldable: instance (GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Data.Functor.Foldable.ListF a b)
+ Data.Functor.Foldable: instance (GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Data.Functor.Foldable.ListF a b)
+ Data.Functor.Foldable: instance Data.Functor.Foldable.Corecursive GHC.Natural.Natural
+ Data.Functor.Foldable: instance Data.Functor.Foldable.Recursive GHC.Natural.Natural

Files

.travis.yml view
@@ -28,6 +28,9 @@     - 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]}}  before_install:  - unset CC@@ -57,7 +60,7 @@      echo "cabal build-cache MISS";      rm -rf $HOME/.cabsnap;      mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin;-     cabal install --only-dependencies --enable-tests --enable-benchmarks;+     cabal install -j --only-dependencies --enable-tests --enable-benchmarks;    fi  # snapshot package-db on cache miss
CHANGELOG.markdown view
@@ -1,3 +1,8 @@+## 5.0.2+* Support GHC-8.2.1+* Fix Template Haskell derivation with non-default type renamer.+* Add `Recursive` and `Corecursive Natural` instances, with `Base Natural = Maybe`.+ ## 5.0.1 * Add `Data.Functor.Foldable.TH` module, which provides derivation of base functors via Template Haskell. 
Data/Functor/Foldable.hs view
@@ -128,7 +128,7 @@ import GHC.Generics (Generic1) #endif #endif-+import Numeric.Natural import Data.Monoid (Monoid (..)) import Prelude @@ -334,6 +334,13 @@   project (x:|xs) = NonEmptyF x $ nonEmpty xs instance Corecursive (NonEmpty a) where   embed = (:|) <$> NEF.head <*> (maybe [] toList <$> NEF.tail)++type instance Base Natural = Maybe+instance Recursive Natural where+  project 0 = Nothing+  project n = Just (n - 1)+instance Corecursive Natural where+  embed = maybe 0 (+1)  -- | Cofree comonads are Recursive/Corecursive type instance Base (Cofree f a) = CofreeF f a
Data/Functor/Foldable/TH.hs view
@@ -86,7 +86,7 @@     , _baseRulesField :: Name -> Name     } --- | Default 'BaseRules': prepend @F@ or @$@ to data type, constructors and field names.+-- | Default 'BaseRules': append @F@ or @$@ to data type, constructors and field names. baseRules :: BaseRules baseRules = BaseRules     { _baseRulesType  = toFName@@ -96,19 +96,19 @@  -- | How to name the base functor type. ----- Default is to prepened @F@ or @$@.+-- Default is to append @F@ or @$@. baseRulesType :: Functor f => ((Name -> Name) -> f (Name -> Name)) -> BaseRules -> f BaseRules baseRulesType f rules = (\x -> rules { _baseRulesType = x }) <$> f (_baseRulesType rules)  -- | How to rename the base functor type constructors. ----- Default is to prepened @F@ or @$@.+-- Default is to append @F@ or @$@. baseRulesCon :: Functor f => ((Name -> Name) -> f (Name -> Name)) -> BaseRules -> f BaseRules baseRulesCon f rules = (\x -> rules { _baseRulesCon = x }) <$> f (_baseRulesCon rules)  -- | How to rename the base functor type field names (in records). ----- Default is to prepened @F@ or @$@.+-- Default is to append @F@ or @$@. baseRulesField :: Functor f => ((Name -> Name) -> f (Name -> Name)) -> BaseRules -> f BaseRules baseRulesField f rules = (\x -> rules { _baseRulesField = x }) <$> f (_baseRulesField rules) @@ -124,14 +124,14 @@ makePrimForDec :: BaseRules -> Dec -> DecsQ makePrimForDec rules dec = case dec of #if MIN_VERSION_template_haskell(2,11,0)-  DataD    _ tyName vars _ cons _ -> do+  DataD    _ tyName vars _ cons _ ->     makePrimForDec' rules False tyName vars cons-  NewtypeD _ tyName vars _ con _ -> do+  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 _ -> do+  NewtypeD _ tyName vars con _ ->     makePrimForDec' rules True tyName vars [con] #endif   _ -> fail "makeFieldOptics: Expected data type-constructor"@@ -159,16 +159,31 @@      -- Data definition     let dataDec = case consF of-          [conF] | isNewtype -> #if MIN_VERSION_template_haskell(2,11,0)-              NewtypeD [] tyNameF varsF Nothing conF [ConT functorTypeName, ConT foldableTypeName, ConT traversableTypeName]-          _ ->-              DataD [] tyNameF varsF Nothing consF [ConT functorTypeName, ConT foldableTypeName, ConT traversableTypeName]+            [conF] | isNewtype ->+                NewtypeD [] tyNameF varsF Nothing conF deriveds+            _ ->+                DataD [] tyNameF varsF Nothing consF deriveds #else-              NewtypeD [] tyNameF varsF conF [functorTypeName, foldableTypeName, traversableTypeName]-          _ ->-              DataD [] tyNameF varsF consF [functorTypeName, foldableTypeName, traversableTypeName]+            [conF] | isNewtype ->+                NewtypeD [] tyNameF varsF conF deriveds+            _ ->+                DataD [] tyNameF varsF consF deriveds #endif+          where+            deriveds =+#if MIN_VERSION_template_haskell(2,12,0)+              [DerivClause Nothing +                [ ConT functorTypeName+                , ConT foldableTypeName+                , ConT traversableTypeName ]]+#elif MIN_VERSION_template_haskell(2,11,0)+              [ ConT functorTypeName+              , ConT foldableTypeName+              , ConT traversableTypeName ]+#else+              [functorTypeName, foldableTypeName, traversableTypeName]+#endif      -- type instance Base #if MIN_VERSION_template_haskell(2,9,0)@@ -180,7 +195,7 @@     -- instance Recursive     args <- (traverse . traverse . traverse) (\_ -> newName "x") fieldCons -    let projDec = FunD projectValName (mkMorphism id toFName args)+    let projDec = FunD projectValName (mkMorphism id (_baseRulesCon rules) args) #if MIN_VERSION_template_haskell(2,11,0)     let recursiveDec = InstanceD Nothing [] (ConT recursiveTypeName `AppT` s) [projDec] #else@@ -188,7 +203,7 @@ #endif      -- instance Corecursive-    let embedDec = FunD embedValName (mkMorphism toFName id args)+    let embedDec = FunD embedValName (mkMorphism (_baseRulesCon rules) id args) #if MIN_VERSION_template_haskell(2,11,0)     let corecursiveDec = InstanceD Nothing [] (ConT corecursiveTypeName `AppT` s) [embedDec] #else@@ -341,7 +356,7 @@     ModifierSymbol          -> True     OtherSymbol             -> True     DashPunctuation         -> True-    OtherPunctuation        -> not (c `elem` "'\"")+    OtherPunctuation        -> c `notElem` "'\""     ConnectorPunctuation    -> c /= '_'     _                       -> False 
examples/Expr.hs view
@@ -4,8 +4,10 @@  import Data.Functor.Foldable import Data.Functor.Foldable.TH+import Language.Haskell.TH import Data.List (foldl') import Test.HUnit+import Data.Functor.Identity  data Expr a     = Lit a@@ -15,6 +17,16 @@  makeBaseFunctor ''Expr +data Expr2 a+    = Lit2 a+    | Add2 (Expr2 a) (Expr2 a)+  deriving (Show)++makeBaseFunctorWith (runIdentity $ return baseRules+    >>= baseRulesCon (\_-> Identity $ mkName . (++ "'") . nameBase)+    >>= baseRulesType (\_ -> Identity $ mkName . (++ "_") . nameBase)+    ) ''Expr2+ expr1 :: Expr Int expr1 = Add (Lit 2) (Lit 3 :* [Lit 4]) @@ -41,10 +53,19 @@     let lBar = cons 'b' $ cons 'a' $ cons 'r' $ nil     "bar" @=? cata lAlg lBar     lBar @=? ana lCoalg "bar"++    let expr3 = Add2 (Lit2 21) $ Add2 (Lit2 11) (Lit2 10)+    42 @=? cata evalAlg2 expr3   where+    -- Type signatures to test name generation+    evalAlg :: ExprF Int Int -> Int     evalAlg (LitF x)   = x     evalAlg (AddF x y) = x + y     evalAlg (x :*$ y) = foldl' (*) x y++    evalAlg2 :: Expr2_ Int Int -> Int+    evalAlg2 (Lit2' x)   = x+    evalAlg2 (Add2' x y) = x + y      divCoalg x         | x < 5     = LitF x
recursion-schemes.cabal view
@@ -1,6 +1,6 @@ name:          recursion-schemes category:      Control, Recursion-version:       5.0.1+version:       5.0.2 license:       BSD3 cabal-version: >= 1.8 license-file:  LICENSE@@ -11,9 +11,12 @@ bug-reports:   http://github.com/ekmett/recursion-schemes/issues copyright:     Copyright (C) 2008-2015 Edward A. Kmett synopsis:      Generalized bananas, lenses and barbed wire-description:   Generalized bananas, lenses and barbed wire+description:+  Recursion operators, see+  "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+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  build-type:    Simple extra-source-files: .travis.yml CHANGELOG.markdown .gitignore README.markdown@@ -50,12 +53,15 @@   if impl(ghc < 7.5)     build-depends: ghc-prim +  if impl(ghc < 7.10)+    build-depends: nats+   exposed-modules:     Data.Functor.Base     Data.Functor.Foldable    if flag(template-haskell)-    build-depends: template-haskell >= 2.5.0.0 && < 2.12, base-orphans >= 0.5.4 && <0.6+    build-depends: template-haskell >= 2.5.0.0 && < 2.13, base-orphans >= 0.5.4 && <0.7     exposed-modules:       Data.Functor.Foldable.TH @@ -71,5 +77,7 @@   ghc-options: -Wall -threaded   build-depends:     base,-    HUnit <1.6,-    recursion-schemes+    HUnit <1.7,+    recursion-schemes,+    template-haskell >= 2.5.0.0 && < 2.13,+    transformers     >= 0.2     && < 1