packages feed

recursion 1.2.2.0 → 2.0.0.0

raw patch · 3 files changed

+16/−39 lines, 3 files

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # recursion +## 2.0.0.0++* Add `zygoM'`, the second monadic zygomorphism+* Remove `scolio`, `dendro`, and `chema`+ ## 1.2.2.0  * Add `zygoM`
recursion.cabal view
@@ -1,6 +1,6 @@ cabal-version:      1.18 name:               recursion-version:            1.2.2.0+version:            2.0.0.0 license:            BSD3 license-file:       LICENSE copyright:          Copyright: (c) 2018 Vanessa McHale@@ -32,7 +32,7 @@     default-language: Haskell2010     other-extensions:         DeriveFunctor FlexibleContexts ExistentialQuantification RankNTypes-        TypeFamilies+        TypeFamilies DeriveFoldable DeriveTraversable     ghc-options:      -Wall     build-depends:         base >=4.9 && <5,
src/Control/Recursion.hs view
@@ -1,4 +1,6 @@+{-# LANGUAGE DeriveFoldable            #-} {-# LANGUAGE DeriveFunctor             #-}+{-# LANGUAGE DeriveTraversable         #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts          #-} {-# LANGUAGE RankNTypes                #-}@@ -36,13 +38,10 @@     , mcata     -- * Monadic recursion schemes     , cataM-    , zygoM     , anaM     , hyloM-    -- * Mutual recursion-    , scolio-    , dendro-    , chema+    , zygoM+    , zygoM'     -- * Helper functions     , lambek     , colambek@@ -80,10 +79,10 @@  data ListF a b = Cons a b                | Nil-               deriving (Functor)+               deriving (Functor, Foldable, Traversable)  data NonEmptyF a b = NonEmptyF a (Maybe b)-    deriving (Functor)+    deriving (Functor, Foldable, Traversable)  newtype Fix f = Fix { unFix :: f (Fix f) } @@ -178,10 +177,12 @@ cataM :: (Recursive t, Traversable (Base t), Monad m) => (Base t a -> m a) -> t -> m a cataM f = c where c = f <=< (traverse c . project) ---  (Base t b -> b) -> (Base t (b, a) -> a) -> t -> a zygoM :: (Recursive t, Traversable (Base t), Monad m) => (Base t b -> m b) -> (Base t (b, a) -> m a) -> t -> m a zygoM f g = fmap snd . cataM (\x -> (,) <$> f (fmap fst x) <*> g x) +zygoM' :: (Recursive t, Traversable (Base t), Monad m) => (Base t b -> m b) -> (Base t (b, a) -> m a) -> t -> m a+zygoM' f g = fmap snd . cataM (\x -> do { a <- g x; b <- f (fmap fst x); pure (b, a) })+ anaM :: (Corecursive t, Traversable (Base t), Monad m) => (a -> m (Base t a)) -> a -> m t anaM f = a where a = (fmap embed . traverse a) <=< f @@ -278,32 +279,3 @@  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 .*)