packages feed

recursion 1.2.0.1 → 1.2.1.0

raw patch · 3 files changed

+67/−1 lines, 3 filesdep ~base

Dependency ranges changed: base

Files

CHANGELOG.md view
@@ -1,5 +1,13 @@ # recursion +## 1.2.1.0++* Add `chema`, `scolio`, and `dendro`++## 1.2.0.1++* Patch export of `cata`/`ana`+ ## 1.2.0.0  * Remove `chema`
recursion.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: recursion-version: 1.2.0.1+version: 1.2.1.0 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2018 Vanessa McHale
src/Control/Recursion.hs view
@@ -38,9 +38,15 @@     , cataM     , anaM     , hyloM+    -- * Mutual recursion+    , scolio+    , dendro+    , chema     -- * Helper functions     , lambek     , colambek+    , hoist+    , refix     ) where  import           Control.Arrow       ((&&&))@@ -62,6 +68,12 @@      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+ data ListF a b = Cons a b                | Nil                deriving (Functor)@@ -77,6 +89,8 @@  type instance Base (Fix f) = f +type instance Base (Fix f) = f+ type instance Base (Mu f) = f  type instance Base (Nu f) = f@@ -123,6 +137,12 @@     embed (NonEmptyF x Nothing)   = x :| []     embed (NonEmptyF x (Just xs)) = x :| toList xs +instance Functor f => Recursive (Fix f) where+    project = unFix++instance Functor f => Corecursive (Fix f) where+    embed = Fix+ -- | 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@@ -226,3 +246,41 @@ -- | 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++hoist :: (Recursive s, Corecursive t)+      => (forall a. Base s a -> Base t a)+      -> s+      -> t+hoist = cata . (embed .)++refix :: (Recursive s, Corecursive t, Base s ~ Base t) => s -> t+refix = cata embed++-- | Entangle two hylomorphisms.+scolio :: (Functor g)+    => ((f b -> b) -> Trans b b) -- ^ A pseudoprism parametric in an \\( F \\)-algebra that allows @b@ to inspect itself.+    -> ((a -> f a) -> Lens a a) -- ^ A lens parametric in an \\( F \\)-coalgebra that allows @b@ to inspect itself.+    -> (g b -> b) -- ^ A @g@-algebra+    -> (a -> g a) -- ^ A @g@-coalgebra+    -> (f b -> b) -- ^ An @f@-algebra+    -> (a -> f a) -- ^ An @f@-coalgebra+    -> a -> b+scolio p l alg coalg alg' coalg' = hylo (p alg' alg) (l coalg' coalg)+-- TODO: figure out rewrite rules+-- also a more flexible approach would be good.++-- Entangle two anamorphisms.+chema :: (Corecursive t')+    => ((a -> f a) -> Lens b b) -- ^ A lens parametric in an \\( F \\)-coalgebra that allows @b@ to inspect itself.+    -> (a -> f a) -- ^ A @(Base t)@-coalgebra+    -> (b -> Base t' b) -- ^ A @(Base t')@-coalgebra+    -> b -> t'+chema = (ana .*)++-- | A dendromorphism entangles two catamorphisms+dendro :: (Recursive t')+    => ((f a -> a) -> Trans b b) -- ^ A pseudoprism parametric in an \\(F \\)-algebra that allows @b@ to inspect itself.+    -> (f a -> a) -- ^ A @(Base t)@-algebra+    -> (Base t' b -> b) -- ^ A @(Base t')@-algebra+    -> t' -> b+dendro = (cata .*)