packages feed

fixfile 0.4.0.0 → 0.5.0.0

raw patch · 3 files changed

+78/−5 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.FixFile: anaM :: (Traversable f, Fixed g, Monad m) => AnaMAlg m f a -> a -> m (g f)
+ Data.FixFile: cataM :: (Traversable f, Fixed g, Monad m) => CataMAlg m f a -> g f -> m a
+ Data.FixFile: cloneH :: Root r => FixFile r -> Handle -> IO ()
+ Data.FixFile: hylo :: Functor f => AnaAlg f a -> CataAlg f b -> a -> b
+ Data.FixFile: hyloM :: (Traversable f, Monad m) => AnaMAlg m f a -> CataMAlg m f b -> a -> m b
+ Data.FixFile: paraM :: (Traversable f, Fixed g, Monad m) => ParaMAlg m g f a -> g f -> m a
+ Data.FixFile: type AnaMAlg m f a = a -> m (f a)
+ Data.FixFile: type CataMAlg m f a = f a -> m a
+ Data.FixFile: type ParaMAlg m g f a = f (g f, a) -> m a

Files

fixfile.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                   fixfile-version:                0.4.0.0+version:                0.5.0.0 synopsis:               File-backed recursive data structures. homepage:               https://github.com/revnull/fixfile license:                LGPL-3
src/Data/FixFile.hs view
@@ -37,11 +37,19 @@                      ,Stored                      -- * F-Algebras                      ,CataAlg+                     ,CataMAlg                      ,cata+                     ,cataM                      ,AnaAlg+                     ,AnaMAlg                      ,ana+                     ,anaM                      ,ParaAlg+                     ,ParaMAlg                      ,para+                     ,paraM+                     ,hylo+                     ,hyloM                      ,iso                      -- * Fixed Typeclasses                      ,FixedAlg(..)@@ -67,6 +75,7 @@                      ,closeFixFile                      ,fixFilePath                      ,clone+                     ,cloneH                      ,vacuum                      -- * Transactions                      ,Transaction@@ -525,6 +534,10 @@ getFull :: Functor f => Transaction (Ref f) s (Fix f) getFull = uses ref iso +{- |+    'cloneH' is 'clone' but taking a 'Handle' as an argument instead of a+    'FilePath'.+-} cloneH :: Root r => FixFile r -> Handle -> IO () cloneH (FixFile _ mv _) dh = runClone where     runClone = do@@ -541,10 +554,7 @@          putMVar mv mv' -    copyPtr ffh h p = do-        b <- getBlock p ffh-        b' <- mapM (copyPtr ffh h) b-        Ptr <$> putRawBlock' b' h+    copyPtr ffh h = hyloM (flip getBlock ffh) ((Ptr <$>) . flip putRawBlock' h)  {- |     It's potentially useful to copy the contents of a 'FixFile' to a new
src/Data/FixFile/Fixed.hs view
@@ -18,12 +18,20 @@                             Fix(..)                            ,Fixed(..)                            ,CataAlg+                           ,CataMAlg                            ,cata+                           ,cataM                            ,AnaAlg+                           ,AnaMAlg                            ,ana+                           ,anaM                            ,ParaAlg+                           ,ParaMAlg                            ,para+                           ,paraM                            ,iso+                           ,hylo+                           ,hyloM                            ,FixedAlg(..)                            ,FixedSub(..)                            ,FixedFunctor(..)@@ -33,6 +41,8 @@                            ,traverseF'                            ) where +import Control.Monad+ {-|     'Fixed' is a typeclass for representing the fixed point of a 'Functor'.     A well-behaved instance of 'Fixed' should not change the shape of the@@ -66,6 +76,11 @@ type AnaAlg f a = a -> f a  {-|+    'AnaMAlg' is a monadic anamorpism F-Algebra.+-}+type AnaMAlg m f a = a -> m (f a)++{-|     'ana' applies an AnaAlg over an argument to produce a fixed-point     of a Functor. -}@@ -73,22 +88,46 @@ ana f = inf . fmap (ana f) . f  {-|+    'anaM' is a monadic anamorphism.+-}+anaM :: (Traversable f, Fixed g, Monad m) =>+    AnaMAlg m f a -> a -> m (g f)+anaM f = fmap inf . (traverse (anaM f) =<<) . f++{-|     'CataAlg' is a catamorphism F-Algebra. -} type CataAlg f a = f a -> a  {-|+    'CataMAlg' is a monadic catamorphism F-Algebra.+-}+type CataMAlg m f a = f a -> m a++{-|     'cata' applies a 'CataAlg' over a fixed point of a 'Functor'. -} cata :: (Functor f, Fixed g) => CataAlg f a -> g f -> a cata f = f . fmap (cata f) . outf  {-|+    'cataM' is a monadic catamorphism.+-}+cataM :: (Traversable f, Fixed g, Monad m) =>+    CataMAlg m f a -> g f -> m a+cataM f = (>>= f) . (traverse (cataM f)) . outf++{-|     'ParaAlg' is a paramorphism F-Algebra. -} type ParaAlg g f a = f (g f, a) -> a  {-|+    'ParaAlg' is a monadic paramorphism F-Algebra.+-}+type ParaMAlg m g f a = f (g f, a) -> m a++{-|     'para' applies a 'ParaAlg' over a fixed point of a 'Functor'. -} para :: (Functor f, Fixed g) => ParaAlg g f a -> g f -> a@@ -96,12 +135,36 @@     para' x = (x, para f x)  {-|+    'paraM' is a monadic paramorphism.+-}+paraM :: (Traversable f, Fixed g, Monad m) =>+    ParaMAlg m g f a -> g f -> m a+paraM f = (>>= f) . mapM para' . outf where+    para' x = do+        x' <- paraM f x+        return (x, x')++{-|     'iso' maps from a fixed point of a 'Functor' to a different fixed     point of the same 'Functor'. For any two well-behaved instances of     'Fixed', the shape of the 'Functor' should remain unchanged. -} iso :: (Functor f, Fixed g, Fixed h) => g f -> h f iso = cata inf++{-|+    'hylo' combines ana and cata into a single operation.+-}+hylo :: Functor f => AnaAlg f a -> CataAlg f b -> a -> b+hylo f g = hylo' where hylo' = g . fmap hylo' . f++{-|+    'hyloM' is a monadic hylomorphism.+-}++hyloM :: (Traversable f, Monad m) =>+    AnaMAlg m f a -> CataMAlg m f b -> a -> m b+hyloM f g = hylo' where hylo' = g <=< mapM hylo' <=< f  {-|     'FixedAlg' is a typeclass for describing the relationship between a