packages feed

monadic-recursion-schemes 0.1.1.0 → 0.1.2.0

raw patch · 2 files changed

+34/−8 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Functor.Foldable.Monadic: metaM :: (Monad m, Traversable (Base t), Recursive s, Corecursive t, Base s ~ Base t) => (Base t t -> m t) -> (s -> m (Base s s)) -> s -> m t

Files

monadic-recursion-schemes.cabal view
@@ -4,7 +4,7 @@ -- http://haskell.org/cabal/users-guide/  name:                monadic-recursion-schemes-version:             0.1.1.0+version:             0.1.2.0 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
@@ -1,15 +1,18 @@+{-# LANGUAGE GADTs #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveFoldable #-} {-# LANGUAGE DeriveTraversable #-}-{-# LANGUAGE LambdaCase #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE ScopedTypeVariables #-} module Data.Functor.Foldable.Monadic   ( cataM, anaM   , paraM, apoM   , histoM, futuM   , histoM', futuM'   , zygoM, cozygoM-  , hyloM+  , hyloM, metaM   ) where  import           Control.Comonad              (Comonad (..))@@ -51,7 +54,7 @@ apoM psi = h   where h = (return . embed) <=< mapM (either return h) <=< psi --- | histomorphism on recursion variant+-- | histomorphism on anamorphism variant histoM :: (Monad m, Traversable (Base t), Recursive t)        => (Base t (Cofree (Base t) a) -> m a) -- ^ algebra        -> t -> m a@@ -66,7 +69,7 @@ histoM' phi = return . extract <=< cataM f   where f = return . uncurry (:<) <=< (liftM2 (,) <$> phi <*> return) --- | futumorphism on recursion variant+-- | futumorphism on catamorphism variant futuM :: (Monad m, Traversable (Base t), Corecursive t)       => (a -> m (Base t (Free (Base t) a))) -- ^ coalgebra       -> a -> m t@@ -78,8 +81,8 @@  -- | futumorphism on anamorphism variant futuM' :: (Monad m, Traversable (Base t), Corecursive t)-      => (a -> m (Base t (Free (Base t) a))) -- ^ coalgebra-      -> a -> m t+       => (a -> m (Base t (Free (Base t) a))) -- ^ coalgebra+       -> a -> m t futuM' psi = anaM f . Pure   where f (Pure  a) = psi a         f (Free fb) = return fb@@ -100,10 +103,33 @@ cozygoM f psi = anaM g . Right   where g = either (return . fmap Left <=< f) psi --- | hylomorphism+-- | hylomorphism on recursive variant hyloM :: (Monad m, Traversable t)       => (t b -> m b)   -- ^ algebra       -> (a -> m (t a)) -- ^ coalgebra       -> a -> m b hyloM phi psi = h   where h = phi <=< mapM h <=< psi++-- FIXME: I couldn't compile with this type signature.+-- | hylomorphism on combination variant of ana to cata+-- hyloM' :: (Monad m, Traversable (Base t), Recursive t, Corecursive t)+--        => (Base t b -> m b)   -- ^ algebra+--        -> (a -> m (Base t a)) -- ^ coalgebra+--        -> a -> m b+hyloM' phi psi = cataM phi <=< anaM psi++-- | metamorphism on recursive variant+metaM :: (Monad m, Traversable (Base t), Recursive s, Corecursive t, Base s ~ Base t)+      => (Base t t -> m t)+      -> (s -> m (Base s s))+      -> s -> m t+metaM phi psi = h+  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)+       => (Base t a -> m a)   -- ^ algebra+       -> (a -> m (Base c a)) -- ^ coalgebra+       -> t -> m c+metaM' phi psi = anaM psi <=< cataM phi