packages feed

recursion 2.1.0.0 → 2.2.0.0

raw patch · 3 files changed

+50/−55 lines, 3 files

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # recursion +## 2.2.0.0++* Fix documentation+* Remove `Lens` and `Trans` which are now spurious+ ## 2.1.0.0  * Add `scolioM`, `scolioM'`, `paraM`, `microM`, `mutuM`, `mutuM'`, `elgotM`, and
recursion.cabal view
@@ -1,41 +1,39 @@-cabal-version: 1.18-name: recursion-version: 2.1.0.0-license: BSD3-license-file: LICENSE-copyright: Copyright: (c) 2018 Vanessa McHale-maintainer: vanessa.mchale@iohk.io-author: Vanessa McHale-bug-reports: https://hub.darcs.net/vmchale/recursion/issues-synopsis: A recursion schemes library for GHC.+cabal-version:      1.18+name:               recursion+version:            2.2.0.0+license:            BSD3+license-file:       LICENSE+copyright:          Copyright: (c) 2018 Vanessa McHale+maintainer:         vanessa.mchale@iohk.io+author:             Vanessa McHale+bug-reports:        https://hub.darcs.net/vmchale/recursion/issues+synopsis:           A recursion schemes library for GHC. description:     A performant recursion schemes library for Haskell with minimal dependencies-category: Control, Recursion-build-type: Simple-extra-source-files:-    cabal.project.local-extra-doc-files: README.md-                 CHANGELOG.md+category:           Control, Recursion+build-type:         Simple+extra-source-files: cabal.project.local+extra-doc-files:+    README.md+    CHANGELOG.md  source-repository head-    type: darcs+    type:     darcs     location: https://hub.darcs.net/vmchale/recursion  flag development-    description:-        Enable `-Werror`-    default: False-    manual: True+    description: Enable `-Werror`+    default:     False+    manual:      True  library-    exposed-modules:-        Control.Recursion-    hs-source-dirs: src+    exposed-modules:  Control.Recursion+    hs-source-dirs:   src     default-language: Haskell2010-    other-extensions: DeriveFunctor FlexibleContexts-                      ExistentialQuantification RankNTypes TypeFamilies DeriveFoldable-                      DeriveTraversable-    ghc-options: -Wall+    other-extensions:+        DeriveFunctor FlexibleContexts ExistentialQuantification RankNTypes+        TypeFamilies DeriveFoldable DeriveTraversable+    ghc-options:      -Wall     build-depends:         base >=4.9 && <5,         composition-prelude -any@@ -44,8 +42,9 @@         ghc-options: -Werror      if impl(ghc >=8.0)-        ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates-                     -Wredundant-constraints -Wnoncanonical-monad-instances+        ghc-options:+            -Wincomplete-uni-patterns -Wincomplete-record-updates+            -Wredundant-constraints -Wnoncanonical-monad-instances      if impl(ghc >=8.4)         ghc-options: -Wmissing-export-lists
src/Control/Recursion.hs view
@@ -55,9 +55,6 @@     , colambek     , hoist     , refix-    -- * Additional types-    , Trans-    , Lens     ) where  import           Control.Arrow       ((&&&))@@ -79,12 +76,7 @@      embed :: Base t t -> t --- | A map of \\( F \\)-algebras (pseudoprism)-type Trans s a = forall f. Functor f => (f a -> a) -> f s -> s---- | A map of \\( F \\)-coalgebras-type Lens s a = forall f. Functor f => (a -> f a) -> s -> f s-+-- | Base functor for a list of type @[a]@. data ListF a b = Cons a b                | Nil                deriving (Functor, Foldable, Traversable)@@ -158,7 +150,7 @@ eitherM :: Monad m => (a -> m c) -> (b -> m c) -> m (Either a b) -> m c eitherM l r = (either l r =<<) --- | Catamorφsm. Folds a structure. (see [here](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.41.125&rep=rep1&type=pdf))+-- | Catamorphism. Folds a structure. (see [here](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.41.125&rep=rep1&type=pdf)) cata :: (Recursive t) => (Base t a -> a) -> t -> a cata f = c where c = f . fmap c . project {-# NOINLINE [0] cata #-}@@ -167,7 +159,7 @@   "cata/Mu" forall f (g :: forall a. (f a -> a) -> a). cata f (Mu g) = g f;      #-} --- | Anamorφsm, meant to build up a structure recursively.+-- | Anamorphism, meant to build up a structure recursively. ana :: (Corecursive t) => (a -> Base t a) -> a -> t ana g = a where a = embed . fmap a . g {-# NOINLINE [0] ana #-}@@ -176,8 +168,7 @@    "ana/Nu" forall (f :: a -> f a). ana f = Nu f;       #-} --- | Base functor for a list of type @[a]@.--- | Hylomorφsm; fold a structure while buildiung it up.+-- | Hylomorphism; fold a structure while buildiung it up. hylo :: Functor f => (f b -> b) -> (a -> f a) -> a -> b hylo f g = h where h = f . fmap h . g {-# NOINLINE [0] hylo #-}@@ -231,17 +222,17 @@ colambek :: (Recursive t, Corecursive t) => (Base t t -> t) colambek = ana (fmap project) --- | Prepromorφsm. Fold a structure while applying a natural transformation at each step.+-- | Prepromorphism. Fold a structure while applying a natural transformation at each step. prepro :: (Recursive t, Corecursive t) => (Base t t -> Base t t) -> (Base t a -> a) -> t -> a prepro e f = c     where c = f . fmap (c . cata (embed . e)) . project --- | Postpromorφsm. Build up a structure, applying a natural transformation along the way.+-- | Postpromorphism. Build up a structure, applying a natural transformation along the way. postpro :: (Recursive t, Corecursive t) => (Base t t -> Base t t) -> (a -> Base t a) -> a -> t postpro e g = a'     where a' = embed . fmap (ana (e . project) . a') . g --- | A mutumorφsm.+-- | A mutumorphism. mutu :: (Recursive t) => (Base t (a, a) -> a) -> (Base t (a, a) -> a) -> t -> a mutu f g = snd . cata (f &&& g) @@ -251,30 +242,30 @@ mutuM' :: (Recursive t, Traversable (Base t), Monad m) => (Base t (a, a) -> m a) -> (Base t (a, a) -> m a) -> t -> m a mutuM' f g = h where h = fmap snd . cataM (\x -> zipM (f x) (g x)) --- | Catamorφsm collaψng along two data types simultaneously.+-- | Catamorphism collaψng along two data types simultaneously. scolio :: (Recursive t) => (Base t (a, t) -> a) -> (Base t (a, t) -> t) -> t -> a scolio = fst .** (cata .* (&&&)) --- | Zygomorφsm (see [here](http://www.iis.sinica.edu.tw/~scm/pub/mds.pdf) for a neat example)+-- | Zygomorphism (see [here](http://www.iis.sinica.edu.tw/~scm/pub/mds.pdf) for a neat example) zygo :: (Recursive t) => (Base t b -> b) -> (Base t (b, a) -> a) -> t -> a zygo f g = snd . cata (\x -> (f (fmap fst x), g x)) --- | Paramorφsm+-- | Paramorphism para :: (Recursive t, Corecursive t) => (Base t (t, a) -> a) -> t -> a para f = snd . cata (\x -> (embed (fmap fst x), f x)) --- | Gibbons' metamorφsm. Tear down a structure, transform it, and then build up a new structure+-- | Gibbons' metamorphism. Tear down a structure, transform it, and then build up a new structure meta :: (Corecursive t', Recursive t) => (a -> Base t' a) -> (b -> a) -> (Base t b -> b) -> t -> t' meta f e g = ana f . e . cata g --- | Erwig's metamorφsm. Essentially a hylomorφsm with a natural+-- | Erwig's metamorphism. Essentially a hylomorphism with a natural -- transformation in between. This allows us to use more than one functor in a--- hylomorφsm.+-- hylomorphism. meta' :: (Functor g) => (f a -> a) -> (forall c. g c -> f c) -> (b -> g b) -> b -> a meta' h e k = g     where g = h . e . fmap g . k --- | Mendler's catamorφsm+-- | Mendler's catamorphism mcata :: (forall y. ((y -> c) -> f y -> c)) -> Fix f -> c mcata ψ = mc where mc = ψ mc . unFix @@ -286,7 +277,7 @@ elgot :: Functor f => (f a -> a) -> (b -> Either a (f b)) -> b -> a elgot φ ψ = h where h = either id (φ . fmap h) . ψ --- | Anamorφsm allowing shortcuts. Compare 'apo'+-- | Anamorphism allowing shortcuts. Compare 'apo' micro :: (Corecursive a) => (b -> Either a (Base a b)) -> b -> a micro = elgot embed @@ -294,7 +285,7 @@ coelgot :: Functor f => ((a, f b) -> b) -> (a -> f a) -> a -> b coelgot φ ψ = h where h = φ . (\x -> (x, fmap h . ψ $ x)) --- | Apomorφsm. Compare 'micro'.+-- | Apomorphism. Compare 'micro'. apo :: (Corecursive t) => (a -> Base t (Either t a)) -> a -> t apo g = a where a = embed . fmap (either id a) . g