monadic-recursion-schemes 0.1.4.0 → 0.1.4.1
raw patch · 3 files changed
+49/−23 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Data.Functor.Foldable.Monadic: codynaM' :: (Monad m, Corecursive c, Traversable (Base c), Traversable (Base t), Recursive t) => (Base t (Cofree (Base t) a) -> m a) -> (a -> m (Base c a)) -> t -> m c
+ Data.Functor.Foldable.Monadic: codynaM'' :: (Monad m, Traversable t) => (t b -> m b) -> (a -> m (t (Free t a))) -> a -> m b
+ Data.Functor.Foldable.Monadic: dynaM'' :: (Monad m, Traversable t) => (t (Cofree t c) -> m c) -> (a -> m (t a)) -> a -> m c
- Data.Functor.Foldable.Monadic: codynaM :: (Monad m, Corecursive c, Traversable (Base c), Traversable (Base t), Recursive t) => (Base t (Cofree (Base t) a) -> m a) -> (a -> m (Base c a)) -> t -> m c
+ Data.Functor.Foldable.Monadic: codynaM :: (Monad m, Traversable t) => (t b -> m b) -> (a -> m (t (Free t a))) -> a -> m b
- Data.Functor.Foldable.Monadic: dynaM :: forall m t a c. (Monad m, Traversable (Base t), Recursive t, Corecursive t) => (Base t (Cofree (Base t) c) -> m c) -> (a -> m (Base t a)) -> a -> m c
+ Data.Functor.Foldable.Monadic: dynaM :: (Monad m, Traversable (Base t), Recursive t, Corecursive t) => (Base t (Cofree (Base t) b) -> m b) -> (a -> m (Base t a)) -> a -> m b
- Data.Functor.Foldable.Monadic: dynaM' :: (Monad m, Traversable t) => (t (Cofree t c) -> m c) -> (a -> m (t a)) -> a -> m c
+ Data.Functor.Foldable.Monadic: dynaM' :: forall m t a c. (Monad m, Traversable (Base t), Recursive t, Corecursive t) => (Base t (Cofree (Base t) c) -> m c) -> (a -> m (Base t a)) -> a -> m c
Files
- CHANGELOG.md +4/−0
- monadic-recursion-schemes.cabal +1/−1
- src/Data/Functor/Foldable/Monadic.hs +44/−22
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for monadic-recursion-schemes +## 0.1.4.1 -- 2020-05-14++* add alternative for dynaM and codynaM+ ## 0.1.4.0 -- 2020-05-14 * add dynaM, codynaM and dynaM' the recursive variant.
monadic-recursion-schemes.cabal view
@@ -4,7 +4,7 @@ -- http://haskell.org/cabal/users-guide/ name: monadic-recursion-schemes-version: 0.1.4.0+version: 0.1.4.1 synopsis: Recursion Schemes for Monadic version. description: Yet another recursion schemes for monadic style, depends on recursion-schemes. homepage: https://github.com/cutsea110/monadic-recursion-schemes.git
src/Data/Functor/Foldable/Monadic.hs view
@@ -17,7 +17,8 @@ , chronoM, cochronoM , chronoM' -- cochronoM' , dynaM, codynaM- , dynaM' -- codynaM'+ , dynaM', codynaM'+ , dynaM'', codynaM'' ) where import Control.Comonad (Comonad (..))@@ -43,7 +44,7 @@ => (a -> m (Base t a)) -- ^ coalgebra -> a -> m t anaM psi = h- where h = (return . embed) <=< mapM h <=< psi+ where h = return . embed <=< mapM h <=< psi -- | paramorphism paraM :: (Monad m, Traversable (Base t), Recursive t)@@ -57,7 +58,7 @@ => (a -> m (Base t (Either t a))) -- ^ coalgebra -> a -> m t apoM psi = h- where h = (return . embed) <=< mapM (either return h) <=< psi+ where h = return . embed <=< mapM (either return h) <=< psi -- | histomorphism on anamorphism variant histoM :: (Monad m, Traversable (Base t), Recursive t)@@ -65,7 +66,7 @@ -> t -> m a histoM phi = h where h = phi <=< mapM f . project- f = anaM (liftM2 (Cf.:<) <$> h <*> (return . project))+ f = anaM (liftM2 (Cf.:<) <$> h <*> return . project) -- | histomorphism on catamorphism variant histoM' :: (Monad m, Traversable (Base t), Recursive t)@@ -79,7 +80,7 @@ => (a -> m (Base t (Free (Base t) a))) -- ^ coalgebra -> a -> m t futuM psi = h- where h = (return . embed) <=< mapM f <=< psi+ where h = return . embed <=< mapM f <=< psi f = cataM $ \case Fr.Pure a -> h a Fr.Free fb -> return (embed fb)@@ -129,7 +130,7 @@ -> (s -> m (Base s s)) -- ^ coalgebra -> s -> m t metaM phi psi = h- where h = (return . embed) <=< mapM h . project+ where h = return . embed <=< mapM h . project -- | metamorphism on combination variant of cata to ana metaM' :: (Monad m, Corecursive c, Traversable (Base c), Traversable (Base t), Recursive t)@@ -162,24 +163,45 @@ -> t -> m c cochronoM phi psi = futuM psi <=< histoM phi --- | dynamorphism on recursive variant over hylomorphism-dynaM' :: (Monad m, Traversable t)- => (t (Cofree t c) -> m c) -- ^ algebra- -> (a -> m (t a)) -- ^ coalgebra+-- | dynamorphism on recursive variant over chronomorphism+dynaM :: (Monad m, Traversable (Base t), Recursive t, Corecursive t)+ => (Base t (Cofree (Base t) b) -> m b) -- ^ algebra+ -> (a -> m (Base t a)) -- ^ coalgebra+ -> a -> m b+dynaM phi psi = chronoM' phi (return . fmap Pure <=< psi)++-- | dynamorphism on combination variant of ana to histo+dynaM' :: forall m t a c. (Monad m, Traversable (Base t), Recursive t, Corecursive t)+ => (Base t (Cofree (Base t) c) -> m c) -- ^ algebra+ -> (a -> m (Base t a)) -- ^ coalgebra -> a -> m c-dynaM' phi psi = return . extract <=< hyloM f psi+dynaM' phi psi = (histoM phi :: t -> m c) <=< (anaM psi :: a -> m t)++-- | dynamorphism on recursive variant over hylomorphism+dynaM'' :: (Monad m, Traversable t)+ => (t (Cofree t c) -> m c) -- ^ algebra+ -> (a -> m (t a)) -- ^ coalgebra+ -> a -> m c+dynaM'' phi psi = return . extract <=< hyloM f psi where f = liftM2 (:<) <$> phi <*> return --- | dynamorphism on combination variant of ana to histo-dynaM :: forall m t a c. (Monad m, Traversable (Base t), Recursive t, Corecursive t)- => (Base t (Cofree (Base t) c) -> m c) -- ^ algebra- -> (a -> m (Base t a)) -- ^ coalgebra- -> a -> m c-dynaM phi psi = (histoM phi :: t -> m c) <=< (anaM psi :: a -> m t)+codynaM :: (Monad m, Traversable t)+ => (t b -> m b) -- ^ algebra+ -> (a -> m (t (Free t a))) -- ^ coalgebra+ -> a -> m b+codynaM phi psi = chronoM' (phi . fmap extract) psi -- | codynamorphism on combination variant of histo to ana-codynaM :: (Monad m, Corecursive c, Traversable (Base c), Traversable (Base t), Recursive t)- => (Base t (Cofree (Base t) a) -> m a) -- ^ algebra- -> (a -> m (Base c a)) -- ^ coalgebra- -> t -> m c-codynaM phi psi = anaM psi <=< histoM phi+codynaM' :: (Monad m, Corecursive c, Traversable (Base c), Traversable (Base t), Recursive t)+ => (Base t (Cofree (Base t) a) -> m a) -- ^ algebra+ -> (a -> m (Base c a)) -- ^ coalgebra+ -> t -> m c+codynaM' phi psi = anaM psi <=< histoM phi++codynaM'' :: (Monad m, Traversable t)+ => (t b -> m b) -- ^ algebra+ -> (a -> m (t (Free t a))) -- ^ coalgebra+ -> a -> m b+codynaM'' phi psi = hyloM phi g . Pure+ where g (Pure a) = psi a+ g (Free fb) = return fb