dunai 0.12.3 → 0.13.0
raw patch · 3 files changed
+62/−4 lines, 3 filesdep +list-transformerdep ~transformersPVP ok
version bump matches the API change (PVP)
Dependencies added: list-transformer
Dependency ranges changed: transformers
API changes (from Hackage documentation)
Files
- CHANGELOG +4/−0
- dunai.cabal +12/−1
- src/Control/Monad/Trans/MSF/List.hs +46/−3
CHANGELOG view
@@ -1,3 +1,7 @@+2024-06-21 Ivan Perez <ivan.perez@keera.co.uk>+ * Version bump (0.13.0) (#420).+ * Implement List interface using list-transformer (#418).+ 2024-04-23 Ivan Perez <ivan.perez@keera.co.uk> * Version bump (0.12.3) (#411). * Fix typo in documentation (#410).
dunai.cabal view
@@ -30,7 +30,7 @@ build-type: Simple name: dunai-version: 0.12.3+version: 0.13.0 author: Ivan Perez, Manuel Bärenz maintainer: ivan.perez@keera.co.uk homepage: https://github.com/ivanperez-keera/dunai@@ -97,7 +97,11 @@ default: False manual: True +flag list-transformer+ description: Use list-transformer instead of transformers to implement the ListT combinators+ default: False + library exposed-modules: Control.Monad.Trans.MSF@@ -146,6 +150,13 @@ MonadRandom >= 0.2 && < 0.6 , transformers-compat >= 0.3 && < 0.8 , void >= 0.1 && < 0.8++ if flag(list-transformer)+ build-depends:+ list-transformer >= 1.1.1 && < 1.2+ , transformers >= 0.3 && < 0.7++ cpp-options: -DLIST_TRANSFORMER test-suite hlint type:
src/Control/Monad/Trans/MSF/List.hs view
@@ -26,9 +26,8 @@ -- additional constraints on the inner monad in order for the combination of -- the monad and the transformer to be a monad. Use at your own risk. module Control.Monad.Trans.MSF.List- {-# WARNING "This module uses the ListT transformer, which is considered deprecated." #-} ( module Control.Monad.Trans.MSF.List- , module Control.Monad.Trans.List+ , module List ) where @@ -37,13 +36,21 @@ import Control.Applicative ((<$>)) #endif -import Control.Monad.Trans.List hiding (liftCallCC, liftCatch)+#ifdef LIST_TRANSFORMER+import Control.Monad (sequence)+import List.Transformer (ListT (ListT, next), Step (..), fold, select)+import qualified List.Transformer as List+#else+import Control.Monad.Trans.List as List hiding (liftCallCC, liftCatch)+#endif -- Internal imports import Data.MonadicStreamFunction.InternalCore (MSF (MSF, unMSF)) -- * List monad +#ifdef LIST_TRANSFORMER+ -- | Run an 'MSF' in the 'ListT' transformer (i.e., multiple MSFs producing -- each producing one output), by applying the input stream to each MSF in the -- list transformer and concatenating the outputs of the MSFs together.@@ -55,9 +62,43 @@ widthFirst msf = widthFirst' [msf] where widthFirst' msfs = MSF $ \a -> do+ (bs, msfs') <- unzip . concat <$> mapM (toList . flip unMSF a) msfs+ return (bs, widthFirst' msfs')++ toList :: (Functor m, Monad m) => ListT m a -> m [a]+ toList = fmap reverse . fold (flip (:)) [] id++-- | Build an 'MSF' in the 'ListT' transformer by broadcasting the input stream+-- value to each MSF in a given list.+sequenceS :: Monad m => [MSF m a b] -> MSF (ListT m) a b+sequenceS msfs = MSF $ \a -> sequence' $ apply a <$> msfs+ where+ sequence' :: Monad m => [m a] -> ListT m a+ sequence' xs = ListT $ next <$> select =<< sequence xs++ apply :: Monad m => a -> MSF m a b -> m (b, MSF (ListT m) a b)+ apply a msf = do+ (b, msf') <- unMSF msf a+ return (b, sequenceS [msf'])++#else++{-# DEPRECATED widthFirst "This ListT definition is deprecated. Use the list-transformer variant of this function instead." #-}+-- | Run an 'MSF' in the 'ListT' transformer (i.e., multiple MSFs producing+-- each producing one output), by applying the input stream to each MSF in the+-- list transformer and concatenating the outputs of the MSFs together.+--+-- An MSF in the ListT transformer can spawn into more than one MSF, or none,+-- so the outputs produced at each individual step are not guaranteed to all+-- have the same length.+widthFirst :: (Functor m, Monad m) => MSF (ListT m) a b -> MSF m a [b]+widthFirst msf = widthFirst' [msf]+ where+ widthFirst' msfs = MSF $ \a -> do (bs, msfs') <- unzip . concat <$> mapM (runListT . flip unMSF a) msfs return (bs, widthFirst' msfs') +{-# DEPRECATED sequenceS "This ListT definition is deprecated. Use the list-transformer variant of this function instead." #-} -- | Build an 'MSF' in the 'ListT' transformer by broadcasting the input stream -- value to each MSF in a given list. sequenceS :: Monad m => [MSF m a b] -> MSF (ListT m) a b@@ -66,6 +107,8 @@ apply a msf = do (b, msf') <- unMSF msf a return (b, sequenceS [msf'])++#endif -- | Apply an 'MSF' to every input. mapMSF :: Monad m => MSF m a b -> MSF m [a] [b]